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 |
|
54
|
13 |
Magnitude subclass:#Date
|
699
|
14 |
instanceVariableNames:'dateEncoding'
|
|
15 |
classVariableNames:'DayNames MonthNames DayAbbrevs MonthAbbrevs EnvironmentChange'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Magnitude-General'
|
1
|
18 |
!
|
|
19 |
|
54
|
20 |
!Date class methodsFor:'documentation'!
|
|
21 |
|
88
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
155
|
25 |
All Rights Reserved
|
88
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
54
|
36 |
documentation
|
|
37 |
"
|
92
|
38 |
Instances of Date represent dates as year, month and day encoded in the
|
|
39 |
(private & hidden) instance dateEncoding. The value found there is
|
|
40 |
year*100*100 + month*100 + day (which makes magnitude-like comparison of
|
|
41 |
dates easy, but is not guaranteed for future versions).
|
54
|
42 |
|
92
|
43 |
The old representation used days since 1st Jan. 1901 internally -
|
|
44 |
with the new implementation, it is possible to reasonably represent almost
|
|
45 |
any Date. (which insurance companies will like, since they can now
|
|
46 |
represent even very old peoples birthday :-)
|
68
|
47 |
Notice: no correction for pre-Julian dates is done.
|
54
|
48 |
|
92
|
49 |
The printed representation of dates is controlled by resource definitions -
|
|
50 |
thus national variants are already supported (see file 'resources/Date.rs').
|
|
51 |
|
|
52 |
Compatibility notice:
|
155
|
53 |
due to some historic reasons, there are some methods found twice
|
|
54 |
with different names in this class. The old ST/X methods will vanish in
|
241
|
55 |
one of the next releases, and kept for a while to support existing
|
155
|
56 |
applications (the info on how these methods should be named came
|
|
57 |
somewhat late from the testers ..).
|
92
|
58 |
|
155
|
59 |
Please do not use methods marked as obsolete in their comment.
|
92
|
60 |
|
|
61 |
Most useful methods:
|
|
62 |
|
155
|
63 |
Date today
|
|
64 |
(Date today) addDays:
|
|
65 |
(Date today) subtractDays:
|
54
|
66 |
"
|
|
67 |
! !
|
|
68 |
|
699
|
69 |
!Date class methodsFor:'instance creation'!
|
|
70 |
|
|
71 |
day:day month:month year:year
|
|
72 |
"return a new Date, given the day, month and year.
|
|
73 |
Obsolete:
|
|
74 |
use newDay:month:year: for ST-80 compatibility"
|
|
75 |
|
|
76 |
^ self newDay:day month:month year:year
|
|
77 |
!
|
|
78 |
|
|
79 |
day:dayInYear year:year
|
|
80 |
"return a new Date, given the year and the day-in-year (starting at 1).
|
|
81 |
Obsolete:
|
|
82 |
use newDay:year: for ST-80 compatibility"
|
|
83 |
|
|
84 |
^ self newDay:dayInYear year:year
|
|
85 |
!
|
|
86 |
|
|
87 |
fromDays:dayCount
|
|
88 |
"return a new Date, given the day-number starting with 0 at 1.Jan 1901;
|
|
89 |
(i.e. 'Date fromDays:0' returns 1st Jan. 1901).
|
|
90 |
Date asDays is the reverse operation.
|
|
91 |
for GNU/ST-80 compatibility"
|
|
92 |
|
|
93 |
|yr rest d|
|
|
94 |
|
|
95 |
"approx. year"
|
|
96 |
yr := (dayCount // 366) + 1901.
|
|
97 |
rest := dayCount - (self yearAsDays:yr) + 1. "+1 for ST-80 compatibility"
|
|
98 |
d := self daysInYear:yr.
|
|
99 |
(rest > d) ifTrue:[
|
|
100 |
"adjust"
|
|
101 |
yr := yr + 1.
|
|
102 |
rest := rest - d.
|
|
103 |
].
|
|
104 |
|
|
105 |
^ self day:rest year:yr
|
|
106 |
|
|
107 |
"
|
|
108 |
Date fromDays:0 -> 1 jan 1901
|
|
109 |
Date fromDays:365 -> 1 jan 1902
|
|
110 |
Date fromDays:730 -> 1 jan 1903
|
|
111 |
Date fromDays:1095 -> 1 jan 1903
|
|
112 |
Date fromDays:1460 ->31 dec 1904 since 1904 was a leap year
|
|
113 |
"
|
|
114 |
!
|
|
115 |
|
|
116 |
fromOSTime:osTime
|
|
117 |
"return a date, representing the date given by the operatingSystem time.
|
|
118 |
This somewhat clumsy implementation hides the OS's date representation
|
|
119 |
(i.e. makes this class independent of what the OS starts its time values with).
|
|
120 |
Dont use this method, the osTime representation is totally unportable."
|
|
121 |
|
|
122 |
^ self basicNew fromOSTime:osTime
|
|
123 |
|
|
124 |
"
|
|
125 |
Date fromOSTime:#(0 0) -> on UNIX: this should return 1st Jan 1970
|
|
126 |
thats where Unix time starts
|
|
127 |
On other systems, it may be something different.
|
|
128 |
|
|
129 |
Date fromOSTime:#(86400 0) -> on UNIX: the day after
|
|
130 |
"
|
|
131 |
!
|
|
132 |
|
|
133 |
newDay:day month:month year:year
|
|
134 |
"return a new Date, given the day, month and year.
|
|
135 |
For your convenience, month may be either an integer
|
|
136 |
or the months name as a string.
|
|
137 |
Year may be the actual year (such as 1890, 2001) or the number
|
|
138 |
of years since 1900 (which is rubbish ST-80 compatibility:
|
|
139 |
it will be totally useless in a few years ...).
|
|
140 |
You better not use this short-year feature in your programs."
|
|
141 |
|
|
142 |
|monthIndex ok yr|
|
|
143 |
|
|
144 |
yr := year.
|
|
145 |
yr < 100 ifTrue:[
|
|
146 |
yr := yr + 1900.
|
|
147 |
].
|
|
148 |
|
|
149 |
month isInteger ifTrue:[
|
|
150 |
monthIndex := month
|
|
151 |
] ifFalse:[
|
|
152 |
monthIndex := self indexOfMonth:month
|
|
153 |
].
|
|
154 |
(monthIndex == 2 and:[day == 29]) ifTrue:[
|
|
155 |
ok := self leapYear:yr
|
|
156 |
] ifFalse:[
|
|
157 |
ok := day <= (self daysInMonth:month forYear:yr)
|
|
158 |
].
|
|
159 |
((day > 0) and:[ok]) ifTrue:[
|
|
160 |
^ self basicNew dateEncoding:(((yr * 100) + monthIndex) * 100) + day
|
|
161 |
].
|
|
162 |
|
|
163 |
"this error is triggered if you try to create a date from an
|
|
164 |
invalid year/month/day combination;
|
|
165 |
Such as 29-feb-year, where year is no leap year
|
|
166 |
"
|
|
167 |
self error:'invalid date'
|
|
168 |
|
|
169 |
"
|
|
170 |
Date newDay:8 month:'may' year:1993
|
|
171 |
Date newDay:8 month:5 year:1994
|
|
172 |
Date newDay:29 month:'feb' year:1994
|
|
173 |
Date newDay:29 month:'feb' year:1993
|
|
174 |
Date newDay:28 month:'feb' year:5
|
|
175 |
Date newDay:28 month:'feb' year:95
|
|
176 |
"
|
|
177 |
!
|
|
178 |
|
|
179 |
newDay:dayInYear year:year
|
|
180 |
"return a new Date, given the year and the day-in-year (starting at 1).
|
|
181 |
ST-80 compatibility"
|
|
182 |
|
|
183 |
|monthAndDay|
|
|
184 |
|
|
185 |
(dayInYear between:1 and:365) ifFalse:[
|
|
186 |
((dayInYear == 366) and:[self leapYear:year]) ifFalse:[
|
|
187 |
"
|
|
188 |
this error is triggered, when you try to create a
|
|
189 |
day from an invalid day-in-year;
|
|
190 |
for example, 366 in a non-leap year.
|
|
191 |
I dont know, if ST-80 wraps to the next year(s) in this case.
|
|
192 |
"
|
|
193 |
^ self error:'invalid date'
|
|
194 |
]
|
|
195 |
].
|
|
196 |
monthAndDay := self monthAndDayFromDayInYear:dayInYear forYear:year.
|
|
197 |
^ self day:(monthAndDay at:2) month:(monthAndDay at:1) year:year
|
|
198 |
|
|
199 |
"
|
|
200 |
Date newDay:150 year:1994
|
|
201 |
Date newDay:1 year:1994
|
|
202 |
Date newDay:1 year:1901
|
|
203 |
Date newDay:1 year:1902
|
|
204 |
Date newDay:365 year:1992
|
|
205 |
Date newDay:366 year:1992
|
|
206 |
Date newDay:365 year:1994
|
|
207 |
Date newDay:366 year:1994
|
|
208 |
"
|
|
209 |
!
|
|
210 |
|
|
211 |
readFrom:aStringOrStream onError:exceptionBlock
|
|
212 |
"return a new Date, reading a printed representation from aStream.
|
|
213 |
Notice, that this is not the storeString format and
|
|
214 |
is different from the format expected by readFrom:.
|
|
215 |
BUG:
|
|
216 |
This method assumes american format (i.e. month-day-year) instead
|
|
217 |
of the german/french and other day-month-year.
|
|
218 |
There ought to be a nationalized variant of this."
|
|
219 |
|
|
220 |
|str month day year|
|
|
221 |
|
|
222 |
Object errorSignal handle:[:ex |
|
|
223 |
^ exceptionBlock value
|
|
224 |
] do:[
|
|
225 |
str := aStringOrStream readStream.
|
|
226 |
|
|
227 |
[str peek isLetterOrDigit] whileFalse:[str next].
|
|
228 |
(str peek isDigit) ifTrue:[
|
|
229 |
day := Integer readFrom:str onError:[^ exceptionBlock value]
|
|
230 |
].
|
|
231 |
[str peek isLetterOrDigit] whileFalse:[str next].
|
|
232 |
(str peek isLetter) ifTrue:[
|
|
233 |
month := str nextAlphaNumericWord.
|
|
234 |
day isNil ifTrue:[
|
|
235 |
[str peek isLetterOrDigit] whileFalse:[str next].
|
|
236 |
day := Integer readFrom:str onError:[^ exceptionBlock value].
|
|
237 |
]
|
|
238 |
] ifFalse:[
|
|
239 |
month := self nameOfMonth:day.
|
|
240 |
day := Integer readFrom:str onError:[^ exceptionBlock value]
|
|
241 |
].
|
|
242 |
[str peek isLetterOrDigit] whileFalse:[str next].
|
|
243 |
year := Integer readFrom:str onError:[^ exceptionBlock value].
|
|
244 |
^ self newDay:day month:month year:year
|
|
245 |
].
|
|
246 |
|
|
247 |
"
|
|
248 |
Date readFromString:'31 December 1992'
|
|
249 |
Date readFromString:'December, 5, 1992'
|
|
250 |
Date readFromString:'December, 5 1992'
|
|
251 |
Date readFromString:'3-jan-95'
|
|
252 |
Date readFromString:'12/31/1992'
|
|
253 |
Date readFromString:'15.4.1992' -> german; leads to an error
|
|
254 |
Date readFromString:'10.4.1992' -> german; leads to a wrong date
|
|
255 |
Date readFromString:'10.4.1992' onError:['wrong date']
|
|
256 |
"
|
|
257 |
|
|
258 |
"Created: 16.11.1995 / 22:50:17 / cg"
|
|
259 |
!
|
|
260 |
|
|
261 |
today
|
|
262 |
"return a date, representing today"
|
|
263 |
|
|
264 |
^ self fromOSTime:OperatingSystem getTimeParts
|
|
265 |
|
|
266 |
"
|
|
267 |
Date today
|
|
268 |
"
|
|
269 |
! !
|
|
270 |
|
|
271 |
!Date class methodsFor:'general queries'!
|
|
272 |
|
|
273 |
abbreviatedNameOfDay:dayIndex
|
|
274 |
"given a day index (1..7), return the abbreviated name
|
|
275 |
of the day"
|
|
276 |
|
|
277 |
EnvironmentChange ifTrue:[
|
|
278 |
self initNames
|
|
279 |
].
|
|
280 |
^ DayAbbrevs at:dayIndex
|
|
281 |
|
|
282 |
"
|
|
283 |
Date abbreviatedNameOfDay:4
|
|
284 |
"
|
|
285 |
!
|
|
286 |
|
|
287 |
abbreviatedNameOfMonth:monthIndex
|
|
288 |
"given a month index (1..12), return the abbreviated name
|
|
289 |
of the month"
|
|
290 |
|
|
291 |
EnvironmentChange ifTrue:[
|
|
292 |
self initNames
|
|
293 |
].
|
|
294 |
^ MonthAbbrevs at:monthIndex
|
|
295 |
|
|
296 |
"
|
|
297 |
Date abbreviatedNameOfMonth:11
|
|
298 |
Date abbreviatedNameOfMonth:12
|
|
299 |
"
|
|
300 |
!
|
|
301 |
|
|
302 |
dateAndTimeNow
|
|
303 |
"return an array containing the date and time of now"
|
|
304 |
|
|
305 |
^ Time dateAndTimeNow
|
|
306 |
|
|
307 |
"
|
|
308 |
Date dateAndTimeNow
|
|
309 |
"
|
|
310 |
!
|
|
311 |
|
|
312 |
dayOfWeek:dayName
|
|
313 |
"given the name of a day (either string or symbol),
|
|
314 |
return the day-index (1 for monday; 7 for sunday).
|
|
315 |
Return 0 for invalid day name"
|
|
316 |
|
|
317 |
EnvironmentChange ifTrue:[
|
|
318 |
self initNames
|
|
319 |
].
|
|
320 |
^ DayNames indexOf:dayName
|
|
321 |
|
|
322 |
"
|
|
323 |
Date dayOfWeek:'wednesday'
|
|
324 |
"
|
|
325 |
!
|
|
326 |
|
|
327 |
daysInMonth:month forYear:yearInteger
|
|
328 |
"given the name of a month and a year, return the number
|
|
329 |
of days this month has (modified GNU).
|
|
330 |
return 0 if the month name was invalid.
|
|
331 |
For your convenience, month maybe an integer or name-string."
|
|
332 |
|
|
333 |
|monthIndex "{ Class: SmallInteger }"|
|
|
334 |
|
|
335 |
month isInteger ifTrue:[
|
|
336 |
monthIndex := month
|
|
337 |
] ifFalse:[
|
|
338 |
monthIndex := self indexOfMonth:month
|
|
339 |
].
|
|
340 |
|
|
341 |
^ self daysInMonthIndex:monthIndex forYear:yearInteger
|
|
342 |
|
|
343 |
"
|
|
344 |
Date daysInMonth:2 forYear:1980
|
|
345 |
Date daysInMonth:2 forYear:1981
|
|
346 |
Date daysInMonth:'feb' forYear:1981
|
|
347 |
"
|
|
348 |
!
|
|
349 |
|
|
350 |
daysInYear:yearInteger
|
|
351 |
"return the number of days in a year"
|
|
352 |
|
|
353 |
(self leapYear:yearInteger) ifTrue:[^ 366].
|
|
354 |
^ 365
|
|
355 |
|
|
356 |
"
|
|
357 |
Date daysInYear:1900
|
|
358 |
Date daysInYear:1901
|
|
359 |
Date daysInYear:1904
|
|
360 |
Date daysInYear:1980
|
|
361 |
Date daysInYear:1981
|
|
362 |
"
|
|
363 |
!
|
|
364 |
|
|
365 |
daysUntilMonth:month forYear:yearInteger
|
|
366 |
"given the name of a month and a year, return the number
|
|
367 |
of days from 1st january to last of prev month of that year.
|
|
368 |
Return 0 if the month name/index is invalid or is january.
|
|
369 |
For your convenience, month maybe an integer or name-string."
|
|
370 |
|
|
371 |
|monthIndex "{ Class: SmallInteger }"
|
|
372 |
sumDays "{ Class: SmallInteger }" |
|
|
373 |
|
|
374 |
month isInteger ifTrue:[
|
|
375 |
monthIndex := month
|
|
376 |
] ifFalse:[
|
|
377 |
monthIndex := self indexOfMonth:month
|
|
378 |
].
|
|
379 |
(monthIndex between:1 and:12) ifFalse:[^ 0].
|
|
380 |
|
|
381 |
sumDays := 0.
|
|
382 |
1 to:monthIndex-1 do:[:m |
|
|
383 |
sumDays := sumDays + (self daysInMonthIndex:m forYear:yearInteger)
|
|
384 |
].
|
|
385 |
^ sumDays
|
|
386 |
|
|
387 |
"
|
|
388 |
Date daysUntilMonth:'feb' forYear:1993
|
|
389 |
Date daysUntilMonth:'jan' forYear:1993
|
|
390 |
"
|
|
391 |
!
|
|
392 |
|
|
393 |
indexOfMonth:aMonthString
|
|
394 |
"given the name of a month (either string or symbol),
|
|
395 |
return the month-index (1 for jan; 12 for december).
|
|
396 |
The given string may be a full or abbreviated name,
|
|
397 |
case is ignored.
|
|
398 |
Return 0 for invalid month name."
|
|
399 |
|
|
400 |
|idx name|
|
|
401 |
|
|
402 |
EnvironmentChange ifTrue:[
|
|
403 |
self initNames
|
|
404 |
].
|
|
405 |
name := aMonthString asLowercase.
|
|
406 |
idx := MonthAbbrevs indexOf:name.
|
|
407 |
idx ~~ 0 ifTrue:[^ idx].
|
|
408 |
idx := MonthNames indexOf:name.
|
|
409 |
idx ~~ 0 ifTrue:[^ idx].
|
|
410 |
|
|
411 |
name at:1 put:(name at:1) asUppercase.
|
|
412 |
idx := MonthAbbrevs indexOf:name.
|
|
413 |
idx ~~ 0 ifTrue:[^ idx].
|
|
414 |
idx := MonthNames indexOf:name.
|
|
415 |
idx ~~ 0 ifTrue:[^ idx].
|
|
416 |
|
|
417 |
^ idx
|
|
418 |
|
|
419 |
"
|
|
420 |
Date indexOfMonth:'jan'
|
|
421 |
Date indexOfMonth:'Jan'
|
|
422 |
Date indexOfMonth:'December'
|
|
423 |
"
|
|
424 |
!
|
|
425 |
|
|
426 |
isLeapYear:yearInteger
|
|
427 |
"Return true, if a year is a leap year.
|
|
428 |
Obsolete:
|
|
429 |
Please use the ST-80 compatible #leapYear for new programs,
|
|
430 |
since this method will vanish."
|
|
431 |
|
|
432 |
^ self leapYear:yearInteger
|
|
433 |
!
|
|
434 |
|
|
435 |
leapYear:yearInteger
|
|
436 |
"return true, if yearInteger is a leap year."
|
|
437 |
|
|
438 |
|y "{ Class: SmallInteger }"|
|
|
439 |
|
|
440 |
y := yearInteger.
|
|
441 |
(y \\ 4 == 0) ifTrue:[
|
|
442 |
(y \\ 100 ~~ 0) ifTrue:[^ true].
|
|
443 |
(y \\ 400 == 0) ifTrue:[^ true]
|
|
444 |
].
|
|
445 |
^ false
|
|
446 |
|
|
447 |
"
|
|
448 |
Date leapYear:1992
|
|
449 |
Date leapYear:1994
|
|
450 |
Date leapYear:1900
|
|
451 |
Date leapYear:2000
|
|
452 |
"
|
|
453 |
!
|
|
454 |
|
|
455 |
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger
|
|
456 |
"given a day-in-year (1..365) return an Array containing the
|
|
457 |
month index and the day-in-month. Return nil if the argument is invalid."
|
|
458 |
|
|
459 |
|restDays daysInMonth|
|
|
460 |
|
|
461 |
restDays := aDayInYear.
|
|
462 |
restDays < 1 ifTrue:[^ nil].
|
|
463 |
|
|
464 |
1 to:12 do:[:m |
|
|
465 |
daysInMonth := self daysInMonthIndex:m forYear:yearInteger.
|
|
466 |
restDays <= daysInMonth ifTrue:[
|
|
467 |
^ Array with:m with:restDays
|
|
468 |
].
|
|
469 |
restDays := restDays - daysInMonth
|
|
470 |
].
|
|
471 |
restDays > daysInMonth ifTrue:[^ nil].
|
|
472 |
^ Array with:12 with:restDays
|
|
473 |
|
|
474 |
"
|
|
475 |
Date monthAndDayFromDayInYear:66 forYear:1980
|
|
476 |
Date monthAndDayFromDayInYear:66 forYear:1981
|
|
477 |
"
|
|
478 |
!
|
|
479 |
|
|
480 |
nameOfDay:dayIndex
|
|
481 |
"given a day index (1..7), return the name of the day"
|
|
482 |
|
|
483 |
EnvironmentChange ifTrue:[
|
|
484 |
self initNames
|
|
485 |
].
|
|
486 |
^ DayNames at:dayIndex
|
|
487 |
|
|
488 |
"
|
|
489 |
Date nameOfDay:4
|
|
490 |
"
|
|
491 |
!
|
|
492 |
|
|
493 |
nameOfMonth:monthIndex
|
|
494 |
"given a month index (1..12), return the name of the month"
|
|
495 |
|
|
496 |
EnvironmentChange ifTrue:[
|
|
497 |
self initNames
|
|
498 |
].
|
|
499 |
^ MonthNames at:monthIndex
|
|
500 |
|
|
501 |
"
|
|
502 |
Date nameOfMonth:11
|
|
503 |
Date nameOfMonth:12
|
|
504 |
Date nameOfMonth:4
|
|
505 |
"
|
|
506 |
!
|
|
507 |
|
|
508 |
yearAsDays: yearInteger
|
|
509 |
"Returns the number of days since Jan 1, 1901. (GNU)
|
|
510 |
to the first Jan of the year, yearInteger.
|
|
511 |
For 1901 this is zero, for 1902 its 365.
|
|
512 |
Defined for years >= 1901"
|
|
513 |
|
|
514 |
|y "{ Class: SmallInteger }"|
|
|
515 |
|
|
516 |
y := yearInteger - 1900.
|
|
517 |
y := y - 1.
|
|
518 |
^ (y * 365)
|
|
519 |
+ (y // 4)
|
|
520 |
- (y // 100)
|
|
521 |
+ ((y + 300) // 400)
|
|
522 |
|
|
523 |
"
|
|
524 |
Date yearAsDays:1901
|
|
525 |
Date yearAsDays:1902
|
|
526 |
Date yearAsDays:1903
|
|
527 |
Date yearAsDays:1904
|
|
528 |
Date yearAsDays:1905
|
|
529 |
Date yearAsDays:1994
|
|
530 |
(Date yearAsDays:2001) - (Date yearAsDays:2000)
|
|
531 |
"
|
|
532 |
! !
|
|
533 |
|
|
534 |
!Date class methodsFor:'handling language changes'!
|
|
535 |
|
|
536 |
initialize
|
|
537 |
"check for case where Resource-classes are absent"
|
|
538 |
ResourcePack isNil ifTrue:[
|
|
539 |
self initNames
|
|
540 |
] ifFalse:[
|
|
541 |
Smalltalk addDependent:self.
|
|
542 |
EnvironmentChange := true
|
|
543 |
]
|
|
544 |
!
|
|
545 |
|
|
546 |
update:something
|
|
547 |
((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[
|
|
548 |
"just remember change for next access"
|
|
549 |
EnvironmentChange := true
|
|
550 |
]
|
|
551 |
! !
|
|
552 |
|
1
|
553 |
!Date class methodsFor:'private'!
|
|
554 |
|
699
|
555 |
daysInMonthIndex: monthIndex forYear: yearInteger
|
|
556 |
"return the number of days in month monthIndex of
|
|
557 |
year yearInteger (modified GNU).
|
|
558 |
Return 0 for invalid month index.
|
|
559 |
This is the internal version of daysInMonth:forYear:"
|
|
560 |
|
|
561 |
|days|
|
|
562 |
|
|
563 |
(monthIndex between:1 and:12) ifFalse:[^ 0].
|
|
564 |
|
|
565 |
days := #(31 28 31 "Jan Feb Mar"
|
|
566 |
30 31 30 "Apr May Jun"
|
|
567 |
31 31 30 "Jul Aug Sep"
|
|
568 |
31 30 31 "Oct Nov Dec"
|
|
569 |
) at: monthIndex.
|
|
570 |
|
|
571 |
(monthIndex == 2) ifTrue:[
|
|
572 |
(self leapYear:yearInteger) ifTrue:[
|
|
573 |
^ days + 1
|
|
574 |
]
|
|
575 |
].
|
|
576 |
^ days
|
|
577 |
|
|
578 |
"
|
|
579 |
Date daysInMonthIndex:2 forYear:1994
|
|
580 |
Date daysInMonthIndex:2 forYear:1980
|
|
581 |
Date daysInMonthIndex:2 forYear:1981
|
|
582 |
"
|
|
583 |
!
|
|
584 |
|
1
|
585 |
initNames
|
|
586 |
"read the language specific names"
|
|
587 |
|
10
|
588 |
|resources|
|
|
589 |
|
54
|
590 |
DayNames := #('monday'
|
155
|
591 |
'tuesday'
|
|
592 |
'wednesday'
|
|
593 |
'thursday'
|
|
594 |
'friday'
|
|
595 |
'saturday'
|
|
596 |
'sunday').
|
1
|
597 |
|
54
|
598 |
DayAbbrevs := #('mon'
|
155
|
599 |
'tue'
|
|
600 |
'wed'
|
|
601 |
'thu'
|
|
602 |
'fri'
|
|
603 |
'sat'
|
|
604 |
'sun').
|
1
|
605 |
|
54
|
606 |
MonthNames := #('january'
|
155
|
607 |
'february'
|
|
608 |
'march'
|
|
609 |
'april'
|
|
610 |
'may'
|
|
611 |
'june'
|
|
612 |
'july'
|
|
613 |
'august'
|
|
614 |
'september'
|
|
615 |
'october'
|
|
616 |
'november'
|
|
617 |
'december').
|
1
|
618 |
|
54
|
619 |
MonthAbbrevs := #('jan'
|
155
|
620 |
'feb'
|
|
621 |
'mar'
|
|
622 |
'apr'
|
|
623 |
'may'
|
|
624 |
'jun'
|
|
625 |
'jul'
|
|
626 |
'aug'
|
|
627 |
'sep'
|
|
628 |
'oct'
|
|
629 |
'nov'
|
|
630 |
'dec').
|
54
|
631 |
|
|
632 |
"check for case where Resource-classes are absent"
|
|
633 |
ResourcePack notNil ifTrue:[
|
155
|
634 |
resources := ResourcePack for:self.
|
54
|
635 |
|
155
|
636 |
DayNames := resources array:DayNames.
|
|
637 |
DayAbbrevs := resources array:DayAbbrevs.
|
|
638 |
MonthNames := resources array:MonthNames.
|
|
639 |
MonthAbbrevs := resources array:MonthAbbrevs.
|
54
|
640 |
].
|
1
|
641 |
|
29
|
642 |
EnvironmentChange := false
|
10
|
643 |
|
|
644 |
"Date initNames"
|
54
|
645 |
! !
|
|
646 |
|
|
647 |
!Date class methodsFor:'private encoding'!
|
|
648 |
|
|
649 |
encodeYear:y month:m day:d
|
92
|
650 |
"the internal encoding is stricktly private,
|
|
651 |
and should not be used outside."
|
|
652 |
|
54
|
653 |
^ (((y * 100) + m) * 100) + d
|
|
654 |
! !
|
|
655 |
|
699
|
656 |
!Date methodsFor:'accessing'!
|
241
|
657 |
|
699
|
658 |
abbreviatedDayName
|
|
659 |
"return the short week-day of the receiver as a string.
|
|
660 |
The returned string depends on the language setting.
|
|
661 |
Expect things like 'mon', 'tue' ..."
|
54
|
662 |
|
699
|
663 |
^ self class abbreviatedNameOfDay:(self dayInWeek)
|
92
|
664 |
|
|
665 |
"
|
699
|
666 |
Date today abbreviatedDayName
|
|
667 |
(Date day:15 month:4 year:1959) abbreviatedDayName
|
92
|
668 |
"
|
|
669 |
!
|
|
670 |
|
699
|
671 |
abbreviatedMonthName
|
|
672 |
"return the month of the receiver as a string.
|
|
673 |
The returned string depends on the language setting.
|
|
674 |
Expect things like 'jan', 'feb' ..."
|
54
|
675 |
|
699
|
676 |
^ self class abbreviatedNameOfMonth:(self month)
|
68
|
677 |
|
92
|
678 |
"
|
699
|
679 |
Date today abbreviatedMonthName
|
|
680 |
(Date day:15 month:4 year:1959) abbreviatedMonthName
|
92
|
681 |
"
|
|
682 |
!
|
|
683 |
|
|
684 |
asDays
|
|
685 |
"return the number of days elapsed since 01-Jan-1901
|
|
686 |
and the receiver's day; starts with 0 for 1-1-1901.
|
|
687 |
Date>>fromDays: is the reverse operation.
|
|
688 |
For ST-80 compatibility."
|
68
|
689 |
|
|
690 |
|yr|
|
|
691 |
|
|
692 |
yr := self year.
|
|
693 |
^ (self class yearAsDays:yr)
|
|
694 |
+ (self class daysUntilMonth:self month forYear:yr)
|
|
695 |
+ self day
|
85
|
696 |
- 1
|
68
|
697 |
|
92
|
698 |
"
|
|
699 |
(Date day: 5 month: 8 year: 1962) asDays -> should be 22496
|
|
700 |
(Date day: 1 month: 1 year: 1901) asDays -> 0
|
|
701 |
Date today asDays
|
|
702 |
Date fromDays:(Date today asDays + 7)
|
|
703 |
"
|
77
|
704 |
!
|
|
705 |
|
|
706 |
asSeconds
|
92
|
707 |
"return the seconds between 1.jan.1901 and the same time in the receivers
|
|
708 |
day. (i.e. midnight to midnight).
|
77
|
709 |
ST-80 compatibility."
|
|
710 |
|
92
|
711 |
^ 60*60*24 * self asDays
|
77
|
712 |
|
92
|
713 |
"
|
|
714 |
(Date day: 5 month: 8 year: 1962) asSeconds
|
|
715 |
(Date day: 1 month: 1 year: 1901) asSeconds
|
|
716 |
(Date today addDays:7) asSeconds - Date today asSeconds
|
|
717 |
"
|
699
|
718 |
!
|
|
719 |
|
|
720 |
day
|
|
721 |
"return the day (1..31) of the receiver"
|
|
722 |
|
|
723 |
^ dateEncoding \\ 100
|
|
724 |
|
|
725 |
"
|
|
726 |
Date today day
|
|
727 |
"
|
|
728 |
!
|
|
729 |
|
|
730 |
dayCount
|
|
731 |
"return the number of days since 1st. Jan. 1901;
|
|
732 |
starting with 0 for this date.
|
|
733 |
Date>>fromDays: is the reverse operation.
|
|
734 |
Obsolete:
|
|
735 |
please use asDays for ST-80 compatibility"
|
|
736 |
|
|
737 |
^ self asDays.
|
|
738 |
|
|
739 |
"
|
|
740 |
(Date day:1 month:1 year:1901) dayCount
|
|
741 |
Date fromDays:(Date day:1 month:1 year:1994) dayCount
|
|
742 |
Date today dayCount
|
|
743 |
"
|
|
744 |
!
|
|
745 |
|
|
746 |
dayInWeek
|
|
747 |
"return the week-day of the receiver - 1 for monday, 7 for sunday"
|
|
748 |
|
|
749 |
^ (1 "know, that 1st Jan 1901 was a tuesday"
|
|
750 |
+ self asDays) \\ 7 + 1
|
|
751 |
|
|
752 |
"
|
|
753 |
Date today dayInWeek
|
|
754 |
(Date day:15 month:4 year:1959) dayInWeek
|
|
755 |
"
|
|
756 |
!
|
|
757 |
|
|
758 |
dayName
|
|
759 |
"return the week-day of the receiver as a string.
|
|
760 |
The returned string depends on the language setting.
|
|
761 |
Expect things like 'monday', 'tuesday' ...
|
|
762 |
Obsolete:
|
|
763 |
use #weekday for ST-80 compatibility"
|
|
764 |
|
|
765 |
^ self weekday
|
|
766 |
!
|
77
|
767 |
|
|
768 |
dayOfMonth
|
|
769 |
"Answer the day of the month represented by me.
|
|
770 |
Same as day; for ST-80 compatibility."
|
|
771 |
|
|
772 |
^ self day
|
92
|
773 |
|
|
774 |
"
|
|
775 |
Date today dayOfMonth
|
|
776 |
"
|
|
777 |
!
|
|
778 |
|
|
779 |
daysInMonth
|
|
780 |
"return the number of days in the month of the receiver"
|
|
781 |
|
|
782 |
^ Date daysInMonth:(self month) forYear:(self year)
|
|
783 |
|
|
784 |
"
|
|
785 |
Date today daysInMonth
|
|
786 |
"
|
|
787 |
!
|
|
788 |
|
|
789 |
daysInYear
|
|
790 |
"return the number of days in the year of the receiver"
|
|
791 |
|
|
792 |
^ Date daysInYear:(self year)
|
|
793 |
|
|
794 |
"
|
|
795 |
Date today daysInYear
|
|
796 |
"
|
|
797 |
!
|
|
798 |
|
|
799 |
daysLeftInYear
|
|
800 |
"return the number of days left in the year of the receiver"
|
|
801 |
|
|
802 |
^ Date daysInYear:(self year) - self day
|
|
803 |
|
|
804 |
"
|
|
805 |
Date today daysLeftInYear
|
|
806 |
"
|
77
|
807 |
!
|
|
808 |
|
699
|
809 |
leap
|
|
810 |
"return true, if the receivers year is a leap year"
|
68
|
811 |
|
699
|
812 |
^ Date leapYear:(self year)
|
68
|
813 |
|
92
|
814 |
"
|
699
|
815 |
Date today leap
|
|
816 |
(Date day:1 month:1 year:1992) leap
|
92
|
817 |
"
|
68
|
818 |
!
|
|
819 |
|
699
|
820 |
month
|
|
821 |
"return the month (1..12) of the receiver"
|
92
|
822 |
|
699
|
823 |
^ (dateEncoding // 100) \\ 100
|
68
|
824 |
|
92
|
825 |
"
|
699
|
826 |
Date today month
|
92
|
827 |
"
|
68
|
828 |
!
|
|
829 |
|
77
|
830 |
monthIndex
|
|
831 |
"return the index of the month (e.g. Feb.=2).
|
|
832 |
Same as month; for ST-80 compatibility."
|
|
833 |
|
|
834 |
^ self month
|
|
835 |
!
|
|
836 |
|
68
|
837 |
monthName
|
|
838 |
"return the month of the receiver as a string.
|
|
839 |
The returned string depends on the language setting.
|
|
840 |
Expect things like 'january', 'february' ..."
|
|
841 |
|
|
842 |
^ self class nameOfMonth:(self month)
|
|
843 |
|
92
|
844 |
"
|
|
845 |
Date today monthName
|
|
846 |
(Date day:15 month:4 year:1959) monthName
|
|
847 |
"
|
68
|
848 |
!
|
|
849 |
|
699
|
850 |
weekday
|
|
851 |
"return the week-day of the receiver as a string.
|
68
|
852 |
The returned string depends on the language setting.
|
699
|
853 |
Expect things like 'monday', 'tuesday' ...
|
|
854 |
For ST-80 compatibility"
|
|
855 |
|
|
856 |
^ self class nameOfDay:(self dayInWeek)
|
|
857 |
|
|
858 |
"
|
|
859 |
Date today weekday
|
|
860 |
(Date day:15 month:4 year:1959) weekday
|
|
861 |
"
|
|
862 |
!
|
|
863 |
|
|
864 |
year
|
|
865 |
"return the year (1..12) of the receiver"
|
|
866 |
|
|
867 |
^ dateEncoding // (100*100)
|
68
|
868 |
|
699
|
869 |
"
|
|
870 |
Date today year
|
|
871 |
"
|
|
872 |
! !
|
|
873 |
|
|
874 |
!Date methodsFor:'arithmetic'!
|
|
875 |
|
|
876 |
addDays:days
|
|
877 |
"return a new date representing 'days' after the receiver.
|
|
878 |
The argument should be some kind of integer.
|
|
879 |
For ST-80 compatibility."
|
|
880 |
|
|
881 |
^ self class fromDays:(self asDays + days)
|
|
882 |
|
|
883 |
"
|
|
884 |
Date today addDays:7
|
|
885 |
"
|
|
886 |
!
|
|
887 |
|
|
888 |
daysUntil:aDate
|
|
889 |
"return the number of days between the receiver and the argument,
|
|
890 |
aDate, whuch should be some kind of date"
|
|
891 |
|
|
892 |
^ aDate asDays - self asDays
|
68
|
893 |
|
92
|
894 |
"
|
699
|
895 |
(Date day:24 month:12 year:1994) daysUntil:(Date day:1 month:1 year:1995)
|
|
896 |
(Date day:1 month:2 year:1992) daysUntil:(Date day:1 month:3 year:1992)
|
|
897 |
(Date day:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994)
|
|
898 |
|
|
899 |
|delta|
|
|
900 |
delta := Date today
|
|
901 |
daysUntil:(Date day:25 month:12 year:Date today year).
|
|
902 |
Transcript show:'still ';
|
|
903 |
show:delta ;
|
|
904 |
showCr:' days till xmas'
|
|
905 |
"
|
|
906 |
!
|
|
907 |
|
|
908 |
minusDays:days
|
|
909 |
"return a new date representing 'days' before the receiver.
|
|
910 |
The argument should be some kind of integer.
|
|
911 |
Obsolete:
|
|
912 |
Please dont use this method since it will vanish.
|
|
913 |
Use #subtractDays: instead for ST-80 compatibility."
|
|
914 |
|
|
915 |
^ self subtractDays:days
|
|
916 |
!
|
|
917 |
|
|
918 |
plusDays:days
|
|
919 |
"return a new date representing 'days' after the receiver.
|
|
920 |
The argument should be some kind of integer.
|
|
921 |
Obsolete:
|
|
922 |
Please dont use this method since it will vanish.
|
|
923 |
Use #addDays: instead for ST-80 compatibility."
|
|
924 |
|
|
925 |
^ self addDays:days
|
|
926 |
!
|
|
927 |
|
|
928 |
subtractDate:aDate
|
|
929 |
"return the number of days between the receiver and aDate"
|
|
930 |
|
|
931 |
^ self asDays - aDate asDays
|
|
932 |
|
|
933 |
"
|
|
934 |
(Date day:1 month:1 year:1995) subtractDate:(Date day:24 month:12 year:1994)
|
|
935 |
(Date day:1 month:3 year:1992) subtractDate:(Date day:1 month:2 year:1992)
|
|
936 |
(Date day:1 month:3 year:1994) subtractDate:(Date day:1 month:2 year:1994)
|
|
937 |
"
|
|
938 |
!
|
|
939 |
|
|
940 |
subtractDays:days
|
|
941 |
"return a new date representing 'days' before the receiver.
|
|
942 |
The argument should be some kind of integer.
|
|
943 |
For ST-80 compatibility"
|
|
944 |
|
|
945 |
^ self class fromDays:(self asDays - days)
|
|
946 |
|
|
947 |
"
|
|
948 |
Date today subtractDays:7
|
92
|
949 |
"
|
1
|
950 |
! !
|
|
951 |
|
|
952 |
!Date methodsFor:'comparing'!
|
|
953 |
|
29
|
954 |
< aDate
|
|
955 |
"return true, if the date represented by the receiver
|
|
956 |
is before the argument, aDate"
|
|
957 |
|
54
|
958 |
(aDate isMemberOf:Date) ifTrue:[
|
155
|
959 |
^ dateEncoding < aDate dateEncoding
|
54
|
960 |
].
|
29
|
961 |
|
54
|
962 |
"the argument must understand year, month and day to be
|
|
963 |
comparable, whatever it is"
|
|
964 |
|
|
965 |
^ dateEncoding < (Date encodeYear:aDate year
|
155
|
966 |
month:aDate month
|
|
967 |
day:aDate day)
|
68
|
968 |
|
|
969 |
"Date today < (Date day:24 month:12 year:2000)"
|
|
970 |
"Date today < (Date day:24 month:12 year:1900)"
|
29
|
971 |
!
|
1
|
972 |
|
|
973 |
= aDate
|
|
974 |
"return true, if the date represented by the receiver
|
|
975 |
is the same as the one represented by argument, aDate"
|
|
976 |
|
155
|
977 |
(aDate isMemberOf:Date) ifFalse:[^ false].
|
|
978 |
|
|
979 |
^ dateEncoding = aDate dateEncoding
|
54
|
980 |
|
|
981 |
"the argument must understand year, month and day to be
|
|
982 |
comparable, whatever it is"
|
|
983 |
|
155
|
984 |
"
|
54
|
985 |
^ dateEncoding = (Date encodeYear:aDate year
|
155
|
986 |
month:aDate month
|
|
987 |
day:aDate day)
|
|
988 |
"
|
68
|
989 |
"Date today = ((Date today plusDays:7) minusDays:7)"
|
92
|
990 |
!
|
|
991 |
|
699
|
992 |
> aDate
|
|
993 |
"return true, if the date represented by the receiver
|
|
994 |
is after the argument, aDate"
|
|
995 |
|
|
996 |
(aDate isMemberOf:Date) ifTrue:[
|
|
997 |
^ dateEncoding > aDate dateEncoding
|
|
998 |
].
|
|
999 |
|
|
1000 |
"the argument must understand year, month and day to be
|
|
1001 |
comparable, whatever it is"
|
|
1002 |
|
|
1003 |
^ dateEncoding > (Date encodeYear:aDate year
|
|
1004 |
month:aDate month
|
|
1005 |
day:aDate day)
|
|
1006 |
|
|
1007 |
"Date today > (Date day:24 month:12 year:2000)"
|
|
1008 |
"Date today > (Date day:24 month:12 year:1900)"
|
|
1009 |
!
|
|
1010 |
|
92
|
1011 |
hash
|
|
1012 |
"return an integer useful for hashing on dates"
|
|
1013 |
|
|
1014 |
^ dateEncoding
|
1
|
1015 |
! !
|
|
1016 |
|
54
|
1017 |
!Date methodsFor:'printing & storing'!
|
1
|
1018 |
|
408
|
1019 |
printFormat:aFormatArray
|
|
1020 |
"return a string containing a printed representation of the receiver.
|
|
1021 |
The formatArray argument consists of 6 or 7 integers which control
|
|
1022 |
the resulting string. The entries are:
|
|
1023 |
1 day position (1, 2 or 3)
|
|
1024 |
2 month position (1..3)
|
|
1025 |
3 year position (1..3)
|
|
1026 |
4 asciiValue of separator character or separator character
|
|
1027 |
or collection of 2 separator characters
|
|
1028 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname
|
|
1029 |
4: abbreviated uppercase 5: full uppercase)
|
|
1030 |
6 year format (1 include century; 2 exclude century)
|
|
1031 |
7 (optional) true/false of true, print numbers in 2-digit format
|
|
1032 |
False, if ommited
|
|
1033 |
|
|
1034 |
Day and monthnames are in the currently active language.
|
|
1035 |
|
|
1036 |
This method supports more options than the ST-80 version; month formats
|
|
1037 |
4 and 5, non-numeric separators and the optional 7th parameter are not
|
|
1038 |
supported by ST-80. Be aware of this for compatibility reasons.
|
|
1039 |
|
|
1040 |
Notice that not all formats can be scanned (correctly) by #readFrom:"
|
|
1041 |
|
|
1042 |
|mf upperCase day month year components sep1 sep2 leadingZeros|
|
|
1043 |
|
|
1044 |
aFormatArray size > 6 ifTrue:[
|
|
1045 |
leadingZeros := aFormatArray at:7
|
|
1046 |
] ifFalse:[
|
|
1047 |
leadingZeros := false.
|
|
1048 |
].
|
|
1049 |
|
|
1050 |
components := Array new:3.
|
|
1051 |
day := self day.
|
|
1052 |
leadingZeros ifTrue:[
|
|
1053 |
day := day printStringLeftPaddedTo:2 with:$0
|
|
1054 |
] ifFalse:[
|
|
1055 |
day := day printString
|
|
1056 |
].
|
|
1057 |
components at:(aFormatArray at:1) put:day.
|
|
1058 |
|
|
1059 |
upperCase := false.
|
|
1060 |
mf := aFormatArray at:5.
|
|
1061 |
(mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true].
|
|
1062 |
|
|
1063 |
mf == 1 ifTrue:[
|
|
1064 |
month := self month.
|
|
1065 |
leadingZeros ifTrue:[
|
|
1066 |
month := month printStringLeftPaddedTo:2 with:$0
|
|
1067 |
] ifFalse:[
|
|
1068 |
month := month printString
|
|
1069 |
]
|
|
1070 |
] ifFalse:[
|
|
1071 |
mf == 2 ifTrue:[
|
|
1072 |
month := self abbreviatedMonthName
|
|
1073 |
] ifFalse:[
|
|
1074 |
month := self monthName
|
|
1075 |
]
|
|
1076 |
].
|
|
1077 |
upperCase ifTrue:[month := month asUppercase].
|
|
1078 |
components at:(aFormatArray at:2) put:month.
|
|
1079 |
|
|
1080 |
year := self year.
|
|
1081 |
(aFormatArray at:6) == 2 ifTrue:[
|
|
1082 |
year := year \\ 100
|
|
1083 |
].
|
|
1084 |
components at:(aFormatArray at:3) put:year printString.
|
|
1085 |
|
|
1086 |
sep1 := (aFormatArray at:4).
|
|
1087 |
sep1 isCollection ifTrue:[
|
|
1088 |
sep2 := (sep1 at:2).
|
|
1089 |
sep1 := (sep1 at:1).
|
|
1090 |
] ifFalse:[
|
|
1091 |
sep1 := sep2 := sep1 asCharacter
|
|
1092 |
].
|
|
1093 |
|
|
1094 |
^ (components at:1)
|
|
1095 |
, sep1 asString
|
|
1096 |
, (components at:2)
|
|
1097 |
, sep2 asString
|
|
1098 |
, (components at:3)
|
|
1099 |
|
|
1100 |
"
|
|
1101 |
Date today printFormat:#(1 2 3 $- 1 2)
|
|
1102 |
Date today printFormat:#(1 2 3 $. 1 2 true)
|
|
1103 |
Date today printFormat:#(2 1 3 32 3 1)
|
|
1104 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1)
|
|
1105 |
Date today printFormat:#(1 2 3 $- 2 1)
|
|
1106 |
Date today printFormat:#(1 2 3 $- 4 1)
|
|
1107 |
"
|
|
1108 |
!
|
|
1109 |
|
|
1110 |
printFormat:aFormatArray on:aStream
|
|
1111 |
"append a printed representation of the receiver to aStream.
|
|
1112 |
The argument, aFormatString controls the format, as described
|
|
1113 |
in the #printFormat: method.
|
|
1114 |
Notice that not all formats can be scanned (correctly) by #readFrom:"
|
|
1115 |
|
|
1116 |
aStream nextPutAll:(self printFormat:aFormatArray)
|
|
1117 |
|
|
1118 |
|
|
1119 |
"european formats:
|
|
1120 |
|
|
1121 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr.
|
|
1122 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr.
|
|
1123 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
|
|
1124 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr.
|
|
1125 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr.
|
|
1126 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr.
|
|
1127 |
|
|
1128 |
US formats:
|
|
1129 |
|
|
1130 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr.
|
|
1131 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr.
|
|
1132 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr.
|
|
1133 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr.
|
|
1134 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr.
|
|
1135 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr.
|
|
1136 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr.
|
|
1137 |
"
|
699
|
1138 |
!
|
|
1139 |
|
|
1140 |
printOn:aStream
|
|
1141 |
"append a printed representation of the receiver to aStream"
|
|
1142 |
|
|
1143 |
self printFormat:#(1 2 3 $- 2 1) on:aStream
|
|
1144 |
|
|
1145 |
"
|
|
1146 |
Date today printOn:Transcript
|
|
1147 |
Date today printNL
|
|
1148 |
"
|
|
1149 |
|
|
1150 |
"Modified: 27.8.1995 / 01:01:49 / claus"
|
|
1151 |
!
|
|
1152 |
|
|
1153 |
storeOn:aStream
|
|
1154 |
"append a representation to aStream, from which the receiver
|
|
1155 |
can be reconstructed"
|
|
1156 |
|
|
1157 |
aStream nextPutAll:'('; nextPutAll:'Date day:'.
|
|
1158 |
self day printOn:aStream.
|
|
1159 |
aStream nextPutAll:' month:'.
|
|
1160 |
self month printOn:aStream.
|
|
1161 |
aStream nextPutAll:' year:'.
|
|
1162 |
self year printOn:aStream.
|
|
1163 |
aStream nextPutAll:')'
|
|
1164 |
|
|
1165 |
"
|
|
1166 |
Date today storeOn:Transcript
|
|
1167 |
Date today storeString
|
|
1168 |
"
|
1
|
1169 |
! !
|
699
|
1170 |
|
|
1171 |
!Date methodsFor:'private accessing'!
|
|
1172 |
|
|
1173 |
dateEncoding
|
|
1174 |
"the internal encoding is stricktly private,
|
|
1175 |
and should not be used outside."
|
|
1176 |
|
|
1177 |
^ dateEncoding
|
|
1178 |
!
|
|
1179 |
|
|
1180 |
dateEncoding:anInteger
|
|
1181 |
"the internal encoding is stricktly private,
|
|
1182 |
and should not be used outside."
|
|
1183 |
|
|
1184 |
dateEncoding := anInteger
|
|
1185 |
!
|
|
1186 |
|
|
1187 |
fromOSTime:osTime
|
|
1188 |
"set my dateEncoding from an OS time.
|
|
1189 |
This somewhat clumsy implementation hides the OS's date representation
|
|
1190 |
(i.e. makes this class independent of what the OS starts its time values with).
|
|
1191 |
Dont use this method, the osTime representation is totally unportable."
|
|
1192 |
|
|
1193 |
OperatingSystem computeDatePartsOf:osTime
|
|
1194 |
for:[:year :month :day |
|
|
1195 |
dateEncoding := (((year * 100) + month) * 100) + day
|
|
1196 |
]
|
|
1197 |
! !
|
|
1198 |
|
|
1199 |
!Date class methodsFor:'documentation'!
|
|
1200 |
|
|
1201 |
version
|
|
1202 |
^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.29 1995-12-07 21:32:16 cg Exp $'
|
|
1203 |
! !
|
|
1204 |
Date initialize!
|