conversion of year in [00..99] to 1900.. no longer done
in newDay:month:year:, but by senders instead.
Senders use Userpreference setting to choose conversion
--- a/Date.st Wed Jan 15 11:50:43 2003 +0100
+++ b/Date.st Wed Jan 15 12:03:05 2003 +0100
@@ -115,30 +115,28 @@
For your convenience, month may be either an integer
or the months name as a string.
- Year may be the actual year (such as 1890, 2001) or the number
- of years since 1900 (which is rubbish ST-80 compatibility:
- it will be totally useless in a few years ...).
- You better not use this short-year feature in your programs."
+ WARNING: semantics changed: 0..99 is no longer treated as 1900..1999,
+ but as 0..99 now.
+ Any such adjustments must be made by the caller of this method now
+ (see those, for example readFrom:onError:)"
- |monthIndex ok yr|
+ |monthIndex ok|
- yr := year.
- yr < 100 ifTrue:[
- yr := yr + 1900.
+ year < 100 ifTrue:[
+ 'Date [warning]: year in [0..99] no longer converted to [1900..1999]' infoPrintCR.
].
-
month isInteger ifTrue:[
monthIndex := month
] ifFalse:[
monthIndex := self indexOfMonth:month
].
(monthIndex == 2 and:[day == 29]) ifTrue:[
- ok := self leapYear:yr
+ ok := self leapYear:year
] ifFalse:[
- ok := day <= (self daysInMonth:month forYear:yr)
+ ok := day <= (self daysInMonth:month forYear:year)
].
((day > 0) and:[ok]) ifTrue:[
- ^ self basicNew dateEncoding:(((yr * 100) + monthIndex) * 100) + day
+ ^ self basicNew dateEncoding:(((year * 100) + monthIndex) * 100) + day
].
"this error is triggered if you try to create a date from an
@@ -152,8 +150,8 @@
Date newDay:8 month:5 year:1994
Date newDay:29 month:'feb' year:1994
Date newDay:29 month:'feb' year:1993
- Date newDay:28 month:'feb' year:5
- Date newDay:28 month:'feb' year:95
+ Date newDay:28 month:'feb' year:5
+ Date newDay:28 month:'feb' year:95
"
"Modified: 19.4.1996 / 15:28:15 / cg"
@@ -224,7 +222,9 @@
].
[str peek isLetterOrDigit] whileFalse:[str next].
year := Integer readFrom:str.
-
+ (year between:0 and:99) ifTrue:[
+ year := UserPreferences current twoDigitDateHandler value:year.
+ ].
self newDay:day month:month year:year
] on:Error do:exceptionBlock.
@@ -232,8 +232,10 @@
Date readFromString:'31 December 1992'
Date readFrom:'19:11:1999'
Date readFromString:'December, 5 1992'
+ Date readFromString:'12/31/1992'
Date readFromString:'3-jan-95'
- Date readFromString:'12/31/1992'
+ Date readFromString:'3-jan-01'
+ Date readFromString:'12/31/01'
Date readFromString:'15.4.1992' -> german; leads to an error
Date readFromString:'10.4.1992' -> german; leads to a wrong date
Date readFromString:'10.4.1992' onError:['wrong date']
@@ -278,7 +280,7 @@
"
^ [
- |str arg|
+ |str arg year|
str := aStringOrStream readStream.
arg := Array new:3.
@@ -290,9 +292,13 @@
ifFalse:[str nextAlphaNumericWord].
arg at:i put:v
].
+ year := (arg at:(aFormatArray at:3)).
+ (year between:0 and:99) ifTrue:[
+ year := UserPreferences current twoDigitDateHandler value:year.
+ ].
self newDay:(arg at:(aFormatArray at:1))
month:(arg at:(aFormatArray at:2))
- year:(arg at:(aFormatArray at:3))
+ year:year
] on:Error do:exceptionBlock.
"
@@ -308,6 +314,9 @@
Date readFrom:'fooBar' printFormat:#(1 2 3) onError:['wrong date']
Date readFrom:'10.4' printFormat:#(1 2 3) onError:['wrong date']
Date readFrom:'10041999' printFormat:#(1 2 3) onError:['wrong date']
+
+ Date readFrom:'31/12/92' printFormat:#(1 2 3) onError:'fail'
+ Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail'
"
"Created: 16.11.1995 / 22:50:17 / cg"
@@ -336,6 +345,8 @@
"
Date readMMDDYYYYFrom:'10041999' onError:['wrong date']
Date readMMDDYYYYFrom:'100419' onError:['wrong date']
+
+ Date readMMDDYYYYFrom:'10040001' onError:['wrong date']
"
"Created: 16.11.1995 / 22:50:17 / cg"
@@ -1907,7 +1918,7 @@
!Date class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.65 2002-11-20 09:40:08 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.66 2003-01-15 11:03:05 cg Exp $'
! !
Date initialize!