author | Claus Gittinger <cg@exept.de> |
Thu, 09 Oct 2003 18:09:39 +0200 | |
changeset 7648 | 61b7826a9a0e |
parent 7646 | 94ae479eedbb |
child 7649 | 1e907123a5c2 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
155 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5515 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
54 | 15 |
Magnitude subclass:#Date |
972 | 16 |
instanceVariableNames:'dateEncoding' |
17 |
classVariableNames:'DayNames MonthNames DayAbbrevs MonthAbbrevs EnvironmentChange' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Magnitude-General' |
|
1 | 20 |
! |
21 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
22 |
!Date class methodsFor:'documentation'! |
54 | 23 |
|
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
155 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
54 | 38 |
documentation |
39 |
" |
|
92 | 40 |
Instances of Date represent dates as year, month and day encoded in the |
41 |
(private & hidden) instance dateEncoding. The value found there is |
|
42 |
year*100*100 + month*100 + day (which makes magnitude-like comparison of |
|
43 |
dates easy, but is not guaranteed for future versions). |
|
1228 | 44 |
Do not depend on the internal representation. |
54 | 45 |
|
92 | 46 |
The old representation used days since 1st Jan. 1901 internally - |
47 |
with the new implementation, it is possible to reasonably represent almost |
|
48 |
any Date. (which insurance companies will like, since they can now |
|
49 |
represent even very old peoples birthday :-) |
|
68 | 50 |
Notice: no correction for pre-Julian dates is done. |
54 | 51 |
|
92 | 52 |
The printed representation of dates is controlled by resource definitions - |
53 |
thus national variants are already supported (see file 'resources/Date.rs'). |
|
54 |
||
55 |
Compatibility notice: |
|
1228 | 56 |
due to some historic reasons, there are some methods found twice |
57 |
with different names in this class. The old ST/X methods will vanish in |
|
58 |
one of the next releases, and kept for a while to support existing |
|
59 |
applications (the info on how these methods should be named came |
|
60 |
somewhat late from the testers ..). |
|
92 | 61 |
|
1228 | 62 |
Please do not use methods marked as obsolete in their comment. |
92 | 63 |
|
64 |
Most useful methods: |
|
65 |
||
1228 | 66 |
Date today |
67 |
(Date today) addDays: |
|
68 |
(Date today) subtractDays: |
|
1295 | 69 |
|
70 |
[author:] |
|
71 |
Claus Gittinger |
|
72 |
||
73 |
[see also:] |
|
74 |
Time AbstractTime |
|
75 |
Filename |
|
76 |
OperatingSystem |
|
54 | 77 |
" |
78 |
! ! |
|
79 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
80 |
!Date class methodsFor:'instance creation'! |
699 | 81 |
|
82 |
fromDays:dayCount |
|
83 |
"return a new Date, given the day-number starting with 0 at 1.Jan 1901; |
|
84 |
(i.e. 'Date fromDays:0' returns 1st Jan. 1901). |
|
85 |
Date asDays is the reverse operation. |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
86 |
Added for GNU/ST-80 compatibility" |
699 | 87 |
|
88 |
|yr rest d| |
|
89 |
||
90 |
"approx. year" |
|
91 |
yr := (dayCount // 366) + 1901. |
|
92 |
rest := dayCount - (self yearAsDays:yr) + 1. "+1 for ST-80 compatibility" |
|
93 |
d := self daysInYear:yr. |
|
94 |
(rest > d) ifTrue:[ |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
95 |
"adjust" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
96 |
yr := yr + 1. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
97 |
rest := rest - d. |
699 | 98 |
]. |
99 |
||
1501 | 100 |
^ self newDay:rest year:yr |
699 | 101 |
|
102 |
" |
|
103 |
Date fromDays:0 -> 1 jan 1901 |
|
104 |
Date fromDays:365 -> 1 jan 1902 |
|
105 |
Date fromDays:730 -> 1 jan 1903 |
|
106 |
Date fromDays:1095 -> 1 jan 1903 |
|
107 |
Date fromDays:1460 ->31 dec 1904 since 1904 was a leap year |
|
108 |
" |
|
109 |
||
1501 | 110 |
"Modified: 1.7.1996 / 14:24:25 / cg" |
699 | 111 |
! |
112 |
||
113 |
newDay:day month:month year:year |
|
114 |
"return a new Date, given the day, month and year. |
|
115 |
For your convenience, month may be either an integer |
|
116 |
or the months name as a string. |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
117 |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
118 |
WARNING: semantics changed: 0..99 is no longer treated as 1900..1999, |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
119 |
but as 0..99 now. |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
120 |
Any such adjustments must be made by the caller of this method now |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
121 |
(see those, for example readFrom:onError:)" |
699 | 122 |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
123 |
|monthIndex ok| |
699 | 124 |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
125 |
year < 100 ifTrue:[ |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
126 |
'Date [warning]: year in [0..99] no longer converted to [1900..1999]' infoPrintCR. |
699 | 127 |
]. |
128 |
month isInteger ifTrue:[ |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
129 |
monthIndex := month |
699 | 130 |
] ifFalse:[ |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
131 |
monthIndex := self indexOfMonth:month |
699 | 132 |
]. |
133 |
(monthIndex == 2 and:[day == 29]) ifTrue:[ |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
134 |
ok := self leapYear:year |
699 | 135 |
] ifFalse:[ |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
136 |
ok := day <= (self daysInMonth:month forYear:year) |
699 | 137 |
]. |
138 |
((day > 0) and:[ok]) ifTrue:[ |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
139 |
^ self basicNew dateEncoding:(((year * 100) + monthIndex) * 100) + day |
699 | 140 |
]. |
141 |
||
142 |
"this error is triggered if you try to create a date from an |
|
143 |
invalid year/month/day combination; |
|
144 |
Such as 29-feb-year, where year is no leap year |
|
145 |
" |
|
146 |
self error:'invalid date' |
|
147 |
||
148 |
" |
|
149 |
Date newDay:8 month:'may' year:1993 |
|
150 |
Date newDay:8 month:5 year:1994 |
|
151 |
Date newDay:29 month:'feb' year:1994 |
|
152 |
Date newDay:29 month:'feb' year:1993 |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
153 |
Date newDay:28 month:'feb' year:5 |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
154 |
Date newDay:28 month:'feb' year:95 |
699 | 155 |
" |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
156 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
157 |
"Modified: 19.4.1996 / 15:28:15 / cg" |
699 | 158 |
! |
159 |
||
160 |
newDay:dayInYear year:year |
|
161 |
"return a new Date, given the year and the day-in-year (starting at 1). |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
162 |
See also: Date today / Time now / AbsoluteTime now. |
699 | 163 |
ST-80 compatibility" |
164 |
||
165 |
|monthAndDay| |
|
166 |
||
167 |
(dayInYear between:1 and:365) ifFalse:[ |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
168 |
((dayInYear == 366) and:[self leapYear:year]) ifFalse:[ |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
169 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
170 |
this error is triggered, when you try to create a |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
171 |
day from an invalid day-in-year; |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
172 |
for example, 366 in a non-leap year. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
173 |
I dont know, if ST-80 wraps to the next year(s) in this case. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
174 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
175 |
^ self error:'invalid date' |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
176 |
] |
699 | 177 |
]. |
178 |
monthAndDay := self monthAndDayFromDayInYear:dayInYear forYear:year. |
|
1501 | 179 |
^ self newDay:(monthAndDay at:2) month:(monthAndDay at:1) year:year |
699 | 180 |
|
181 |
" |
|
182 |
Date newDay:150 year:1994 |
|
183 |
Date newDay:1 year:1994 |
|
184 |
Date newDay:1 year:1901 |
|
185 |
Date newDay:1 year:1902 |
|
186 |
Date newDay:365 year:1992 |
|
187 |
Date newDay:366 year:1992 |
|
188 |
Date newDay:365 year:1994 |
|
189 |
Date newDay:366 year:1994 |
|
190 |
" |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
191 |
|
1501 | 192 |
"Modified: 1.7.1996 / 14:22:24 / cg" |
699 | 193 |
! |
194 |
||
195 |
readFrom:aStringOrStream onError:exceptionBlock |
|
196 |
"return a new Date, reading a printed representation from aStream. |
|
197 |
Notice, that this is not the storeString format and |
|
198 |
is different from the format expected by readFrom:. |
|
199 |
BUG: |
|
200 |
This method assumes american format (i.e. month-day-year) instead |
|
201 |
of the german/french and other day-month-year. |
|
4998 | 202 |
There ought to be a internationalized variant of this." |
699 | 203 |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
204 |
^ [ |
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
205 |
|str month day year| |
972 | 206 |
str := aStringOrStream readStream. |
699 | 207 |
|
972 | 208 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
209 |
(str peek isDigit) ifTrue:[ |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3257
diff
changeset
|
210 |
day := Integer readFrom:str |
972 | 211 |
]. |
212 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
|
213 |
(str peek isLetter) ifTrue:[ |
|
214 |
month := str nextAlphaNumericWord. |
|
215 |
day isNil ifTrue:[ |
|
216 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3257
diff
changeset
|
217 |
day := Integer readFrom:str. |
972 | 218 |
] |
219 |
] ifFalse:[ |
|
220 |
month := self nameOfMonth:day. |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3257
diff
changeset
|
221 |
day := Integer readFrom:str |
972 | 222 |
]. |
223 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3257
diff
changeset
|
224 |
year := Integer readFrom:str. |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
225 |
(year between:0 and:99) ifTrue:[ |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
226 |
year := UserPreferences current twoDigitDateHandler value:year. |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
227 |
]. |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
228 |
self newDay:day month:month year:year |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
229 |
] on:Error do:exceptionBlock. |
699 | 230 |
|
231 |
" |
|
232 |
Date readFromString:'31 December 1992' |
|
4997 | 233 |
Date readFrom:'19:11:1999' |
234 |
Date readFromString:'December, 5 1992' |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
235 |
Date readFromString:'12/31/1992' |
4997 | 236 |
Date readFromString:'3-jan-95' |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
237 |
Date readFromString:'3-jan-01' |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
238 |
Date readFromString:'12/31/01' |
4997 | 239 |
Date readFromString:'15.4.1992' -> german; leads to an error |
240 |
Date readFromString:'10.4.1992' -> german; leads to a wrong date |
|
241 |
Date readFromString:'10.4.1992' onError:['wrong date'] |
|
242 |
Date readFromString:'32.4.1992' onError:['wrong date'] |
|
243 |
Date readFromString:'fooBar' onError:['wrong date'] |
|
244 |
Date readFromString:'10.4' onError:['wrong date'] |
|
245 |
Date readFromString:'10041999' onError:['wrong date'] |
|
246 |
" |
|
247 |
||
248 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
249 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
250 |
! |
|
251 |
||
252 |
readFrom:aStringOrStream printFormat:aFormatArray |
|
253 |
"return a new Date, reading a printed representation from aStream. |
|
254 |
1 day position (1, 2 or 3) |
|
255 |
2 month position (1..3) |
|
256 |
3 year position (1..3) |
|
257 |
" |
|
258 |
^ self readFrom:aStringOrStream |
|
259 |
printFormat:aFormatArray |
|
260 |
onError:[self error:'expected: ' , self name] |
|
261 |
||
262 |
" |
|
263 |
Date readFrom:'19:11:1999' printFormat:#( 1 2 3 ) |
|
264 |
Date readFrom:'19-nov-1999' printFormat:#( 1 2 3 ) |
|
265 |
Date readFrom:'19:11:1999' printFormat:#( 2 1 3 ) -> exception: wrong month |
|
266 |
Date readFrom:'5:12:1999' printFormat:#( 2 1 3 ) |
|
267 |
Date readFrom:'may-12-1999' printFormat:#( 2 1 3 ) |
|
268 |
Date readFrom:'1999 may 12' printFormat:#( 3 2 1 ) |
|
269 |
" |
|
270 |
||
271 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
272 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
273 |
! |
|
274 |
||
275 |
readFrom:aStringOrStream printFormat:aFormatArray onError:exceptionBlock |
|
276 |
"return a new Date, reading a printed representation from aStream. |
|
277 |
1 day position (1, 2 or 3) |
|
278 |
2 month position (1..3) |
|
279 |
3 year position (1..3) |
|
280 |
" |
|
281 |
||
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
282 |
^ [ |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
283 |
|str arg year| |
4997 | 284 |
|
285 |
str := aStringOrStream readStream. |
|
286 |
arg := Array new:3. |
|
287 |
||
288 |
1 to:3 do:[:i||v| |
|
289 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
|
290 |
||
291 |
v := (str peek isDigit) ifTrue:[Integer readFrom:str] |
|
292 |
ifFalse:[str nextAlphaNumericWord]. |
|
293 |
arg at:i put:v |
|
294 |
]. |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
295 |
year := (arg at:(aFormatArray at:3)). |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
296 |
(year between:0 and:99) ifTrue:[ |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
297 |
year := UserPreferences current twoDigitDateHandler value:year. |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
298 |
]. |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
299 |
self newDay:(arg at:(aFormatArray at:1)) |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
300 |
month:(arg at:(aFormatArray at:2)) |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
301 |
year:year |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
302 |
] on:Error do:exceptionBlock. |
4997 | 303 |
|
304 |
" |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
305 |
Date readFrom:'31 December 1992' printFormat:#(1 2 3) onError:'fail' |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
306 |
Date readFrom:'19:11:1999' printFormat:#(1 2 3) onError:'fail' |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
307 |
Date readFrom:'December, 5 1992' printFormat:#(1 2 3) onError:'fail' |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
308 |
Date readFrom:'3-jan-95' printFormat:#(1 2 3) onError:'fail' |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
309 |
Date readFrom:'12/31/1992' printFormat:#(1 2 3) onError:'fail' |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
310 |
Date readFrom:'15.4.1992' printFormat:#(1 2 3) onError:'wrong date' -> german |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
311 |
Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:'fail' -> german |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
312 |
Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:['wrong date'] |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
313 |
Date readFrom:'32.4.1992' printFormat:#(1 2 3) onError:['wrong date'] |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
314 |
Date readFrom:'fooBar' printFormat:#(1 2 3) onError:['wrong date'] |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
315 |
Date readFrom:'10.4' printFormat:#(1 2 3) onError:['wrong date'] |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
316 |
Date readFrom:'10041999' printFormat:#(1 2 3) onError:['wrong date'] |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
317 |
|
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
318 |
Date readFrom:'31/12/92' printFormat:#(1 2 3) onError:'fail' |
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
319 |
Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail' |
4421 | 320 |
" |
321 |
||
322 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
323 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
324 |
! |
|
325 |
||
326 |
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock |
|
327 |
"return a new Date, reading a printed representation from aStream. |
|
328 |
Notice, that this is not the storeString format and |
|
4998 | 329 |
is different from the format expected by readFrom:" |
4421 | 330 |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
331 |
^ [ |
4421 | 332 |
|str month day year| |
333 |
||
334 |
str := aStringOrStream readStream. |
|
335 |
month := str next:2. |
|
336 |
month := Integer readFrom:month. |
|
337 |
day := str next:2. |
|
338 |
day := Integer readFrom:day. |
|
339 |
year := str next:4. |
|
340 |
year := Integer readFrom:year. |
|
341 |
||
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
342 |
self newDay:day month:month year:year |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
343 |
] on:Error do:exceptionBlock |
4421 | 344 |
|
345 |
" |
|
346 |
Date readMMDDYYYYFrom:'10041999' onError:['wrong date'] |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
347 |
Date readMMDDYYYYFrom:'100419' onError:['wrong date'] |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
348 |
|
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
349 |
Date readMMDDYYYYFrom:'10040001' onError:['wrong date'] |
699 | 350 |
" |
351 |
||
352 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
353 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
699 | 354 |
! |
355 |
||
356 |
today |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
357 |
"return a date, representing today. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
358 |
See also: Time now / AbsoluteTime now." |
699 | 359 |
|
1501 | 360 |
^ self fromOSTime:(OperatingSystem getOSTime) |
699 | 361 |
|
362 |
" |
|
363 |
Date today |
|
364 |
" |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
365 |
|
1501 | 366 |
"Modified: 1.7.1996 / 15:20:16 / cg" |
5548 | 367 |
! |
368 |
||
369 |
tomorrow |
|
370 |
"return a date, representing tomorrow. |
|
371 |
See also: Time now / AbsoluteTime now." |
|
372 |
||
373 |
^ Date today addDays:1 |
|
374 |
||
375 |
" |
|
376 |
Date tomorrow |
|
377 |
Date tomorrow dayInWeek |
|
378 |
" |
|
379 |
! |
|
380 |
||
381 |
yesterday |
|
382 |
"return a date, representing yesterday. |
|
383 |
See also: Time now / AbsoluteTime now." |
|
384 |
||
385 |
^ Date today subtractDays:1 |
|
386 |
||
387 |
" |
|
388 |
Date yesterday |
|
389 |
Date yesterday dayInWeek |
|
390 |
" |
|
699 | 391 |
! ! |
392 |
||
7299 | 393 |
!Date class methodsFor:'Compatibility-Dolphin'! |
6872 | 394 |
|
395 |
newDay:day monthIndex:month year:year |
|
396 |
^ self newDay:day month:month year:year |
|
397 |
||
398 |
" |
|
399 |
Date newDay:8 monthIndex:5 year:1993 |
|
400 |
" |
|
401 |
||
402 |
"Modified: 19.4.1996 / 15:28:15 / cg" |
|
403 |
! ! |
|
404 |
||
7646 | 405 |
!Date class methodsFor:'Compatibility-ST80'! |
406 |
||
7648 | 407 |
newDay:day monthNumber:monthIndex year:year |
7646 | 408 |
"ST80 compatibility" |
409 |
||
410 |
^ self newDay:day month:monthIndex year:year |
|
411 |
! ! |
|
412 |
||
7299 | 413 |
!Date class methodsFor:'Compatibility-Squeak'! |
7005 | 414 |
|
415 |
fromSeconds:seconds |
|
416 |
"Answer an instance of me which is 'seconds' seconds after January 1, 1901." |
|
417 |
||
418 |
| secondsInDay | |
|
419 |
||
420 |
secondsInDay := 24 * 60 * 60. |
|
421 |
^self fromDays: seconds // secondsInDay |
|
422 |
||
423 |
" |
|
424 |
Date fromSeconds:0 |
|
425 |
Date fromSeconds:(24 * 60 * 60 * 365) |
|
426 |
" |
|
427 |
! ! |
|
428 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
429 |
!Date class methodsFor:'general queries'! |
699 | 430 |
|
431 |
abbreviatedNameOfDay:dayIndex |
|
432 |
"given a day index (1..7), return the abbreviated name |
|
433 |
of the day" |
|
434 |
||
5830 | 435 |
(DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
436 |
self initNames |
|
699 | 437 |
]. |
438 |
^ DayAbbrevs at:dayIndex |
|
439 |
||
440 |
" |
|
441 |
Date abbreviatedNameOfDay:4 |
|
442 |
" |
|
443 |
! |
|
444 |
||
445 |
abbreviatedNameOfMonth:monthIndex |
|
446 |
"given a month index (1..12), return the abbreviated name |
|
447 |
of the month" |
|
448 |
||
5830 | 449 |
(MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
450 |
self initNames |
|
699 | 451 |
]. |
452 |
^ MonthAbbrevs at:monthIndex |
|
453 |
||
454 |
" |
|
455 |
Date abbreviatedNameOfMonth:11 |
|
456 |
Date abbreviatedNameOfMonth:12 |
|
457 |
" |
|
458 |
! |
|
459 |
||
460 |
dateAndTimeNow |
|
461 |
"return an array containing the date and time of now" |
|
462 |
||
463 |
^ Time dateAndTimeNow |
|
464 |
||
465 |
" |
|
466 |
Date dateAndTimeNow |
|
467 |
" |
|
468 |
! |
|
469 |
||
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
470 |
dayOfFirstWeekInYear:aYear |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
471 |
"for a given year, return the day corresponding to that years monday of week-01. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
472 |
The 1st week is the one, in which the first thursday is found; |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
473 |
and the 1st day of that week is the preceeding monday |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
474 |
(that means: that the returned day might be a day of the previous year)" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
475 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
476 |
|day dayInWeekOf1stJan firstThursday firstDayInWeek| |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
477 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
478 |
"/ find the first thursday ... |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
479 |
day := AbsoluteTime newDay:1 year:aYear. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
480 |
dayInWeekOf1stJan := day dayInWeek. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
481 |
dayInWeekOf1stJan > 4 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
482 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
483 |
] ifFalse:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
484 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
485 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
486 |
"/ back to the preceeding monday |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
487 |
firstDayInWeek := firstThursday subtractDays:3. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
488 |
^ firstDayInWeek |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
489 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
490 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
491 |
Date dayOfFirstWeekInYear:1998 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
492 |
Date dayOfFirstWeekInYear:1999 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
493 |
Date dayOfFirstWeekInYear:2000 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
494 |
Date dayOfFirstWeekInYear:2001 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
495 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
496 |
! |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
497 |
|
699 | 498 |
dayOfWeek:dayName |
499 |
"given the name of a day (either string or symbol), |
|
500 |
return the day-index (1 for monday; 7 for sunday). |
|
501 |
Return 0 for invalid day name" |
|
502 |
||
6976 | 503 |
|idx| |
504 |
||
5830 | 505 |
(DayNames isNil or:[EnvironmentChange]) ifTrue:[ |
506 |
self initNames |
|
699 | 507 |
]. |
6976 | 508 |
idx := DayNames indexOf:dayName. |
509 |
idx == 0 ifTrue:[ |
|
510 |
idx := DayNames indexOf:dayName asLowercase. |
|
511 |
]. |
|
512 |
^ idx |
|
699 | 513 |
|
514 |
" |
|
6976 | 515 |
Date dayOfWeek:'wednesday' |
516 |
Date dayOfWeek:'Wednesday' |
|
699 | 517 |
" |
518 |
! |
|
519 |
||
520 |
daysInMonth:month forYear:yearInteger |
|
521 |
"given the name of a month and a year, return the number |
|
522 |
of days this month has (modified GNU). |
|
523 |
return 0 if the month name was invalid. |
|
524 |
For your convenience, month maybe an integer or name-string." |
|
525 |
||
526 |
|monthIndex "{ Class: SmallInteger }"| |
|
527 |
||
528 |
month isInteger ifTrue:[ |
|
529 |
monthIndex := month |
|
530 |
] ifFalse:[ |
|
531 |
monthIndex := self indexOfMonth:month |
|
532 |
]. |
|
533 |
||
534 |
^ self daysInMonthIndex:monthIndex forYear:yearInteger |
|
535 |
||
536 |
" |
|
537 |
Date daysInMonth:2 forYear:1980 |
|
538 |
Date daysInMonth:2 forYear:1981 |
|
539 |
Date daysInMonth:'feb' forYear:1981 |
|
540 |
" |
|
541 |
! |
|
542 |
||
543 |
daysInYear:yearInteger |
|
544 |
"return the number of days in a year" |
|
545 |
||
546 |
(self leapYear:yearInteger) ifTrue:[^ 366]. |
|
547 |
^ 365 |
|
548 |
||
549 |
" |
|
550 |
Date daysInYear:1900 |
|
551 |
Date daysInYear:1901 |
|
552 |
Date daysInYear:1904 |
|
553 |
Date daysInYear:1980 |
|
554 |
Date daysInYear:1981 |
|
555 |
" |
|
556 |
! |
|
557 |
||
558 |
daysUntilMonth:month forYear:yearInteger |
|
559 |
"given the name of a month and a year, return the number |
|
560 |
of days from 1st january to last of prev month of that year. |
|
561 |
Return 0 if the month name/index is invalid or is january. |
|
562 |
For your convenience, month maybe an integer or name-string." |
|
563 |
||
564 |
|monthIndex "{ Class: SmallInteger }" |
|
565 |
sumDays "{ Class: SmallInteger }" | |
|
566 |
||
567 |
month isInteger ifTrue:[ |
|
568 |
monthIndex := month |
|
569 |
] ifFalse:[ |
|
570 |
monthIndex := self indexOfMonth:month |
|
571 |
]. |
|
572 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
|
573 |
||
574 |
sumDays := 0. |
|
575 |
1 to:monthIndex-1 do:[:m | |
|
576 |
sumDays := sumDays + (self daysInMonthIndex:m forYear:yearInteger) |
|
577 |
]. |
|
578 |
^ sumDays |
|
579 |
||
580 |
" |
|
581 |
Date daysUntilMonth:'feb' forYear:1993 |
|
582 |
Date daysUntilMonth:'jan' forYear:1993 |
|
583 |
" |
|
584 |
! |
|
585 |
||
5778 | 586 |
firstDayOfYear:inYear |
587 |
"return the weekDay-index of the 1st-january of the given year. |
|
588 |
1->monday, 2->tuesday, ... 7->sunday" |
|
589 |
||
590 |
| t d | |
|
591 |
||
592 |
((inYear < 1) or:[ inYear > 9999]) ifTrue:[ |
|
593 |
^ 0. |
|
594 |
]. |
|
595 |
||
596 |
"/ normal Gregorian calendar: one extra day per four years |
|
597 |
t := 4 + inYear + ((inYear + 3) // 4). |
|
598 |
||
599 |
inYear > 1800 ifTrue:[ |
|
600 |
"/ Julian calendar: regular Gregorian less 3 days per 400 |
|
601 |
t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400). |
|
602 |
]. |
|
603 |
inYear > 1752 ifTrue:[ |
|
604 |
"/ calendar changeover |
|
605 |
t := t + 3. |
|
606 |
]. |
|
607 |
d := t \\ 7. |
|
608 |
"/ convert from 0 (sunday) .. 6 (saturday) |
|
609 |
"/ to 1 (munday) .. 7 (sunday) |
|
610 |
d == 0 ifTrue:[^ 7]. |
|
611 |
^ d |
|
612 |
||
613 |
" |
|
614 |
self firstDayOfYear:2000 |
|
615 |
(Date newDay:1 year:2000) dayInWeek |
|
616 |
self firstDayOfYear:1999 |
|
617 |
(Date newDay:1 year:1999) dayInWeek |
|
618 |
self firstDayOfYear:1998 |
|
619 |
(Date newDay:1 year:1998) dayInWeek |
|
620 |
self firstDayOfYear:2001 |
|
621 |
(Date newDay:1 year:2001) dayInWeek |
|
622 |
self firstDayOfYear:2002 |
|
623 |
(Date newDay:1 year:2002) dayInWeek |
|
624 |
self firstDayOfYear:2006 |
|
625 |
(Date newDay:1 year:2006) dayInWeek |
|
626 |
||
627 |
self firstDayOfYear:1800 |
|
628 |
(Date newDay:1 year:1800) dayInWeek |
|
629 |
" |
|
630 |
! |
|
631 |
||
699 | 632 |
indexOfMonth:aMonthString |
633 |
"given the name of a month (either string or symbol), |
|
634 |
return the month-index (1 for jan; 12 for december). |
|
635 |
The given string may be a full or abbreviated name, |
|
636 |
case is ignored. |
|
637 |
Return 0 for invalid month name." |
|
638 |
||
639 |
|idx name| |
|
640 |
||
641 |
EnvironmentChange ifTrue:[ |
|
642 |
self initNames |
|
643 |
]. |
|
644 |
name := aMonthString asLowercase. |
|
645 |
idx := MonthAbbrevs indexOf:name. |
|
646 |
idx ~~ 0 ifTrue:[^ idx]. |
|
647 |
idx := MonthNames indexOf:name. |
|
648 |
idx ~~ 0 ifTrue:[^ idx]. |
|
649 |
||
650 |
name at:1 put:(name at:1) asUppercase. |
|
651 |
idx := MonthAbbrevs indexOf:name. |
|
652 |
idx ~~ 0 ifTrue:[^ idx]. |
|
653 |
idx := MonthNames indexOf:name. |
|
654 |
idx ~~ 0 ifTrue:[^ idx]. |
|
655 |
||
656 |
^ idx |
|
657 |
||
658 |
" |
|
659 |
Date indexOfMonth:'jan' |
|
660 |
Date indexOfMonth:'Jan' |
|
661 |
Date indexOfMonth:'December' |
|
662 |
" |
|
663 |
! |
|
664 |
||
665 |
isLeapYear:yearInteger |
|
666 |
"Return true, if a year is a leap year. |
|
667 |
Obsolete: |
|
668 |
Please use the ST-80 compatible #leapYear for new programs, |
|
669 |
since this method will vanish." |
|
670 |
||
671 |
^ self leapYear:yearInteger |
|
672 |
! |
|
673 |
||
674 |
leapYear:yearInteger |
|
675 |
"return true, if yearInteger is a leap year." |
|
676 |
||
677 |
|y "{ Class: SmallInteger }"| |
|
678 |
||
679 |
y := yearInteger. |
|
680 |
(y \\ 4 == 0) ifTrue:[ |
|
681 |
(y \\ 100 ~~ 0) ifTrue:[^ true]. |
|
682 |
(y \\ 400 == 0) ifTrue:[^ true] |
|
683 |
]. |
|
684 |
^ false |
|
685 |
||
686 |
" |
|
687 |
Date leapYear:1992 |
|
688 |
Date leapYear:1994 |
|
689 |
Date leapYear:1900 |
|
690 |
Date leapYear:2000 |
|
691 |
" |
|
692 |
! |
|
693 |
||
694 |
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger |
|
695 |
"given a day-in-year (1..365) return an Array containing the |
|
696 |
month index and the day-in-month. Return nil if the argument is invalid." |
|
697 |
||
698 |
|restDays daysInMonth| |
|
699 |
||
700 |
restDays := aDayInYear. |
|
701 |
restDays < 1 ifTrue:[^ nil]. |
|
702 |
||
703 |
1 to:12 do:[:m | |
|
704 |
daysInMonth := self daysInMonthIndex:m forYear:yearInteger. |
|
705 |
restDays <= daysInMonth ifTrue:[ |
|
706 |
^ Array with:m with:restDays |
|
707 |
]. |
|
708 |
restDays := restDays - daysInMonth |
|
709 |
]. |
|
710 |
restDays > daysInMonth ifTrue:[^ nil]. |
|
711 |
^ Array with:12 with:restDays |
|
712 |
||
713 |
" |
|
714 |
Date monthAndDayFromDayInYear:66 forYear:1980 |
|
715 |
Date monthAndDayFromDayInYear:66 forYear:1981 |
|
716 |
" |
|
717 |
! |
|
718 |
||
719 |
nameOfDay:dayIndex |
|
720 |
"given a day index (1..7), return the name of the day" |
|
721 |
||
5830 | 722 |
(DayNames isNil or:[EnvironmentChange]) ifTrue:[ |
723 |
self initNames |
|
699 | 724 |
]. |
725 |
^ DayNames at:dayIndex |
|
726 |
||
727 |
" |
|
728 |
Date nameOfDay:4 |
|
729 |
" |
|
730 |
! |
|
731 |
||
732 |
nameOfMonth:monthIndex |
|
733 |
"given a month index (1..12), return the name of the month" |
|
734 |
||
5830 | 735 |
(MonthNames isNil or:[EnvironmentChange]) ifTrue:[ |
736 |
self initNames |
|
699 | 737 |
]. |
738 |
^ MonthNames at:monthIndex |
|
739 |
||
740 |
" |
|
741 |
Date nameOfMonth:11 |
|
742 |
Date nameOfMonth:12 |
|
743 |
Date nameOfMonth:4 |
|
744 |
" |
|
745 |
! |
|
746 |
||
5548 | 747 |
weekInYearOf:aDateOrTimestamp |
748 |
"for a given date or timeStamp, return the week-number. |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
749 |
the returned week number starts with 1 for the first week which has a thursday in it. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
750 |
The above definition can lead to the 1st week starting in the old year!!" |
5548 | 751 |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
752 |
|dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week| |
5548 | 753 |
|
754 |
dayInYear := aDateOrTimestamp dayInYear. |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
755 |
dayOfFirstWeekInYear := self dayOfFirstWeekInYear:aDateOrTimestamp year. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
756 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
757 |
numDays := aDateOrTimestamp asDate subtractDate:dayOfFirstWeekInYear asDate. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
758 |
"/ careful with the first days - could be W52/W53 of the previous year ... |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
759 |
numDays < 0 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
760 |
"/ not in a week here ... |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
761 |
"/ can be either 52 or 53, depending on the previous year. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
762 |
^ self weekInYearOf:(Date day:31 month:12 year:aDateOrTimestamp year - 1) |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
763 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
764 |
|
5548 | 765 |
"/ compute the week |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
766 |
week := numDays // 7 + 1. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
767 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
768 |
"/ careful with the last days - could be W01 of the next year ... |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
769 |
week == 53 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
770 |
dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
771 |
aDateOrTimestamp asDate >= dayOfFirstWeekInNextYear asDate ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
772 |
^ 1 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
773 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
774 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
775 |
^ week |
5548 | 776 |
|
777 |
" |
|
5663 | 778 |
AbsoluteTime now weekInYear |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
779 |
Date weekInYearOf:(Date day:31 month:12 year:1999) was a friday; |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
780 |
Date weekInYearOf:(AbsoluteTime newDay:1 year:2000) was a saturday; therefore last week of 1999 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
781 |
Date weekInYearOf:(AbsoluteTime newDay:2 year:2000) was a sunday; therefore last week of 1999 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
782 |
Date weekInYearOf:(AbsoluteTime newDay:3 year:2000) was a monday -> W01 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
783 |
Date weekInYearOf:(AbsoluteTime newDay:4 year:2000) was a tuesday -> W01 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
784 |
Date weekInYearOf:(AbsoluteTime newDay:5 year:2000) was a wed -> W01 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
785 |
Date weekInYearOf:(AbsoluteTime newDay:6 year:2000) was a thursday -> W01 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
786 |
Date weekInYearOf:(AbsoluteTime newDay:7 year:2000) was a fri -> W01 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
787 |
Date weekInYearOf:(AbsoluteTime newDay:8 year:2000) was a sat -> W01 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
788 |
Date weekInYearOf:(AbsoluteTime newDay:9 year:2000) was a sun -> W01 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
789 |
Date weekInYearOf:(AbsoluteTime newDay:10 year:2000) was a monday -> W02 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
790 |
Date weekInYearOf:(AbsoluteTime newDay:16 year:2000) was a sunday -> W02 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
791 |
Date weekInYearOf:(AbsoluteTime newDay:17 year:2000) was a monday -> W03 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
792 |
Date weekInYearOf:(Date day:1 month:1 year:2001) |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
793 |
Date weekInYearOf:(Date day:2 month:1 year:2001) |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
794 |
Date weekInYearOf:(Date day:3 month:1 year:2001) |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
795 |
Date weekInYearOf:(Date day:24 month:12 year:2001) -> W52 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
796 |
Date weekInYearOf:(Date day:30 month:12 year:2001) -> W52 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
797 |
Date weekInYearOf:(Date day:31 month:12 year:2001) -> W01 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
798 |
Date weekInYearOf:(Date day:1 month:1 year:2002) |
5778 | 799 |
Date weekInYearOf:(Date day:2 month:1 year:2002) |
800 |
Date weekInYearOf:(Date day:7 month:1 year:2002) |
|
5548 | 801 |
" |
802 |
! |
|
803 |
||
699 | 804 |
yearAsDays: yearInteger |
805 |
"Returns the number of days since Jan 1, 1901. (GNU) |
|
806 |
to the first Jan of the year, yearInteger. |
|
807 |
For 1901 this is zero, for 1902 its 365. |
|
808 |
Defined for years >= 1901" |
|
809 |
||
810 |
|y "{ Class: SmallInteger }"| |
|
811 |
||
812 |
y := yearInteger - 1900. |
|
813 |
y := y - 1. |
|
814 |
^ (y * 365) |
|
815 |
+ (y // 4) |
|
816 |
- (y // 100) |
|
817 |
+ ((y + 300) // 400) |
|
818 |
||
819 |
" |
|
820 |
Date yearAsDays:1901 |
|
821 |
Date yearAsDays:1902 |
|
822 |
Date yearAsDays:1903 |
|
823 |
Date yearAsDays:1904 |
|
824 |
Date yearAsDays:1905 |
|
825 |
Date yearAsDays:1994 |
|
826 |
(Date yearAsDays:2001) - (Date yearAsDays:2000) |
|
827 |
" |
|
828 |
! ! |
|
829 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
830 |
!Date class methodsFor:'handling language changes'! |
699 | 831 |
|
832 |
initialize |
|
833 |
"check for case where Resource-classes are absent" |
|
834 |
ResourcePack isNil ifTrue:[ |
|
835 |
self initNames |
|
836 |
] ifFalse:[ |
|
837 |
Smalltalk addDependent:self. |
|
838 |
EnvironmentChange := true |
|
839 |
] |
|
840 |
! |
|
841 |
||
1468 | 842 |
update:something with:aParameter from:changedObject |
699 | 843 |
((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[ |
1468 | 844 |
"just remember change for next access" |
845 |
EnvironmentChange := true |
|
699 | 846 |
] |
1468 | 847 |
|
848 |
"Created: 15.6.1996 / 15:19:25 / cg" |
|
699 | 849 |
! ! |
850 |
||
7646 | 851 |
|
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
852 |
!Date class methodsFor:'obsolete instance creation'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
853 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
854 |
day:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
855 |
"return a new Date, given the day, month and year. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
856 |
Obsolete: |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
857 |
use newDay:month:year: for ST-80 compatibility" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
858 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
859 |
^ self newDay:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
860 |
! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
861 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
862 |
day:dayInYear year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
863 |
"return a new Date, given the year and the day-in-year (starting at 1). |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
864 |
Obsolete: |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
865 |
use newDay:year: for ST-80 compatibility" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
866 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
867 |
^ self newDay:dayInYear year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
868 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
869 |
|
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
870 |
!Date class methodsFor:'private'! |
1 | 871 |
|
699 | 872 |
daysInMonthIndex: monthIndex forYear: yearInteger |
873 |
"return the number of days in month monthIndex of |
|
874 |
year yearInteger (modified GNU). |
|
875 |
Return 0 for invalid month index. |
|
876 |
This is the internal version of daysInMonth:forYear:" |
|
877 |
||
878 |
|days| |
|
879 |
||
880 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
|
881 |
||
882 |
days := #(31 28 31 "Jan Feb Mar" |
|
883 |
30 31 30 "Apr May Jun" |
|
884 |
31 31 30 "Jul Aug Sep" |
|
885 |
31 30 31 "Oct Nov Dec" |
|
886 |
) at: monthIndex. |
|
887 |
||
888 |
(monthIndex == 2) ifTrue:[ |
|
889 |
(self leapYear:yearInteger) ifTrue:[ |
|
890 |
^ days + 1 |
|
891 |
] |
|
892 |
]. |
|
893 |
^ days |
|
894 |
||
895 |
" |
|
896 |
Date daysInMonthIndex:2 forYear:1994 |
|
897 |
Date daysInMonthIndex:2 forYear:1980 |
|
898 |
Date daysInMonthIndex:2 forYear:1981 |
|
899 |
" |
|
900 |
! |
|
901 |
||
1 | 902 |
initNames |
903 |
"read the language specific names" |
|
904 |
||
10 | 905 |
|resources| |
906 |
||
54 | 907 |
DayNames := #('monday' |
155 | 908 |
'tuesday' |
909 |
'wednesday' |
|
910 |
'thursday' |
|
911 |
'friday' |
|
912 |
'saturday' |
|
913 |
'sunday'). |
|
1 | 914 |
|
54 | 915 |
DayAbbrevs := #('mon' |
155 | 916 |
'tue' |
917 |
'wed' |
|
918 |
'thu' |
|
919 |
'fri' |
|
920 |
'sat' |
|
921 |
'sun'). |
|
1 | 922 |
|
54 | 923 |
MonthNames := #('january' |
155 | 924 |
'february' |
925 |
'march' |
|
926 |
'april' |
|
927 |
'may' |
|
928 |
'june' |
|
929 |
'july' |
|
930 |
'august' |
|
931 |
'september' |
|
932 |
'october' |
|
933 |
'november' |
|
934 |
'december'). |
|
1 | 935 |
|
54 | 936 |
MonthAbbrevs := #('jan' |
155 | 937 |
'feb' |
938 |
'mar' |
|
939 |
'apr' |
|
940 |
'may' |
|
941 |
'jun' |
|
942 |
'jul' |
|
943 |
'aug' |
|
944 |
'sep' |
|
945 |
'oct' |
|
946 |
'nov' |
|
947 |
'dec'). |
|
54 | 948 |
|
949 |
"check for case where Resource-classes are absent" |
|
950 |
ResourcePack notNil ifTrue:[ |
|
155 | 951 |
resources := ResourcePack for:self. |
54 | 952 |
|
155 | 953 |
DayNames := resources array:DayNames. |
954 |
DayAbbrevs := resources array:DayAbbrevs. |
|
955 |
MonthNames := resources array:MonthNames. |
|
956 |
MonthAbbrevs := resources array:MonthAbbrevs. |
|
54 | 957 |
]. |
1 | 958 |
|
29 | 959 |
EnvironmentChange := false |
10 | 960 |
|
961 |
"Date initNames" |
|
54 | 962 |
! ! |
963 |
||
7258 | 964 |
!Date class methodsFor:'private-encoding'! |
54 | 965 |
|
966 |
encodeYear:y month:m day:d |
|
92 | 967 |
"the internal encoding is stricktly private, |
968 |
and should not be used outside." |
|
969 |
||
54 | 970 |
^ (((y * 100) + m) * 100) + d |
971 |
! ! |
|
972 |
||
7258 | 973 |
!Date class methodsFor:'private-instance creation'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
974 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
975 |
fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
976 |
"return a date, representing the date given by the operatingSystem time. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
977 |
This somewhat clumsy implementation hides the OS's date representation |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
978 |
(i.e. makes this class independent of what the OS starts its time values with). |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
979 |
Dont use this method, the osTime representation is totally unportable." |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
980 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
981 |
^ self basicNew fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
982 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
983 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
984 |
Date fromOSTime:#(0 0) -> on UNIX: this should return 1st Jan 1970 |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
985 |
thats where Unix time starts |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
986 |
On other systems, it may be something different. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
987 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
988 |
Date fromOSTime:#(86400 0) -> on UNIX: the day after |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
989 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
990 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
991 |
|
7646 | 992 |
|
7261 | 993 |
!Date methodsFor:'Compatibility-ANSI'! |
6419 | 994 |
|
995 |
dayOfWeek |
|
996 |
"return the week-day of the receiver - 1 is sunday, 7 for saturday. |
|
997 |
WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday). |
|
998 |
" |
|
999 |
||
1000 |
|d| |
|
1001 |
||
1002 |
d := self dayInWeek. |
|
1003 |
d == 7 ifTrue:[ |
|
1004 |
^ 1 |
|
1005 |
]. |
|
1006 |
^ d + 1 |
|
1007 |
||
1008 |
" |
|
1009 |
Date today dayOfWeek |
|
1010 |
Date today dayInWeek |
|
1011 |
" |
|
1012 |
! |
|
1013 |
||
1014 |
dayOfWeekAbbreviation |
|
1015 |
"return the short week-day of the receiver as a string. |
|
1016 |
The returned string depends on the language setting. |
|
1017 |
Expect things like 'mon', 'tue' ..." |
|
1018 |
||
1019 |
^ self abbreviatedDayName |
|
1020 |
||
1021 |
" |
|
1022 |
Date today dayOfWeekAbbreviation |
|
1023 |
" |
|
1024 |
! |
|
1025 |
||
1026 |
dayOfWeekName |
|
1027 |
"return the week-day of the receiver as a string. |
|
1028 |
The returned string depends on the language setting. |
|
1029 |
Expect things like 'monday', 'tuesday' ..." |
|
1030 |
||
1031 |
^ self weekday |
|
1032 |
||
1033 |
" |
|
1034 |
Date today dayOfWeekName |
|
1035 |
Date today dayOfWeekAbbreviation |
|
1036 |
" |
|
1037 |
! |
|
1038 |
||
1039 |
dayOfYear |
|
1040 |
"return the day-nr within the year of the receiver - 1..365/366" |
|
1041 |
||
1042 |
^ self dayInYear |
|
1043 |
||
1044 |
" |
|
1045 |
Date today dayOfYear |
|
1046 |
" |
|
1047 |
! |
|
1048 |
||
1049 |
isLeapYear |
|
1050 |
"return true, if the receivers year is a leap year" |
|
1051 |
||
1052 |
^ self leap |
|
1053 |
||
1054 |
" |
|
1055 |
Date today isLeapYear |
|
1056 |
(Date day:1 month:1 year:1992) isLeapYear |
|
1057 |
" |
|
1058 |
! |
|
1059 |
||
1060 |
monthAbbreviation |
|
1061 |
"return the month of the receiver as a string. |
|
1062 |
The returned string depends on the language setting. |
|
1063 |
Expect things like 'jan', 'feb' ..." |
|
1064 |
||
1065 |
^ self abbreviatedMonthName |
|
1066 |
||
1067 |
" |
|
1068 |
Date today monthAbbreviation |
|
1069 |
" |
|
1070 |
! ! |
|
1071 |
||
7261 | 1072 |
!Date methodsFor:'Compatibility-ST80'! |
5515 | 1073 |
|
6976 | 1074 |
previous:dayName |
1075 |
"Return the previous date whose weekday name is dayName. |
|
1076 |
Caveat; dayName is expected to be in the current language" |
|
1077 |
||
1078 |
^ self subtractDays:(self weekdayIndex - (self class dayOfWeek:dayName) - 1 \\ 7 + 1) |
|
1079 |
||
1080 |
" |
|
1081 |
Date today |
|
1082 |
Date today previous:#Monday |
|
1083 |
Date today previous:#Friday |
|
1084 |
" |
|
1085 |
! |
|
1086 |
||
7023 | 1087 |
printFormat:aFormatArray |
1088 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
1089 |
Return a string containing a printed representation of the receiver. |
|
1090 |
The formatArray argument consists of 6 or 7 integers which control |
|
1091 |
the resulting string. The entries are: |
|
1092 |
1 day position (1, 2 or 3) |
|
1093 |
2 month position (1..3) |
|
1094 |
3 year position (1..3) |
|
1095 |
4 asciiValue of separator character or separator character |
|
1096 |
or collection of 2 separator characters |
|
1097 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
1098 |
4: abbreviated uppercase 5: full uppercase) |
|
1099 |
6 year format (1 include century; 2 exclude century) |
|
1100 |
7 (optional) true/false. |
|
1101 |
if true, print numbers in 2-digit format |
|
1102 |
(i.e. with leading zeros); |
|
1103 |
Taken as false, if ommited |
|
1104 |
||
1105 |
Day and monthnames are in the currently active language. |
|
1106 |
||
1107 |
This method supports more options than the ST-80 version; month formats |
|
1108 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
1109 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
1110 |
||
1111 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
1112 |
This is an ST-80 compatibility method - I would have choosen another |
|
1113 |
(less cryptic) formatString ... |
|
1114 |
" |
|
1115 |
||
1116 |
|mf upperCase day month year components sep1 sep2 leadingZeros| |
|
1117 |
||
1118 |
aFormatArray size > 6 ifTrue:[ |
|
1119 |
leadingZeros := aFormatArray at:7 |
|
1120 |
] ifFalse:[ |
|
1121 |
leadingZeros := false. |
|
1122 |
]. |
|
1123 |
||
1124 |
components := Array new:3. |
|
1125 |
day := self day. |
|
1126 |
leadingZeros ifTrue:[ |
|
1127 |
day := day printStringLeftPaddedTo:2 with:$0 |
|
1128 |
] ifFalse:[ |
|
1129 |
day := day printString |
|
1130 |
]. |
|
1131 |
components at:(aFormatArray at:1) put:day. |
|
1132 |
||
1133 |
upperCase := false. |
|
1134 |
mf := aFormatArray at:5. |
|
1135 |
(mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true]. |
|
1136 |
||
1137 |
mf == 1 ifTrue:[ |
|
1138 |
month := self month. |
|
1139 |
leadingZeros ifTrue:[ |
|
1140 |
month := month printStringLeftPaddedTo:2 with:$0 |
|
1141 |
] ifFalse:[ |
|
1142 |
month := month printString |
|
1143 |
] |
|
1144 |
] ifFalse:[ |
|
1145 |
mf == 2 ifTrue:[ |
|
1146 |
month := self abbreviatedMonthName |
|
1147 |
] ifFalse:[ |
|
1148 |
month := self monthName |
|
1149 |
] |
|
1150 |
]. |
|
1151 |
upperCase ifTrue:[month := month asUppercase]. |
|
1152 |
components at:(aFormatArray at:2) put:month. |
|
1153 |
||
1154 |
year := self year. |
|
1155 |
(aFormatArray at:6) == 2 ifTrue:[ |
|
1156 |
year := year \\ 100. |
|
1157 |
year := year printStringLeftPaddedTo:2 with:$0 |
|
1158 |
]. |
|
1159 |
year := year printString. |
|
1160 |
components at:(aFormatArray at:3) put:year. |
|
1161 |
||
1162 |
sep1 := sep2 := (aFormatArray at:4). |
|
1163 |
sep1 isString ifFalse:[ |
|
1164 |
sep1 isCollection ifTrue:[ |
|
1165 |
sep2 := (sep1 at:2). |
|
1166 |
sep1 := (sep1 at:1). |
|
1167 |
] ifFalse:[ |
|
1168 |
sep1 := sep2 := sep1 asCharacter |
|
1169 |
] |
|
1170 |
]. |
|
1171 |
||
1172 |
^ (components at:1) |
|
1173 |
, sep1 asString |
|
1174 |
, (components at:2) |
|
1175 |
, sep2 asString |
|
1176 |
, (components at:3) |
|
1177 |
||
1178 |
" |
|
1179 |
Date today printFormat:#(1 2 3 '' 1 2) |
|
1180 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
1181 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
|
1182 |
Date today printFormat:#(2 1 3 32 3 1) |
|
1183 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
1184 |
Date today printFormat:#(1 2 3 $- 2 1) |
|
1185 |
Date today printFormat:#(1 2 3 $- 4 1) |
|
1186 |
" |
|
1187 |
! |
|
1188 |
||
1189 |
printFormat:aFormatArray on:aStream |
|
1190 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
1191 |
in printFormat:. |
|
1192 |
Append a printed representation of the receiver to aStream. |
|
1193 |
The argument, aFormatString controls the format, as described |
|
1194 |
in the #printFormat: method. |
|
1195 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
1196 |
||
1197 |
aStream nextPutAll:(self printFormat:aFormatArray) |
|
1198 |
||
1199 |
||
1200 |
"european formats: |
|
1201 |
||
1202 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
1203 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
1204 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1205 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
1206 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
1207 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
1208 |
||
1209 |
US formats: |
|
1210 |
||
1211 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
1212 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
1213 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
1214 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
1215 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
1216 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1217 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
1218 |
" |
|
1219 |
! |
|
1220 |
||
5515 | 1221 |
shortPrintString |
1222 |
"dummy - for now" |
|
1223 |
||
1224 |
^ self printString |
|
1225 |
||
1226 |
"Created: 20.6.1997 / 17:16:48 / cg" |
|
6976 | 1227 |
! |
1228 |
||
1229 |
weekdayIndex |
|
1230 |
"Return the day index; Monday=1, ... , Sunday=7" |
|
1231 |
||
1232 |
^ (self asDays + 1) \\ 7 + 1 "1 January 1901 was a Tuesday" |
|
1233 |
||
1234 |
" |
|
1235 |
Date today dayName |
|
1236 |
Date today weekdayIndex |
|
1237 |
" |
|
5515 | 1238 |
! ! |
1239 |
||
7261 | 1240 |
!Date methodsFor:'Compatibility-Squeak'! |
4407 | 1241 |
|
1242 |
mmddyyyy |
|
4462 | 1243 |
"return a printed representation of the receiver in the |
1244 |
form mmddyyyy. |
|
1245 |
The receiver can be reconstructed with: |
|
1246 |
Date readMMDDYYYYFrom:aStringOrStream onError:[...]" |
|
1247 |
||
4407 | 1248 |
^ (self month printStringLeftPaddedTo:2 with:$0) |
1249 |
, (self day printStringLeftPaddedTo:2 with:$0) |
|
1250 |
, (self year printStringLeftPaddedTo:4 with:$0) |
|
1251 |
||
1252 |
" |
|
1253 |
Date today mmddyyyy |
|
1254 |
" |
|
1255 |
! ! |
|
1256 |
||
699 | 1257 |
!Date methodsFor:'accessing'! |
241 | 1258 |
|
699 | 1259 |
abbreviatedDayName |
1260 |
"return the short week-day of the receiver as a string. |
|
1261 |
The returned string depends on the language setting. |
|
1262 |
Expect things like 'mon', 'tue' ..." |
|
54 | 1263 |
|
699 | 1264 |
^ self class abbreviatedNameOfDay:(self dayInWeek) |
92 | 1265 |
|
1266 |
" |
|
699 | 1267 |
Date today abbreviatedDayName |
1268 |
(Date day:15 month:4 year:1959) abbreviatedDayName |
|
92 | 1269 |
" |
1270 |
! |
|
1271 |
||
699 | 1272 |
abbreviatedMonthName |
1273 |
"return the month of the receiver as a string. |
|
1274 |
The returned string depends on the language setting. |
|
1275 |
Expect things like 'jan', 'feb' ..." |
|
54 | 1276 |
|
699 | 1277 |
^ self class abbreviatedNameOfMonth:(self month) |
68 | 1278 |
|
92 | 1279 |
" |
699 | 1280 |
Date today abbreviatedMonthName |
1281 |
(Date day:15 month:4 year:1959) abbreviatedMonthName |
|
92 | 1282 |
" |
1283 |
! |
|
1284 |
||
1285 |
asDays |
|
1286 |
"return the number of days elapsed since 01-Jan-1901 |
|
1287 |
and the receiver's day; starts with 0 for 1-1-1901. |
|
1288 |
Date>>fromDays: is the reverse operation. |
|
1289 |
For ST-80 compatibility." |
|
68 | 1290 |
|
1291 |
|yr| |
|
1292 |
||
1293 |
yr := self year. |
|
1294 |
^ (self class yearAsDays:yr) |
|
1295 |
+ (self class daysUntilMonth:self month forYear:yr) |
|
1296 |
+ self day |
|
85 | 1297 |
- 1 |
68 | 1298 |
|
92 | 1299 |
" |
1300 |
(Date day: 5 month: 8 year: 1962) asDays -> should be 22496 |
|
1301 |
(Date day: 1 month: 1 year: 1901) asDays -> 0 |
|
1302 |
Date today asDays |
|
1303 |
Date fromDays:(Date today asDays + 7) |
|
1304 |
" |
|
77 | 1305 |
! |
1306 |
||
1307 |
asSeconds |
|
92 | 1308 |
"return the seconds between 1.jan.1901 and the same time in the receivers |
1309 |
day. (i.e. midnight to midnight). |
|
1501 | 1310 |
This does not include any leapSeconds ... strictly speaking, this is incorrect. |
77 | 1311 |
ST-80 compatibility." |
1312 |
||
92 | 1313 |
^ 60*60*24 * self asDays |
77 | 1314 |
|
92 | 1315 |
" |
1316 |
(Date day: 5 month: 8 year: 1962) asSeconds |
|
1317 |
(Date day: 1 month: 1 year: 1901) asSeconds |
|
1318 |
(Date today addDays:7) asSeconds - Date today asSeconds |
|
1501 | 1319 |
" |
1320 |
||
1321 |
"Modified: 1.7.1996 / 14:19:17 / cg" |
|
699 | 1322 |
! |
1323 |
||
1324 |
day |
|
1325 |
"return the day (1..31) of the receiver" |
|
1326 |
||
1327 |
^ dateEncoding \\ 100 |
|
1328 |
||
1329 |
" |
|
1330 |
Date today day |
|
1331 |
" |
|
1332 |
! |
|
1333 |
||
1334 |
dayCount |
|
1335 |
"return the number of days since 1st. Jan. 1901; |
|
1336 |
starting with 0 for this date. |
|
1337 |
Date>>fromDays: is the reverse operation. |
|
1338 |
Obsolete: |
|
1339 |
please use asDays for ST-80 compatibility" |
|
1340 |
||
1341 |
^ self asDays. |
|
1342 |
||
1343 |
" |
|
1344 |
(Date day:1 month:1 year:1901) dayCount |
|
1345 |
Date fromDays:(Date day:1 month:1 year:1994) dayCount |
|
1346 |
Date today dayCount |
|
1347 |
" |
|
1348 |
! |
|
1349 |
||
1350 |
dayInWeek |
|
5778 | 1351 |
"return the week-day of the receiver - 1 for monday, 7 for sunday. |
6419 | 1352 |
WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday). |
5778 | 1353 |
WARNING: does not care for pre-julian dates |
1354 |
(i.e. do not use this for dates before 1752) |
|
1355 |
" |
|
699 | 1356 |
|
3256
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1357 |
|wday| |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1358 |
|
5778 | 1359 |
wday := (1 "knowing, that 1st Jan 1901 was a tuesday" |
3256
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1360 |
+ self asDays) \\ 7 + 1. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1361 |
wday < 1 ifTrue:[ |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1362 |
wday := wday + 7 |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1363 |
]. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1364 |
^ wday |
699 | 1365 |
|
1366 |
" |
|
5778 | 1367 |
Date today dayInWeek |
5548 | 1368 |
Date tomorrow dayInWeek |
1369 |
Date yesterday dayInWeek |
|
5778 | 1370 |
(Date today subtractDays:2) dayInWeek |
3257 | 1371 |
Date today weekday |
5548 | 1372 |
Date tomorrow weekday |
1373 |
Date yesterday weekday |
|
1501 | 1374 |
(Date day:15 month:4 year:1959) dayInWeek |
1375 |
(Date day:1 month:1 year:1901) dayInWeek |
|
3256
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1376 |
(Date day:31 month:12 year:1899) dayInWeek |
699 | 1377 |
" |
1501 | 1378 |
|
3257 | 1379 |
"Modified: / 1.2.1998 / 14:10:27 / cg" |
699 | 1380 |
! |
1381 |
||
5548 | 1382 |
dayInYear |
1383 |
"return the day-nr within the year of the receiver - 1 .. 365/366" |
|
1384 |
||
1385 |
^ self asAbsoluteTime dayInYear |
|
1386 |
||
1387 |
" |
|
1388 |
Date today dayInYear |
|
1389 |
(Date newDay:1 year:1999) dayInYear |
|
1390 |
(Date newDay:1 year:2000) dayInYear |
|
1391 |
(Date newDay:2 year:2000) dayInYear |
|
1392 |
" |
|
1393 |
! |
|
1394 |
||
699 | 1395 |
dayName |
1396 |
"return the week-day of the receiver as a string. |
|
1397 |
The returned string depends on the language setting. |
|
1398 |
Expect things like 'monday', 'tuesday' ... |
|
1399 |
Obsolete: |
|
1400 |
use #weekday for ST-80 compatibility" |
|
1401 |
||
1402 |
^ self weekday |
|
1403 |
! |
|
77 | 1404 |
|
1405 |
dayOfMonth |
|
1406 |
"Answer the day of the month represented by me. |
|
1407 |
Same as day; for ST-80 compatibility." |
|
1408 |
||
1409 |
^ self day |
|
92 | 1410 |
|
1411 |
" |
|
1412 |
Date today dayOfMonth |
|
1413 |
" |
|
1414 |
! |
|
1415 |
||
1416 |
daysInMonth |
|
1417 |
"return the number of days in the month of the receiver" |
|
1418 |
||
1419 |
^ Date daysInMonth:(self month) forYear:(self year) |
|
1420 |
||
1421 |
" |
|
1422 |
Date today daysInMonth |
|
1423 |
" |
|
1424 |
! |
|
1425 |
||
1426 |
daysInYear |
|
1427 |
"return the number of days in the year of the receiver" |
|
1428 |
||
1429 |
^ Date daysInYear:(self year) |
|
1430 |
||
1431 |
" |
|
1432 |
Date today daysInYear |
|
1433 |
" |
|
1434 |
! |
|
1435 |
||
5778 | 1436 |
daysLeftInMonth |
1437 |
"return the number of days left in the month of the receiver" |
|
1438 |
||
1439 |
^ self daysInMonth - self day |
|
1440 |
||
1441 |
" |
|
1442 |
Date today daysLeftInMonth |
|
1443 |
" |
|
1444 |
! |
|
1445 |
||
92 | 1446 |
daysLeftInYear |
1447 |
"return the number of days left in the year of the receiver" |
|
1448 |
||
5282 | 1449 |
^ (Date daysInYear:(self year)) - self day |
92 | 1450 |
|
1451 |
" |
|
5282 | 1452 |
Date today daysLeftInYear |
92 | 1453 |
" |
77 | 1454 |
! |
1455 |
||
699 | 1456 |
leap |
1457 |
"return true, if the receivers year is a leap year" |
|
68 | 1458 |
|
699 | 1459 |
^ Date leapYear:(self year) |
68 | 1460 |
|
92 | 1461 |
" |
699 | 1462 |
Date today leap |
1463 |
(Date day:1 month:1 year:1992) leap |
|
92 | 1464 |
" |
68 | 1465 |
! |
1466 |
||
699 | 1467 |
month |
1468 |
"return the month (1..12) of the receiver" |
|
92 | 1469 |
|
699 | 1470 |
^ (dateEncoding // 100) \\ 100 |
68 | 1471 |
|
92 | 1472 |
" |
699 | 1473 |
Date today month |
92 | 1474 |
" |
68 | 1475 |
! |
1476 |
||
77 | 1477 |
monthIndex |
1478 |
"return the index of the month (e.g. Feb.=2). |
|
1479 |
Same as month; for ST-80 compatibility." |
|
1480 |
||
1481 |
^ self month |
|
1482 |
! |
|
1483 |
||
68 | 1484 |
monthName |
1485 |
"return the month of the receiver as a string. |
|
1486 |
The returned string depends on the language setting. |
|
1487 |
Expect things like 'january', 'february' ..." |
|
1488 |
||
1489 |
^ self class nameOfMonth:(self month) |
|
1490 |
||
92 | 1491 |
" |
1492 |
Date today monthName |
|
1493 |
(Date day:15 month:4 year:1959) monthName |
|
1494 |
" |
|
68 | 1495 |
! |
1496 |
||
5548 | 1497 |
weekInYear |
1498 |
"return the week number of the receiver - 1 for Jan, 1st. |
|
1499 |
each week is Mon .. Sun (i.e. Sunday belongs to the previous week)" |
|
1500 |
||
1501 |
^ self class weekInYearOf:self |
|
1502 |
||
1503 |
" |
|
1504 |
Date today weekInYear |
|
1505 |
(Date newDay:1 year:2000) weekInYear was a saturday |
|
1506 |
(Date newDay:2 year:2000) weekInYear was a sunday |
|
1507 |
(Date newDay:3 year:2000) weekInYear was a monday |
|
1508 |
(Date newDay:4 year:2000) weekInYear was a tuesday |
|
1509 |
(Date newDay:5 year:2000) weekInYear was a wed |
|
1510 |
(Date newDay:6 year:2000) weekInYear was a thursday |
|
1511 |
(Date newDay:7 year:2000) weekInYear was a fri |
|
1512 |
(Date newDay:8 year:2000) weekInYear was a sat |
|
1513 |
(Date newDay:9 year:2000) weekInYear was a sun |
|
1514 |
(Date newDay:10 year:2000) weekInYear was a monday |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1515 |
(Date day:3 month:1 year:2001) weekInYear |
5548 | 1516 |
" |
1517 |
! |
|
1518 |
||
699 | 1519 |
weekday |
1520 |
"return the week-day of the receiver as a string. |
|
68 | 1521 |
The returned string depends on the language setting. |
699 | 1522 |
Expect things like 'monday', 'tuesday' ... |
1523 |
For ST-80 compatibility" |
|
1524 |
||
1525 |
^ self class nameOfDay:(self dayInWeek) |
|
1526 |
||
1527 |
" |
|
1528 |
Date today weekday |
|
1529 |
(Date day:15 month:4 year:1959) weekday |
|
1530 |
" |
|
1531 |
! |
|
1532 |
||
1533 |
year |
|
1534 |
"return the year (1..12) of the receiver" |
|
1535 |
||
1536 |
^ dateEncoding // (100*100) |
|
68 | 1537 |
|
699 | 1538 |
" |
1539 |
Date today year |
|
1540 |
" |
|
1541 |
! ! |
|
1542 |
||
1543 |
!Date methodsFor:'arithmetic'! |
|
1544 |
||
1545 |
addDays:days |
|
1546 |
"return a new date representing 'days' after the receiver. |
|
1547 |
The argument should be some kind of integer. |
|
1548 |
For ST-80 compatibility." |
|
1549 |
||
1550 |
^ self class fromDays:(self asDays + days) |
|
1551 |
||
1552 |
" |
|
1553 |
Date today addDays:7 |
|
1554 |
" |
|
1555 |
! |
|
1556 |
||
1557 |
daysUntil:aDate |
|
1558 |
"return the number of days between the receiver and the argument, |
|
1559 |
aDate, whuch should be some kind of date" |
|
1560 |
||
1561 |
^ aDate asDays - self asDays |
|
68 | 1562 |
|
92 | 1563 |
" |
699 | 1564 |
(Date day:24 month:12 year:1994) daysUntil:(Date day:1 month:1 year:1995) |
1565 |
(Date day:1 month:2 year:1992) daysUntil:(Date day:1 month:3 year:1992) |
|
1566 |
(Date day:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994) |
|
1567 |
||
1568 |
|delta| |
|
1569 |
delta := Date today |
|
1570 |
daysUntil:(Date day:25 month:12 year:Date today year). |
|
1571 |
Transcript show:'still '; |
|
1572 |
show:delta ; |
|
1422 | 1573 |
showCR:' days till xmas' |
699 | 1574 |
" |
1575 |
! |
|
1576 |
||
1577 |
minusDays:days |
|
1578 |
"return a new date representing 'days' before the receiver. |
|
1579 |
The argument should be some kind of integer. |
|
1580 |
Obsolete: |
|
1581 |
Please dont use this method since it will vanish. |
|
1582 |
Use #subtractDays: instead for ST-80 compatibility." |
|
1583 |
||
1584 |
^ self subtractDays:days |
|
1585 |
! |
|
1586 |
||
1587 |
plusDays:days |
|
1588 |
"return a new date representing 'days' after the receiver. |
|
1589 |
The argument should be some kind of integer. |
|
1590 |
Obsolete: |
|
1591 |
Please dont use this method since it will vanish. |
|
1592 |
Use #addDays: instead for ST-80 compatibility." |
|
1593 |
||
1594 |
^ self addDays:days |
|
1595 |
! |
|
1596 |
||
1597 |
subtractDate:aDate |
|
1598 |
"return the number of days between the receiver and aDate" |
|
1599 |
||
1600 |
^ self asDays - aDate asDays |
|
1601 |
||
1602 |
" |
|
1603 |
(Date day:1 month:1 year:1995) subtractDate:(Date day:24 month:12 year:1994) |
|
1604 |
(Date day:1 month:3 year:1992) subtractDate:(Date day:1 month:2 year:1992) |
|
1605 |
(Date day:1 month:3 year:1994) subtractDate:(Date day:1 month:2 year:1994) |
|
1606 |
" |
|
1607 |
! |
|
1608 |
||
1609 |
subtractDays:days |
|
1610 |
"return a new date representing 'days' before the receiver. |
|
1611 |
The argument should be some kind of integer. |
|
1612 |
For ST-80 compatibility" |
|
1613 |
||
1614 |
^ self class fromDays:(self asDays - days) |
|
1615 |
||
1616 |
" |
|
1617 |
Date today subtractDays:7 |
|
92 | 1618 |
" |
1 | 1619 |
! ! |
1620 |
||
1621 |
!Date methodsFor:'comparing'! |
|
1622 |
||
29 | 1623 |
< aDate |
1624 |
"return true, if the date represented by the receiver |
|
1625 |
is before the argument, aDate" |
|
1626 |
||
54 | 1627 |
(aDate isMemberOf:Date) ifTrue:[ |
155 | 1628 |
^ dateEncoding < aDate dateEncoding |
54 | 1629 |
]. |
29 | 1630 |
|
54 | 1631 |
"the argument must understand year, month and day to be |
1632 |
comparable, whatever it is" |
|
1633 |
||
1634 |
^ dateEncoding < (Date encodeYear:aDate year |
|
155 | 1635 |
month:aDate month |
1636 |
day:aDate day) |
|
68 | 1637 |
|
1638 |
"Date today < (Date day:24 month:12 year:2000)" |
|
1639 |
"Date today < (Date day:24 month:12 year:1900)" |
|
29 | 1640 |
! |
1 | 1641 |
|
1642 |
= aDate |
|
1643 |
"return true, if the date represented by the receiver |
|
1644 |
is the same as the one represented by argument, aDate" |
|
1645 |
||
155 | 1646 |
(aDate isMemberOf:Date) ifFalse:[^ false]. |
1647 |
||
1648 |
^ dateEncoding = aDate dateEncoding |
|
54 | 1649 |
|
1650 |
"the argument must understand year, month and day to be |
|
1651 |
comparable, whatever it is" |
|
1652 |
||
155 | 1653 |
" |
54 | 1654 |
^ dateEncoding = (Date encodeYear:aDate year |
155 | 1655 |
month:aDate month |
1656 |
day:aDate day) |
|
1657 |
" |
|
68 | 1658 |
"Date today = ((Date today plusDays:7) minusDays:7)" |
92 | 1659 |
! |
1660 |
||
699 | 1661 |
> aDate |
1662 |
"return true, if the date represented by the receiver |
|
1663 |
is after the argument, aDate" |
|
1664 |
||
1665 |
(aDate isMemberOf:Date) ifTrue:[ |
|
1666 |
^ dateEncoding > aDate dateEncoding |
|
1667 |
]. |
|
1668 |
||
1669 |
"the argument must understand year, month and day to be |
|
1670 |
comparable, whatever it is" |
|
1671 |
||
1672 |
^ dateEncoding > (Date encodeYear:aDate year |
|
1673 |
month:aDate month |
|
1674 |
day:aDate day) |
|
1675 |
||
1676 |
"Date today > (Date day:24 month:12 year:2000)" |
|
1677 |
"Date today > (Date day:24 month:12 year:1900)" |
|
1678 |
! |
|
1679 |
||
92 | 1680 |
hash |
1681 |
"return an integer useful for hashing on dates" |
|
1682 |
||
1683 |
^ dateEncoding |
|
1 | 1684 |
! ! |
1685 |
||
1501 | 1686 |
!Date methodsFor:'converting'! |
1687 |
||
1688 |
asAbsoluteTime |
|
5679 | 1689 |
"return an absoluteTime instance, representing midnight of last night" |
1501 | 1690 |
|
4379 | 1691 |
^ AbsoluteTime year:(self year) month:(self month) day:(self day) |
1692 |
hour:0 minute:0 second:0 millisecond:0 |
|
1501 | 1693 |
|
1694 |
" |
|
1695 |
Date today asAbsoluteTime |
|
1696 |
" |
|
1697 |
||
4379 | 1698 |
"Modified: / 1.7.1996 / 14:53:32 / cg" |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1699 |
"Modified: / 13.7.1999 / 12:31:47 / stefan" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1700 |
! |
4408 | 1701 |
|
1702 |
asDate |
|
1703 |
"return the receiver" |
|
1704 |
||
1705 |
^ self |
|
5679 | 1706 |
! |
1707 |
||
1708 |
asTimestamp |
|
1709 |
"return an absoluteTime instance, representing midnight of last night" |
|
1710 |
||
1711 |
^ self asAbsoluteTime |
|
1712 |
||
1713 |
" |
|
1714 |
Date today asTimestamp |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1715 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1716 |
! ! |
1501 | 1717 |
|
7646 | 1718 |
|
54 | 1719 |
!Date methodsFor:'printing & storing'! |
1 | 1720 |
|
5778 | 1721 |
addPrintBindingsTo:aDictionary |
1722 |
"add bindings for printing to aDictionary." |
|
1723 |
||
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1724 |
|d ds ds0 dsB m ms ms0 msB y w mn dn ws ws0 dw| |
5778 | 1725 |
|
1726 |
d := self day. |
|
1727 |
ds := d printString. |
|
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1728 |
dsB := d printStringLeftPaddedTo:2. |
5778 | 1729 |
ds0 := d printStringLeftPaddedTo:2 with:$0. |
1730 |
||
1731 |
m := self month. |
|
1732 |
ms := m printString. |
|
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1733 |
msB := m printStringLeftPaddedTo:2. |
5778 | 1734 |
ms0 := m printStringLeftPaddedTo:2 with:$0. |
1735 |
||
1736 |
y := self year. |
|
1737 |
w := self weekInYear. |
|
1738 |
ws := w printString. |
|
1739 |
ws0 := w printStringLeftPaddedTo:2 with:$0. |
|
1740 |
mn := self monthName. |
|
1741 |
dn := self dayName. |
|
1742 |
||
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1743 |
aDictionary at:#day put:ds0. "/ 0-padded |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1744 |
aDictionary at:#dayPadded put:dsB. "/ Blank-padded |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1745 |
aDictionary at:#Day put:ds. "/ unpadded |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1746 |
|
5827
71a6e54e02e5
same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents:
5778
diff
changeset
|
1747 |
aDictionary at:#month put:ms0. "/ 0-padded |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1748 |
aDictionary at:#monthPadded put:ms0. "/ Blank-padded |
5827
71a6e54e02e5
same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents:
5778
diff
changeset
|
1749 |
aDictionary at:#Month put:ms. "/ unpadded |
71a6e54e02e5
same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents:
5778
diff
changeset
|
1750 |
aDictionary at:#mon put:ms0. "/ 0-padded - for backward compatibility only |
71a6e54e02e5
same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents:
5778
diff
changeset
|
1751 |
aDictionary at:#Mon put:ms. "/ unpadded - for backward compatibility only |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1752 |
|
5827
71a6e54e02e5
same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents:
5778
diff
changeset
|
1753 |
aDictionary at:#year put:y. "/ padded |
5778 | 1754 |
aDictionary at:#week put:ws0. |
1755 |
aDictionary at:#Week put:ws. |
|
1756 |
||
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1757 |
y ~~ Date today year ifTrue:[ |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1758 |
aDictionary at:#yearOrTime put:(' ' , y printString). |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1759 |
]. |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
1760 |
|
5778 | 1761 |
aDictionary at:$d put:ds0. |
1762 |
aDictionary at:$D put:ds. |
|
1763 |
aDictionary at:$m put:ms0. |
|
1764 |
aDictionary at:$M put:ms. |
|
1765 |
aDictionary at:$y put:y. |
|
1766 |
aDictionary at:$Y put:((y \\ 100)printStringLeftPaddedTo:2 with:$0). |
|
1767 |
aDictionary at:$w put:ws0. |
|
1768 |
aDictionary at:$W put:ws. |
|
1769 |
||
1770 |
aDictionary at:#monthName put:mn. |
|
1771 |
aDictionary at:#MonthName put:mn asUppercaseFirst. |
|
1772 |
aDictionary at:#MONTHNAME put:mn asUppercase. |
|
1773 |
||
1774 |
aDictionary at:#dayName put:dn. |
|
1775 |
aDictionary at:#DayName put:dn asUppercaseFirst. |
|
1776 |
aDictionary at:#DAYNAME put:dn asUppercase. |
|
1777 |
||
5827
71a6e54e02e5
same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents:
5778
diff
changeset
|
1778 |
aDictionary at:#weekDay put:(dw := self dayInWeek). |
6419 | 1779 |
aDictionary at:#weekDayUS put:(dw := self dayOfWeek). |
1780 |
||
5827
71a6e54e02e5
same format-codes in printFormat as AbsoluteTIme
Claus Gittinger <cg@exept.de>
parents:
5778
diff
changeset
|
1781 |
aDictionary at:#dayInWeek put:dw. "/ for backward compatibility only |
5778 | 1782 |
aDictionary at:#shortDayName put:(dn := self abbreviatedDayName). |
1783 |
aDictionary at:#ShortDayName put:dn asUppercaseFirst. |
|
1784 |
aDictionary at:#SHORTDAYNAME put:dn asUppercase. |
|
1785 |
||
1786 |
aDictionary at:#shortMonthName put:(mn := self abbreviatedMonthName). |
|
1787 |
aDictionary at:#ShortMonthName put:mn asUppercaseFirst. |
|
1788 |
aDictionary at:#SHORTMONTHNAME put:mn asUppercase. |
|
1789 |
||
7327 | 1790 |
aDictionary at:#nth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:d \\ 10 + 1). |
1791 |
"/ 0 1 2 3 4 5 6 7 8 9 |
|
1792 |
aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:dw-1 \\ 10 + 1). |
|
1793 |
"/ 0 1 2 3 4 5 6 |
|
1794 |
aDictionary at:#weekNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:w \\ 10 + 1). |
|
1795 |
"/ 0 1 2 3 4 5 6 7 8 9 |
|
5778 | 1796 |
! |
1797 |
||
699 | 1798 |
printOn:aStream |
1799 |
"append a printed representation of the receiver to aStream" |
|
1800 |
||
1801 |
self printFormat:#(1 2 3 $- 2 1) on:aStream |
|
1802 |
||
1803 |
" |
|
1804 |
Date today printOn:Transcript |
|
1805 |
Date today printNL |
|
1806 |
" |
|
1807 |
||
1808 |
"Modified: 27.8.1995 / 01:01:49 / claus" |
|
1809 |
! |
|
1810 |
||
7023 | 1811 |
printOn:aStream format:aFormatStringOrSqueakFormatArray |
5778 | 1812 |
"print using a format string; |
1813 |
valid format items are: |
|
1814 |
%d day, 01..31 0-padded to length 2 |
|
1815 |
%m month, 01..12 0-padded to length 2 |
|
1816 |
%w week in year, 00..53 0-padded to length 2 |
|
1817 |
%y year, full |
|
1818 |
||
1819 |
special: |
|
1820 |
%D day - unpadded |
|
1821 |
%M month - unpadded |
|
1822 |
%W week in year - unpadded |
|
1823 |
%Y year, last 2 digits only (danger) |
|
1824 |
||
1825 |
%weekDay - day in week (1->monday, 2->tuesday, ... ,7->sunday) |
|
1826 |
||
1827 |
%dayName - full day name |
|
1828 |
%DayName - full day name, first character uppercase |
|
1829 |
%DAYNAME - full day name, all uppercase |
|
1830 |
||
1831 |
%monthName - full month name |
|
1832 |
%MonthName - full month name, first character uppercase |
|
1833 |
%MONTHNAME - full month name, all uppercase |
|
1834 |
||
1835 |
%shortDayName - short (abbreviated) day name |
|
1836 |
%ShortDayName - short (abbreviated) day name, first character uppercase |
|
1837 |
%SHORTDAYNAME - short (abbreviated) day name, all uppercase |
|
1838 |
||
1839 |
%shortMonthName - short (abbreviated) month name |
|
1840 |
%ShortMonthName - short (abbreviated) month name, first character uppercase |
|
1841 |
%SHORTMONTHNAME - short (abbreviated) month name, all uppercase |
|
1842 |
||
1843 |
%nth - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
7327 | 1844 |
%weekDayNth - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
1845 |
%weekNth - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
7023 | 1846 |
|
1847 |
for ST80/squeak compatibility (which expects a format-array), the following is also supported: |
|
1848 |
#(item item item sep monthfmt yearfmt twoDigits) |
|
1849 |
items: 1=day 2=month 3=year will appear in the order given, |
|
1850 |
separated by sep which is eaither an ascii code or character. |
|
1851 |
monthFmt: 1=09 2=Sep 3=September |
|
1852 |
yearFmt: 1=1996 2=96 |
|
1853 |
digits: (missing or)1=9 2=09. |
|
5778 | 1854 |
" |
1855 |
||
7023 | 1856 |
aFormatStringOrSqueakFormatArray isArray ifTrue:[ |
1857 |
"/ a squeak format array |
|
1858 |
^ self printFormat:aFormatStringOrSqueakFormatArray on:aStream |
|
1859 |
]. |
|
1860 |
||
1861 |
aStream nextPutAll:(self printStringFormat:aFormatStringOrSqueakFormatArray) |
|
5778 | 1862 |
|
1863 |
" |
|
1864 |
Date today printOn:Transcript format:'%y%m%d' (iso format) |
|
1865 |
Date today printOn:Transcript format:'%y-%m-%d' (iso format) |
|
1866 |
Date today printOn:Transcript format:'%y-W%w' (iso format - working week) |
|
1867 |
Date today printOn:Transcript format:'%d-%m-%y' (european trivia format) |
|
1868 |
Date today printOn:Transcript format:'%m/%d/%y' (us trivia format) |
|
1869 |
Date today printOn:Transcript format:'%D-%(monthName)-%y' (us trivia format) |
|
1870 |
Date today printOn:Transcript format:'%D-%(MonthName)-%y' (us trivia format) |
|
1871 |
Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
1872 |
Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
1873 |
Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
1874 |
Date today printOn:Transcript format:'%d%m%Y' (millenium bug format - danger) |
|
1875 |
Date today printOn:Transcript format:'Today is the %(weekDay) day of the week' |
|
1876 |
" |
|
7023 | 1877 |
" |
1878 |
String streamContents:[:s | |
|
1879 |
Date today printOn:s format:#(1 2 3 $/ 1 2) |
|
1880 |
] |
|
1881 |
" |
|
5778 | 1882 |
! |
1883 |
||
7023 | 1884 |
printStringFormat:aFormatStringOrArray |
5778 | 1885 |
"print using a format string; |
1886 |
valid format items are: |
|
1887 |
%d day, 01..31 0-padded to length 2 |
|
1888 |
%m month, 01..12 0-padded to length 2 |
|
1889 |
%w week in year, 00..53 0-padded to length 2 |
|
1890 |
%y year, full |
|
1891 |
||
1892 |
special: |
|
1893 |
%D day - unpadded |
|
1894 |
%M month - unpadded |
|
1895 |
%W week in year - unpadded |
|
1896 |
%Y year, last 2 digits only (danger) |
|
1897 |
||
1898 |
%weekDay - day in week (1->monday, 2->tuesday, ... ,7->sunday) |
|
6419 | 1899 |
%weekDayUS - day in week (1->sunday, 2->monday, ... ,7->saturday) |
5778 | 1900 |
|
1901 |
%dayName - full day name |
|
1902 |
%DayName - full day name, first character uppercase |
|
1903 |
%DAYNAME - full day name, all uppercase |
|
1904 |
||
1905 |
%monthName - full month name |
|
1906 |
%MonthName - full month name, first character uppercase |
|
1907 |
%MONTHNAME - full month name, all uppercase |
|
1908 |
||
1909 |
%shortDayName - short (abbreviated) day name |
|
1910 |
%ShortDayName - short (abbreviated) day name, first character uppercase |
|
1911 |
%SHORTDAYNAME - short (abbreviated) day name, all uppercase |
|
1912 |
||
1913 |
%shortMonthName - short (abbreviated) month name |
|
1914 |
%ShortMonthName - short (abbreviated) month name, first character uppercase |
|
1915 |
%SHORTMONTHNAME - short (abbreviated) month name, all uppercase |
|
1916 |
||
1917 |
%nth - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
7327 | 1918 |
%weekDayNth - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
1919 |
%weekNth - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
5778 | 1920 |
" |
1921 |
||
1922 |
|dict| |
|
1923 |
||
1924 |
dict := IdentityDictionary new. |
|
1925 |
self addPrintBindingsTo:dict. |
|
1926 |
||
7023 | 1927 |
^ (aFormatStringOrArray expandPlaceholdersWith:dict) |
5778 | 1928 |
|
1929 |
" |
|
1930 |
Date today printStringFormat:'%y%m%d' (iso format) |
|
1931 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
|
1932 |
Date today printStringFormat:'%y-W%w' (iso format - working week) |
|
1933 |
Date today printStringFormat:'%d-%m-%y' (european trivia format) |
|
1934 |
Date today printStringFormat:'%m/%d/%y' (us trivia format) |
|
1935 |
Date today printStringFormat:'%D-%(monthName)-%y' (us trivia format) |
|
1936 |
Date today printStringFormat:'%D-%(MonthName)-%y' (us trivia format) |
|
1937 |
Date today printStringFormat:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
1938 |
Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
1939 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
1940 |
Date today printStringFormat:'%d%m%Y' (millenium bug format - danger) |
|
7327 | 1941 |
Date today printStringFormat:'Today is day %(weekDay) of the week' |
1942 |
Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week' |
|
1943 |
Date today printStringFormat:'Today is the %(Day)%(nth) day of the month' |
|
5778 | 1944 |
" |
1945 |
! |
|
1946 |
||
699 | 1947 |
storeOn:aStream |
1948 |
"append a representation to aStream, from which the receiver |
|
1949 |
can be reconstructed" |
|
1950 |
||
1951 |
aStream nextPutAll:'('; nextPutAll:'Date day:'. |
|
1952 |
self day printOn:aStream. |
|
1953 |
aStream nextPutAll:' month:'. |
|
1954 |
self month printOn:aStream. |
|
1955 |
aStream nextPutAll:' year:'. |
|
1956 |
self year printOn:aStream. |
|
1957 |
aStream nextPutAll:')' |
|
1958 |
||
1959 |
" |
|
1960 |
Date today storeOn:Transcript |
|
1961 |
Date today storeString |
|
1962 |
" |
|
1 | 1963 |
! ! |
699 | 1964 |
|
7646 | 1965 |
|
7258 | 1966 |
!Date methodsFor:'private-accessing'! |
699 | 1967 |
|
1968 |
dateEncoding |
|
1969 |
"the internal encoding is stricktly private, |
|
1970 |
and should not be used outside." |
|
1971 |
||
1972 |
^ dateEncoding |
|
1973 |
! |
|
1974 |
||
1975 |
dateEncoding:anInteger |
|
1976 |
"the internal encoding is stricktly private, |
|
1977 |
and should not be used outside." |
|
1978 |
||
1979 |
dateEncoding := anInteger |
|
1980 |
! |
|
1981 |
||
1982 |
fromOSTime:osTime |
|
1983 |
"set my dateEncoding from an OS time. |
|
1984 |
This somewhat clumsy implementation hides the OS's date representation |
|
1985 |
(i.e. makes this class independent of what the OS starts its time values with). |
|
1986 |
Dont use this method, the osTime representation is totally unportable." |
|
1987 |
||
5858 | 1988 |
|v y m d| |
1989 |
||
1990 |
v := OperatingSystem computeTimeAndDateFrom:osTime. |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1991 |
y := v year. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1992 |
m := v month. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1993 |
d := v day. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1994 |
|
5858 | 1995 |
dateEncoding := (((y * 100) + m) * 100) + d |
1501 | 1996 |
|
1997 |
"Modified: 1.7.1996 / 15:23:12 / cg" |
|
699 | 1998 |
! ! |
1999 |
||
7646 | 2000 |
|
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
2001 |
!Date class methodsFor:'documentation'! |
699 | 2002 |
|
2003 |
version |
|
7648 | 2004 |
^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.76 2003-10-09 16:09:39 cg Exp $' |
699 | 2005 |
! ! |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
2006 |
|
699 | 2007 |
Date initialize! |