'From Squeak3.3alpha of 11 January 2002 [latest update: #4798] on 27 March 2002 at 1:49:59 pm'! "Change Set: GregorianCleanup Date: 27 March 2002 Author: Dan Ingalls Introduces a method Date>>dayMonthYearDo: which allows code to use nicely named variables for day, month, and year, instead of pulling apart the tuple returned by asGregorian. asGregorian remains for compatibility, but its former senders have been cleaned up using the new method. Also introduces Date>>daylightSavingsInEffect which can be useful. Published as 4820GregorianCleanup-di.cs to 3.3a. "! !Date methodsFor: 'converting' stamp: 'di 3/27/2002 11:46'! dayMonthYearDo: dmyBlock "Supply integers for day, month and year to dmyBlock and return the result" "Comments and variable names courtesy of the former method for asGregorian" | l n i j dd mm yyyy | l _ self julianDayNumber + 68569. n _ (4 * l) // 146097. l _ l - ( (146097 * n + 3) // 4 ). i _ (4000 * (l + 1) ) // 1461001. l _ l - ( (1461 * i) // 4 ) + 31. j _ (80 *l) // 2447. dd _ l - ( (2447 * j) // 80 ). l _ j // 11. mm _ j + 2 - (12 * l). yyyy _ 100 * (n -49) + i + l. ^ dmyBlock value: dd value: mm value: yyyy.! ! !Date methodsFor: 'accessing' stamp: 'di 3/27/2002 11:49'! monthIndex "Answer the index of the month in which the receiver falls." ^ self dayMonthYearDo: [:day :month :year | month]! ! !Date methodsFor: 'accessing' stamp: 'di 3/27/2002 11:50'! year "Answer the year in which the receiver falls." ^ self dayMonthYearDo: [:day :month :year | year]! ! !Date methodsFor: 'inquiries' stamp: 'di 3/27/2002 11:49'! dayOfMonth "Answer which day of the month is represented by the receiver." ^ self dayMonthYearDo: [:day :month :year | day]! ! !Date methodsFor: 'inquiries' stamp: 'di 3/27/2002 13:28'! daylightSavingsInEffect self dayMonthYearDo: [:day :month :year | (month < 4 or: [month > 10]) ifTrue: [^ false]. "False November through March" (month > 4 and: [month < 10]) ifTrue: [^ true]. "True May through September" month = 4 ifTrue: ["It's April -- true on first Sunday or later" day >= 7 ifTrue: [^ true]. "Must be after" ^ self dayOfMonth > (self weekdayIndex \\ 7)] ifFalse: ["It's October -- false on last Sunday or later". day < 24 ifTrue: [^ true]. "Must be before" ^ self dayOfMonth < (24 + (self weekdayIndex \\ 7))]]! ! !Date methodsFor: 'converting' stamp: 'di 3/27/2002 11:48'! asGregorian "Return an array of integers #(dd mm yyyy)" ^ self dayMonthYearDo: [:day :month :year | Array with: day with: month with: year]! ! !Date methodsFor: 'printing' stamp: 'di 3/27/2002 11:55'! printOn: aStream format: formatArray "Print a description of the receiver on aStream using the format denoted the argument, formatArray: #(item item item sep monthfmt yearfmt twoDigits) items: 1=day 2=month 3=year will appear in the order given, separated by sep which is eaither an ascii code or character. monthFmt: 1=09 2=Sep 3=September yearFmt: 1=1996 2=96 digits: (missing or)1=9 2=09. See the examples in printOn: and mmddyy" | twoDigits element monthFormat | self dayMonthYearDo: [:day :month :year | twoDigits _ formatArray size > 6 and: [ (formatArray at: 7) > 1 ]. 1 to: 3 do: [ :i | element _ formatArray at: i. element = 1 ifTrue: [twoDigits ifTrue: [ aStream nextPutAll: (day asString padded: #left to: 2 with: $0) ] ifFalse: [ day printOn: aStream ]]. element = 2 ifTrue: [monthFormat _ formatArray at: 5. monthFormat = 1 ifTrue: [twoDigits ifTrue: [ aStream nextPutAll: (month asString padded: #left to: 2 with: $0) ] ifFalse: [ month printOn: aStream ]]. monthFormat = 2 ifTrue: [aStream nextPutAll: ((MonthNames at: month) copyFrom: 1 to: 3)]. monthFormat = 3 ifTrue: [aStream nextPutAll: (MonthNames at: month)]]. element = 3 ifTrue: [(formatArray at: 6) = 1 ifTrue: [ year printOn: aStream ] ifFalse: [ aStream nextPutAll: ((year \\ 100) asString padded: #left to: 2 with: $0) ]]. i < 3 ifTrue: [(formatArray at: 4) ~= 0 ifTrue: [ aStream nextPut: (formatArray at: 4) asCharacter ]]. ]. ]! !