comment/format in:
authorClaus Gittinger <cg@exept.de>
Mon, 05 Nov 2012 18:00:17 +0100
changeset 14496 86af3ba4d272
parent 14495 d5afe5bc91f7
child 14497 211259d933cb
comment/format in: #dayOfFirstWeekInYear: #weekInYearOf: #addPrintBindingsTo:language: add weekDayNth for US #yearAsDays: raise an error if called for a date before 1901 (unsupported)
Date.st
--- a/Date.st	Mon Nov 05 17:48:19 2012 +0100
+++ b/Date.st	Mon Nov 05 18:00:17 2012 +0100
@@ -798,6 +798,7 @@
     "
 ! !
 
+
 !Date class methodsFor:'change & update'!
 
 update:something with:aParameter from:changedObject
@@ -900,6 +901,8 @@
     ^ firstDayInWeek
 
     "
+     Date newDay:1 year:1900  
+     Date dayOfFirstWeekInYear:1900  
      Date dayOfFirstWeekInYear:1998   
      Date dayOfFirstWeekInYear:1999    
      Date dayOfFirstWeekInYear:2000  
@@ -1257,8 +1260,13 @@
 
 weekInYearOf:aDateOrTimestamp
     "for a given date or timeStamp, return the week-number.
-     the returned week number starts with 1 for the first week which has a thursday in it.
-     The above definition can lead to the 1st week starting in the old year!!"
+     The returned week number starts with 1 for the first week which has a thursday in it.
+     (see DIN 1355-1/ISO 8601)
+     The rule is:
+        every monday (and only monday), a new week begins   
+        the first week is the one which has at least 4 days of the new year in it
+        
+     Be prepared: this definition can lead to the 1st week starting in the old year!!"
 
     |date dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week|
 
@@ -1322,6 +1330,8 @@
 
     |y "{ Class: SmallInteger }"|
 
+    yearInteger < 1901 ifTrue:[ self error:'cannot deal with dates before 1901' ].
+
     y := yearInteger - 1900.
     y := y - 1.
     ^ (y * 365)
@@ -1331,6 +1341,7 @@
 
     "
      Date yearAsDays:5 
+     Date yearAsDays:1900 
      Date yearAsDays:1901 
      Date yearAsDays:1902   
      Date yearAsDays:1903   
@@ -1373,6 +1384,7 @@
     ^ self leapYear:yearInteger
 ! !
 
+
 !Date class methodsFor:'private'!
 
 abbreviatedMonthNamesForLanguage:languageOrNilForDefault
@@ -1630,6 +1642,7 @@
     "
 ! !
 
+
 !Date methodsFor:'Compatibility-ANSI'!
 
 dayOfWeek
@@ -2714,6 +2727,8 @@
     "
 ! !
 
+
+
 !Date methodsFor:'obsolete'!
 
 asAbsoluteTime
@@ -2784,6 +2799,7 @@
     ^ self addDays:days
 ! !
 
+
 !Date methodsFor:'printing & storing'!
 
 addPrintBindingsTo:aDictionary
@@ -2882,12 +2898,12 @@
     aDictionary at:$W put:ws.
 
     aDictionary at:#monthName put:monthName.
-    aDictionary at:#monthname put:monthName.
+    aDictionary at:#monthname put:monthName asLowercase.
     aDictionary at:#MonthName put:monthName asUppercaseFirst.
     aDictionary at:#MONTHNAME put:monthName asUppercase.
 
     aDictionary at:#dayName put:dayName.
-    aDictionary at:#dayname put:dayName.
+    aDictionary at:#dayname put:dayName asLowercase.
     aDictionary at:#DayName put:dayName asUppercaseFirst.
     aDictionary at:#DAYNAME put:dayName asUppercase.
 
@@ -2896,12 +2912,12 @@
     aDictionary at:#weekDayUS put:dayOfWeek.
 
     aDictionary at:#shortDayName put:(shortDayName := self class abbreviatedNameOfDay:(self dayInWeek) language:languageOrNil).
-    aDictionary at:#shortdayname put:shortDayName.
+    aDictionary at:#shortdayname put:shortDayName asLowercase.
     aDictionary at:#ShortDayName put:shortDayName asUppercaseFirst.
     aDictionary at:#SHORTDAYNAME put:shortDayName asUppercase.
 
     aDictionary at:#shortMonthName put:(shortMonthName := self class abbreviatedNameOfMonth:(self month) language:languageOrNil).
-    aDictionary at:#shortmonthname put:shortMonthName.
+    aDictionary at:#shortmonthname put:shortMonthName asLowercase.
     aDictionary at:#ShortMonthName put:shortMonthName asUppercaseFirst.
     aDictionary at:#SHORTMONTHNAME put:shortMonthName asUppercase.
 
@@ -2909,6 +2925,8 @@
                                      "/ 0   1    2    3    4    5    6    7    8    9
     aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:(dayOfWeek-1) \\ 10 + 1). 
                                      "/ 0   1    2    3    4    5    6      
+    aDictionary at:#weekDayUSNth put:(#('st' 'nd' 'rd' 'th' 'th' 'th' 'th') at:(dayOfWeek-1) \\ 10 + 1). 
+                                     "/ 0   1    2    3    4    5    6      
     aDictionary at:#weekNth    put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:weekInYear \\ 10 + 1).
                                      "/ 0   1    2    3    4    5    6    7    8    9     
 !
@@ -3141,11 +3159,11 @@
 !Date class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.141 2012-08-29 14:24:55 sr Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.142 2012-11-05 17:00:17 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.141 2012-08-29 14:24:55 sr Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.142 2012-11-05 17:00:17 cg Exp $'
 ! !
 
 Date initialize!