[squeak-dev] The Inbox: Kernel-cbc.872.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Sep 22 05:16:57 UTC 2014


A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-cbc.872.mcz

==================== Summary ====================

Name: Kernel-cbc.872
Author: cbc
Time: 21 September 2014, 10:14:21.049 pm
UUID: 6c144dc0-7a21-a644-af0d-3fca4985da78
Ancestors: Kernel-cbc.871

Added #hash to GenericMonth, GenericYear, and GenericDuration.  Commented all 3 classes.  Simplified how GenericDuration works.

=============== Diff against Kernel-cbc.871 ===============

Item was changed:
  Object subclass: #GenericDuration
  	instanceVariableNames: 'sequence'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Kernel-Chronology'!
+ 
+ !GenericDuration commentStamp: 'cbc 9/21/2014 22:07' prior: 0!
+ The GenericDuration class exists to support simple DateAndTime arithmetic (also including Timespan, such as Date).  This class supports chains of different duration arthmetic with each other, such as:
+    1 year + 2 months + 3 days + 4 hours + 5 minuts + 6 seconds + 7 nanoSeconds
+ Instances of GenericDuration should be created by adding (or subtracting)2 or more durations with each other, including other instances of GenericDuration.
+ 
+ You cannot ask a GenericDuration how long it is.  This is a nonsensical question if a year or month is involved, as those are only resolvable once it is place into relationship to an actual date.
+ 
+ GenericDuration are associate, but not commutative.  That is
+    1 month + 31 days ~= 31 days + 1 month
+ but
+    ((1 month + 1 year) + 31 days) = (1 month + (1 year + 31 days))
+ !

Item was changed:
  ----- Method: GenericDuration>>+ (in category 'ansii protocol') -----
  + aDuration
  	"aDuration is one of the families of Duration.  Not that if it isn't, it will fail, but only when addng to a DateAndTime or Timespan, not before!!"
  	aDuration class = self class
+ 		ifTrue: [sequence addAllLast: aDuration sequence]
+ 		ifFalse: [sequence addLast: aDuration copy]
- 		ifTrue: [sequence addAll: aDuration sequence]
- 		ifFalse: [sequence addLast: { #+. #-. aDuration. }]
  	!

Item was changed:
  ----- Method: GenericDuration>>- (in category 'ansii protocol') -----
  - aDuration
  	"aDuration is one of the families of Duration.  Not that if it isn't, it will fail, but only when addng to a DateAndTime or Timespan, not before!!"
  	aDuration class = self class
+ 		ifTrue: [sequence addAllLast: (aDuration sequence collect: [:s| s copy negated])]
+ 		ifFalse: [sequence addLast: aDuration copy negated]!
- 		ifTrue: [sequence addAll: (aDuration sequence collect: [:s| s copy swap: 1 with: 2])]
- 		ifFalse: [sequence addLast: { #-. #+. aDuration. }]!

Item was changed:
  ----- Method: GenericDuration>>addToDateTime: (in category 'ansii protocol') -----
  addToDateTime: aDateAndTime
+ 	^sequence inject: aDateAndTime into: [:result :duration | result + duration ]!
- 	^sequence inject: aDateAndTime into: [:result :message|
- 		result perform: message first with: message last
- 		]!

Item was changed:
  ----- Method: GenericDuration>>addToDuration: (in category 'ansii protocol') -----
  addToDuration: aDuration
+ 	sequence addFirst: aDuration copy!
- 	sequence addFirst: { #+. #-. aDuration. }!

Item was added:
+ ----- Method: GenericDuration>>hash (in category 'ansii protocol') -----
+ hash
+ 	^(sequence collect: #hash) sum hash!

Item was changed:
  ----- Method: GenericDuration>>printOn: (in category 'squeak protocol') -----
  printOn: stream
+ 	sequence do: [:msg| msg printOn: stream] separatedBy: [stream nextPutAll: ' + ']!
- 	sequence do: [:msg| msg printOn: stream] separatedBy: [stream space]!

Item was changed:
  ----- Method: GenericDuration>>subtractFromDateTime: (in category 'ansii protocol') -----
  subtractFromDateTime: aDateAndTime
+ 	^sequence inject: aDateAndTime into: [:result :duration | result + duration copy negated ]!
- 	^sequence inject: aDateAndTime into: [:result :message|
- 		result perform: message second with: message last
- 		]!

Item was changed:
  ----- Method: GenericDuration>>subtractFromDuration: (in category 'ansii protocol') -----
  subtractFromDuration: aDuration
+ 	sequence addFirst: aDuration copy negated!
- 	sequence do: [:s| s swap: 1 with: 2].
- 	sequence addFirst: { #+. #-. aDuration. }!

Item was changed:
  Object subclass: #GenericMonth
  	instanceVariableNames: 'number'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Kernel-Chronology'!
+ 
+ !GenericMonth commentStamp: 'cbc 9/21/2014 22:01' prior: 0!
+ The GenericMonth class exists to support simple DateAndTime arithmetic with months (also including Timespan, such as Date).  This class is the mechanism behind:
+     DateAndTime now + 3 months
+ Instances of this class should be created by sending #month or #months to an integer (other types of number result in unspecified results).
+ (note that sending #month to any number will result in either exactly 1 month or -1 month, ignoring the actual number you send it too.)
+ 
+ Thse are the rules about what a 'month' is:
+ 1: If you add a month, you want the result to be in the next calendar month, never the following one.
+ 2: If you add a month, you want the same day of the month if possible, and if not (becaue the next month has less days), then the closest that you can get to it.
+ 4: If you add more than 1 month, you want to end up in the right calendar month that you would expect, and as close to the starting day of the month as you can.
+ 3: If you subtract a month, you want it in the previous calendar month, and as close to the starting day of the month as you can get.
+ 
+ So, adding 1 month to August 31 would give September 30th; adding 2 months to August 31 would give October 31st.  And adding 1 month to September 30th would give October 30th.
+ 
+ 
+ !

Item was added:
+ ----- Method: GenericMonth>>hash (in category 'ansiProtocol') -----
+ hash
+ 	^number hash!

Item was changed:
  Object subclass: #GenericYear
  	instanceVariableNames: 'number'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Kernel-Chronology'!
+ 
+ !GenericYear commentStamp: 'cbc 9/21/2014 22:00' prior: 0!
+ The GenericYear class exists to support simple DateAndTime arithmetic with years (also including Timespan, such as Date).  This class is the mechanism behind:
+     DateAndTime now + 3 years
+ Instances of this class should be created by sending #year or #years to an integer (other types of number result in unspecified results).
+ (note that sending #year to any number will result in either exactly 1 year or -1 year, ignoring the actual number you send it too.)
+ 
+ Thse are the rules about what a 'year' is:
+ 1: If you add a year, you want the result to be in the next year, never the following one; it needs to end up in the same month as the starting month; and it needs to be the same day of the month if possible as the starting date, and if not (becaue the next years month has less days such as leap year to non-leap year), then the closest that you can get to it.
+ 4: If you add more than 1 year, you want to end up in the right year, same calendar month that you would expect, and as close to the starting day of the month as you can.
+ 3: If you subtract a year, you want it in the previous year and same calendar month, and as close to the starting day of the month as you can get.!

Item was added:
+ ----- Method: GenericYear>>hash (in category 'ansiProtocol') -----
+ hash
+ 	^number hash!



More information about the Squeak-dev mailing list