author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 04 Feb 2011 23:09:23 +0000 | |
branch | jv |
changeset 17815 | 956b46750806 |
parent 17814 | b75a7f0c346b |
child 17834 | 04ff72c5039a |
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 |
" |
|
5515 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
54 | 14 |
Magnitude subclass:#Date |
972 | 15 |
instanceVariableNames:'dateEncoding' |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
16 |
classVariableNames:'DayNames MonthNames DayAbbrevs MonthAbbrevs DefaultFormats |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
17 |
ShortFormats LongFormats EnvironmentChange' |
972 | 18 |
poolDictionaries:'' |
7673 | 19 |
category:'Magnitude-Time' |
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 :-) |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
50 |
Notice: no correction for pre-Gregorian dates (< 1583) 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 |
||
8145 | 80 |
!Date class methodsFor:'initialization'! |
81 |
||
82 |
initDefaultNames |
|
83 |
"read the language specific names." |
|
84 |
||
85 |
|enDayNames enDayAbbrevs enMonthNames enMonthAbbrevs |
|
17757 | 86 |
enDefaultFormat enLongFormat enShortFormat | |
8145 | 87 |
|
88 |
DayNames := Dictionary new. |
|
89 |
DayAbbrevs := Dictionary new. |
|
90 |
MonthNames := Dictionary new. |
|
91 |
MonthAbbrevs := Dictionary new. |
|
92 |
DefaultFormats := Dictionary new. |
|
93 |
LongFormats := Dictionary new. |
|
94 |
ShortFormats := Dictionary new. |
|
95 |
||
96 |
enDayNames := #('monday' |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
97 |
'tuesday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
98 |
'wednesday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
99 |
'thursday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
100 |
'friday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
101 |
'saturday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
102 |
'sunday'). |
8145 | 103 |
|
104 |
enDayAbbrevs := #('mon' |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
105 |
'tue' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
106 |
'wed' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
107 |
'thu' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
108 |
'fri' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
109 |
'sat' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
110 |
'sun'). |
8145 | 111 |
|
112 |
enMonthNames := #('january' |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
113 |
'february' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
114 |
'march' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
115 |
'april' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
116 |
'may' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
117 |
'june' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
118 |
'july' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
119 |
'august' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
120 |
'september' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
121 |
'october' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
122 |
'november' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
123 |
'december'). |
8145 | 124 |
|
125 |
enMonthAbbrevs := #('jan' |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
126 |
'feb' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
127 |
'mar' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
128 |
'apr' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
129 |
'may' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
130 |
'jun' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
131 |
'jul' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
132 |
'aug' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
133 |
'sep' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
134 |
'oct' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
135 |
'nov' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
136 |
'dec'). |
8145 | 137 |
|
138 |
DayNames at:#'en' put:enDayNames. |
|
139 |
DayAbbrevs at:#'en' put:enDayAbbrevs. |
|
140 |
MonthNames at:#'en' put:enMonthNames. |
|
141 |
MonthAbbrevs at:#'en' put:enMonthAbbrevs. |
|
142 |
||
143 |
DefaultFormats at:#'en' put:(enDefaultFormat := '%d-%m-%y'). |
|
144 |
ShortFormats at:#'en' put:(enShortFormat := '%d-%m-%y'). |
|
145 |
LongFormats at:#'en' put:(enLongFormat := '%(dayName), %d-%m-%y'). |
|
17757 | 146 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
147 |
"/ take the "master" language here, for the caching |
8145 | 148 |
EnvironmentChange := (Smalltalk language asSymbol ~~ #'en'). |
149 |
||
150 |
" |
|
17757 | 151 |
Date initDefaultNames |
152 |
" |
|
153 |
! |
|
154 |
||
155 |
initNames |
|
156 |
"read the language specific names." |
|
157 |
||
158 |
|lang| |
|
159 |
||
160 |
DayNames isNil ifTrue:[ |
|
161 |
self initDefaultNames. |
|
162 |
]. |
|
163 |
||
164 |
lang := Smalltalk language asSymbol. |
|
165 |
lang ~~ #'en' ifTrue:[ |
|
166 |
self initNamesForLanguage: lang. |
|
167 |
]. |
|
168 |
||
169 |
EnvironmentChange := false |
|
170 |
||
171 |
" |
|
8145 | 172 |
Date initNames |
173 |
" |
|
174 |
! |
|
175 |
||
17757 | 176 |
initNamesForLanguage:language |
8145 | 177 |
"read the language specific names." |
178 |
||
179 |
|resources lang |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
180 |
enDayNames enDayAbbrevs enMonthNames enMonthAbbrevs monthAbbrevKeys |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
181 |
enDefaultFormat enLongFormat enShortFormat may| |
8145 | 182 |
|
8943 | 183 |
DayNames isNil ifTrue:[ |
184 |
self initDefaultNames. |
|
185 |
]. |
|
186 |
||
17757 | 187 |
lang := language asSymbol. |
8145 | 188 |
lang ~~ #'en' ifTrue:[ |
17757 | 189 |
resources := ResourcePack forPackage:'stx:libbasic' resourceFileName: language,'.rs' cached:false . |
190 |
resources notNil ifTrue:[ |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
191 |
enDayNames := DayNames at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
192 |
enDayAbbrevs := DayAbbrevs at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
193 |
enMonthNames := MonthNames at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
194 |
enMonthAbbrevs := MonthAbbrevs at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
195 |
monthAbbrevKeys := enMonthAbbrevs copy. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
196 |
monthAbbrevKeys at:5 put:'MAY_ABBREV'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
197 |
|
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
198 |
enDefaultFormat := DefaultFormats at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
199 |
enShortFormat := ShortFormats at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
200 |
enLongFormat := LongFormats at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
201 |
|
17757 | 202 |
DefaultFormats at:lang put:(resources at:'DATEFORMAT' default:enDefaultFormat). |
203 |
ShortFormats at:lang put:(resources at:'SHORTDATEFORMAT' default:enShortFormat). |
|
204 |
LongFormats at:lang put:(resources at:'LONGDATEFORMAT' default:enLongFormat). |
|
205 |
||
206 |
DayNames at:lang put:(resources array:enDayNames). |
|
207 |
DayAbbrevs at:lang put:(resources array:enDayAbbrevs). |
|
208 |
MonthNames at:lang put:(resources array:enMonthNames). |
|
209 |
MonthAbbrevs at:lang put:(resources array:monthAbbrevKeys). |
|
210 |
"/ may needs special care (same key for long and short name) |
|
211 |
may := resources string:'MAY_ABBREV' default:nil. |
|
212 |
may isNil ifTrue:[ |
|
213 |
may := resources string:'may'. |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
214 |
]. |
17757 | 215 |
(MonthAbbrevs at:lang) at:5 put:may. |
8145 | 216 |
]. |
217 |
]. |
|
218 |
||
219 |
" |
|
17757 | 220 |
Date initNamesForLanguage:#de. |
221 |
Date initNamesForLanguage:#fr. |
|
222 |
Date initNamesForLanguage:#es. |
|
8145 | 223 |
" |
224 |
! |
|
225 |
||
226 |
initialize |
|
8943 | 227 |
DayNames isNil ifTrue:[ |
228 |
self initDefaultNames. |
|
229 |
]. |
|
8145 | 230 |
|
231 |
Smalltalk addDependent:self. |
|
232 |
Language ~= 'en' ifTrue:[ |
|
233 |
EnvironmentChange := true |
|
234 |
] |
|
235 |
! ! |
|
236 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
237 |
!Date class methodsFor:'instance creation'! |
699 | 238 |
|
239 |
fromDays:dayCount |
|
240 |
"return a new Date, given the day-number starting with 0 at 1.Jan 1901; |
|
241 |
(i.e. 'Date fromDays:0' returns 1st Jan. 1901). |
|
242 |
Date asDays is the reverse operation. |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
243 |
Added for GNU/ST-80 compatibility" |
699 | 244 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
245 |
|year rest d yearIncrement| |
699 | 246 |
|
247 |
"approx. year" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
248 |
year := (dayCount // 366) + 1901. |
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
249 |
dayCount < 0 ifTrue:[ |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
250 |
rest := dayCount negated - (self yearAsDays:year) + 1. "+1 for ST-80 compatibility" |
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
251 |
yearIncrement := -1. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
252 |
] ifFalse:[ |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
253 |
rest := dayCount - (self yearAsDays:year) + 1. "+1 for ST-80 compatibility" |
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
254 |
yearIncrement := 1. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
255 |
]. |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
256 |
rest > 365 ifTrue:[ |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
257 |
[d := self daysInYear:year. rest > d] whileTrue:[ |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
258 |
"adjust" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
259 |
year := year + yearIncrement. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
260 |
rest := rest - d. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
261 |
]. |
699 | 262 |
]. |
263 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
264 |
^ self newDay:rest year:year |
699 | 265 |
|
266 |
" |
|
267 |
Date fromDays:0 -> 1 jan 1901 |
|
268 |
Date fromDays:365 -> 1 jan 1902 |
|
269 |
Date fromDays:730 -> 1 jan 1903 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
270 |
Date fromDays:1095 -> 1 jan 1904 |
699 | 271 |
Date fromDays:1460 ->31 dec 1904 since 1904 was a leap year |
272 |
" |
|
273 |
||
1501 | 274 |
"Modified: 1.7.1996 / 14:24:25 / cg" |
699 | 275 |
! |
276 |
||
277 |
newDay:day month:month year:year |
|
278 |
"return a new Date, given the day, month and year. |
|
279 |
For your convenience, month may be either an integer |
|
280 |
or the months name as a string. |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
281 |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
(see those, for example readFrom:onError:)" |
699 | 286 |
|
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
287 |
|monthIndex ok| |
699 | 288 |
|
8446
e19765545de6
Dont generate a warning for years between -1 and -99
Stefan Vogel <sv@exept.de>
parents:
8247
diff
changeset
|
289 |
(year < 100 and:[year > 0]) ifTrue:[ |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
290 |
'Date [warning]: year in [0..99] no longer converted to [1900..1999]' infoPrintCR. |
699 | 291 |
]. |
292 |
month isInteger ifTrue:[ |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
293 |
monthIndex := month |
699 | 294 |
] ifFalse:[ |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
295 |
monthIndex := self indexOfMonth:month |
699 | 296 |
]. |
297 |
(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
|
298 |
ok := self leapYear:year |
699 | 299 |
] ifFalse:[ |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
300 |
ok := day <= (self daysInMonth:month forYear:year) |
699 | 301 |
]. |
302 |
((day > 0) and:[ok]) ifTrue:[ |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
303 |
^ self basicNew year:year month:monthIndex day:day. |
699 | 304 |
]. |
305 |
||
306 |
"this error is triggered if you try to create a date from an |
|
307 |
invalid year/month/day combination; |
|
308 |
Such as 29-feb-year, where year is no leap year |
|
309 |
" |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
310 |
self conversionErrorSignal raiseErrorString:' - invalid date'. |
699 | 311 |
|
312 |
" |
|
313 |
Date newDay:8 month:'may' year:1993 |
|
314 |
Date newDay:8 month:5 year:1994 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
315 |
Date newDay:29 month:'feb' year:2004 |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
316 |
Date newDay:29 month:'feb' year:2003 |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
317 |
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
|
318 |
Date newDay:28 month:'feb' year:95 |
699 | 319 |
" |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
320 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
321 |
"Modified: 19.4.1996 / 15:28:15 / cg" |
699 | 322 |
! |
323 |
||
324 |
newDay:dayInYear year:year |
|
325 |
"return a new Date, given the year and the day-in-year (starting at 1). |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
326 |
See also: Date today / Time now / Timestamp now. |
699 | 327 |
ST-80 compatibility" |
328 |
||
329 |
|monthAndDay| |
|
330 |
||
331 |
(dayInYear between:1 and:365) ifFalse:[ |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
332 |
(dayInYear > 0 or:[(dayInYear == 366) and:[self leapYear:year]]) ifFalse:[ |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
333 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
334 |
this error is triggered, when you try to create a |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
335 |
day from an invalid day-in-year; |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
336 |
for example, 366 in a non-leap year. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
337 |
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
|
338 |
" |
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
339 |
^ self conversionErrorSignal raiseErrorString:' - invalid day in year'. |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
340 |
] |
699 | 341 |
]. |
342 |
monthAndDay := self monthAndDayFromDayInYear:dayInYear forYear:year. |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
343 |
^ self basicNew year:year month:(monthAndDay at:1) day:(monthAndDay at:2) |
699 | 344 |
|
345 |
" |
|
346 |
Date newDay:150 year:1994 |
|
347 |
Date newDay:1 year:1994 |
|
348 |
Date newDay:1 year:1901 |
|
349 |
Date newDay:1 year:1902 |
|
350 |
Date newDay:365 year:1992 |
|
351 |
Date newDay:366 year:1992 |
|
352 |
Date newDay:365 year:1994 |
|
353 |
Date newDay:366 year:1994 |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
354 |
Date newDay:0 year:1994 |
699 | 355 |
" |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
356 |
|
1501 | 357 |
"Modified: 1.7.1996 / 14:22:24 / cg" |
699 | 358 |
! |
359 |
||
360 |
readFrom:aStringOrStream onError:exceptionBlock |
|
361 |
"return a new Date, reading a printed representation from aStream. |
|
362 |
Notice, that this is not the storeString format and |
|
363 |
is different from the format expected by readFrom:. |
|
364 |
BUG: |
|
10760
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
365 |
This method handles american format (i.e. month/day/year), |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
366 |
common format with letter month in the middle (10 December 2007) |
10760
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
367 |
and ISO format (yyyy-mm-dd) - as long as yyyy is > 12. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
368 |
|
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
369 |
It does not handle the german/french and other dd-mm-yyyy. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
370 |
use readFrom:printFormat:onError: for this." |
699 | 371 |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
372 |
^ [ |
10760
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
373 |
|str items first second month day year| |
972 | 374 |
str := aStringOrStream readStream. |
699 | 375 |
|
10760
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
376 |
items := #(1 2 3) collect:[:idx| |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
377 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
378 |
(str peek isDigit) ifTrue:[ |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
379 |
Integer readFrom:str |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
380 |
] ifFalse:[ |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
381 |
str nextAlphaNumericWord |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
382 |
]. |
972 | 383 |
]. |
10760
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
384 |
|
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
385 |
first := items at:1. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
386 |
second := items at:2. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
387 |
|
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
388 |
(first isInteger and:[second isInteger and:[first > 12]]) ifTrue:[ |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
389 |
"ISO Date: yyyy-mm-dd" |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
390 |
year := first. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
391 |
month := second. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
392 |
day := items at:3. |
972 | 393 |
] ifFalse:[ |
10760
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
394 |
second isInteger ifTrue:[ |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
395 |
"must be an american date mm/dd/yy" |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
396 |
month := first. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
397 |
day := second. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
398 |
] ifFalse:[ |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
399 |
"3 Dec 2007" |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
400 |
day := first. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
401 |
month := second. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
402 |
]. |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
403 |
year := items at:3. |
972 | 404 |
]. |
6952
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
405 |
(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
|
406 |
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
|
407 |
]. |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
408 |
self newDay:day month:month year:year |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
409 |
] on:Error do:exceptionBlock. |
699 | 410 |
|
411 |
" |
|
412 |
Date readFromString:'31 December 1992' |
|
4997 | 413 |
Date readFrom:'19:11:1999' |
10760
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
414 |
Date readFrom:'2007-12-31' onError:'wrong date'. |
4997 | 415 |
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
|
416 |
Date readFromString:'12/31/1992' |
4997 | 417 |
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
|
418 |
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
|
419 |
Date readFromString:'12/31/01' |
4997 | 420 |
Date readFromString:'15.4.1992' -> german; leads to an error |
421 |
Date readFromString:'10.4.1992' -> german; leads to a wrong date |
|
422 |
Date readFromString:'10.4.1992' onError:['wrong date'] |
|
423 |
Date readFromString:'32.4.1992' onError:['wrong date'] |
|
424 |
Date readFromString:'fooBar' onError:['wrong date'] |
|
425 |
Date readFromString:'10.4' onError:['wrong date'] |
|
426 |
Date readFromString:'10041999' onError:['wrong date'] |
|
427 |
" |
|
428 |
||
429 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
430 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
431 |
! |
|
432 |
||
7649 | 433 |
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString |
4997 | 434 |
"return a new Date, reading a printed representation from aStream. |
7649 | 435 |
aSqueakFormatArrayOrFormatString may either be a squeak formatArray |
436 |
1 day position (1, 2 or 3) |
|
437 |
2 month position (1..3) |
|
438 |
3 year position (1..3) |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
439 |
or a formatString (see printing instance protocol)." |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
440 |
|
7649 | 441 |
^ self |
442 |
readFrom:aStringOrStream |
|
443 |
printFormat:aSqueakFormatArrayOrFormatString |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
444 |
onError:[ self conversionErrorSignal raise ] |
4997 | 445 |
|
446 |
" |
|
447 |
Date readFrom:'19:11:1999' printFormat:#( 1 2 3 ) |
|
448 |
Date readFrom:'19-nov-1999' printFormat:#( 1 2 3 ) |
|
449 |
Date readFrom:'19:11:1999' printFormat:#( 2 1 3 ) -> exception: wrong month |
|
450 |
Date readFrom:'5:12:1999' printFormat:#( 2 1 3 ) |
|
451 |
Date readFrom:'may-12-1999' printFormat:#( 2 1 3 ) |
|
452 |
Date readFrom:'1999 may 12' printFormat:#( 3 2 1 ) |
|
17757 | 453 |
Date readFrom:'12/31/2001' printFormat:#( 2 1 3 ) |
454 |
Date readFrom:' 31.08.2001' printFormat:#( 1 2 3 ) |
|
455 |
Date readFrom:' 31.dec.2001' printFormat:#( 1 2 3 ) |
|
456 |
Date readFrom:' 31.Dec.2001' printFormat:#( 1 2 3 ) |
|
457 |
Date readFrom:' 31.dez.2001' printFormat:#( 1 2 3 ) |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
458 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
459 |
Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
460 |
Date readFrom:'12/01' printFormat:'%m %y' onError:'fail' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
461 |
Date readFrom:'01' printFormat:'%y' onError:'fail' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
462 |
Date readFrom:'30.01' printFormat:'%d %m' onError:'fail' |
4997 | 463 |
" |
464 |
||
465 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
466 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
467 |
! |
|
468 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
469 |
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString language:languageOrNil onError:exceptionBlock |
4997 | 470 |
"return a new Date, reading a printed representation from aStream. |
7649 | 471 |
aSqueakFormatArrayOrFormatString may either be a squeak formatArray |
472 |
1 day position (1, 2 or 3) |
|
473 |
2 month position (1..3) |
|
474 |
3 year position (1..3) |
|
475 |
or a formatString (see printing instance protocol). |
|
17757 | 476 |
For now %d, %m, %monthName, %shortMonthName and %y are supported in the formatString. |
477 |
The formatString can have any of these characters '-.:,;/' as separator. |
|
478 |
The formatString can also use a space as separator (for ex. '%d %m %y') and any separator will be allowed. |
|
479 |
However, when a character separator is defined, only that separator will be expected. |
|
7649 | 480 |
TODO: make this a general feature of all DateAndTime classes. |
4997 | 481 |
" |
482 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
483 |
|str day month year somePartAssoc| |
7649 | 484 |
|
485 |
str := aStringOrStream readStream. |
|
486 |
||
487 |
aSqueakFormatArrayOrFormatString isArray |
|
488 |
ifTrue:[ |
|
489 |
[ |
|
490 |
|arg| |
|
491 |
||
492 |
arg := Array new:3. |
|
4997 | 493 |
|
7649 | 494 |
1 to:3 do:[:i||v| |
495 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
|
4997 | 496 |
|
7649 | 497 |
v := (str peek isDigit) ifTrue:[Integer readFrom:str] |
498 |
ifFalse:[str nextAlphaNumericWord]. |
|
499 |
arg at:i put:v |
|
500 |
]. |
|
501 |
year := (arg at:(aSqueakFormatArrayOrFormatString at:3)). |
|
502 |
day := arg at:(aSqueakFormatArrayOrFormatString at:1). |
|
503 |
month := arg at:(aSqueakFormatArrayOrFormatString at:2). |
|
7673 | 504 |
] on:Error do:[:ex| ^ exceptionBlock value]. |
7649 | 505 |
] ifFalse:[ |
506 |
[ |
|
507 |
|formatStream fc c sel| |
|
4997 | 508 |
|
7649 | 509 |
formatStream := aSqueakFormatArrayOrFormatString readStream. |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
510 |
|
7649 | 511 |
[formatStream atEnd] whileFalse:[ |
512 |
fc := formatStream next. |
|
513 |
fc == $% ifTrue:[ |
|
514 |
sel := ''. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
515 |
(fc := formatStream peek) notNil ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
516 |
fc = $( ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
517 |
formatStream next. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
518 |
sel := formatStream upTo:$) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
519 |
] ifFalse:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
520 |
sel := sel , (formatStream throughAnyForWhich:[:ch | ch isLetter]) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
521 |
] |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
522 |
]. |
17757 | 523 |
somePartAssoc := self readDatePartFrom:str format:sel language:languageOrNil. |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
524 |
somePartAssoc key == #day ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
525 |
day := somePartAssoc value. |
7649 | 526 |
] ifFalse:[ |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
527 |
somePartAssoc key == #month ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
528 |
month := somePartAssoc value. |
7649 | 529 |
] ifFalse:[ |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
530 |
somePartAssoc key == #year ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
531 |
year := somePartAssoc value. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
532 |
] ifFalse:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
533 |
self error:'oops' |
7649 | 534 |
] |
535 |
] |
|
536 |
] |
|
537 |
] ifFalse:[ |
|
538 |
fc == Character space ifTrue:[ |
|
17757 | 539 |
"/ Skip most possible separator characters |
540 |
"/ (if not enought, should check for isNationalAlphaNumeric instead) |
|
541 |
[(c := str peek) isSeparator or:[ '-.:,;/\|?<>[]{}()#@!!$&^+=~*_"`' includes:c ] ] whileTrue:[ str next ]. |
|
7649 | 542 |
] ifFalse:[ |
543 |
str skipSeparators. |
|
7673 | 544 |
str next == fc ifFalse:[^ exceptionBlock value]. |
7649 | 545 |
str skipSeparators. |
546 |
] |
|
547 |
] |
|
548 |
]. |
|
7673 | 549 |
] on:Error do:[:ex| ^ exceptionBlock value]. |
4997 | 550 |
]. |
7649 | 551 |
|
552 |
day isNil ifTrue:[ day := 1 ]. |
|
553 |
month isNil ifTrue:[ month := 1 ]. |
|
554 |
year isNil ifTrue:[ year := Date today year ]. |
|
555 |
||
556 |
(year between:0 and:99) ifTrue:[ |
|
557 |
year := UserPreferences current twoDigitDateHandler value:year. |
|
558 |
]. |
|
8878 | 559 |
[ |
560 |
^ self newDay:day month:month year:year. |
|
561 |
] on:Error do:[:ex| ^ exceptionBlock value]. |
|
4997 | 562 |
|
563 |
" |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
564 |
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
|
565 |
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
|
566 |
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
|
567 |
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
|
568 |
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
|
569 |
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
|
570 |
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
|
571 |
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
|
572 |
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
|
573 |
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
|
574 |
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
|
575 |
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
|
576 |
|
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
577 |
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
|
578 |
Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail' |
7649 | 579 |
|
580 |
Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail' |
|
581 |
Date readFrom:'12/01' printFormat:'%m %y' onError:'fail' |
|
582 |
Date readFrom:'01' printFormat:'%y' onError:'fail' |
|
17757 | 583 |
Date readFrom:'30.01' printFormat:'%d %m' onError:'fail' |
584 |
||
585 |
Date readFrom:'3-3-1995' printFormat:'%d %m %y' language: #de onError:'fail' |
|
17767 | 586 |
Date readFrom:'3-Mrz-1995' printFormat:'%d %monthName %y' language: #de onError:'fail' |
587 |
Date readFrom:'3-mr-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail' |
|
588 |
Date readFrom:'3/mr/1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail' |
|
589 |
Date readFrom:'3/mr/1995' printFormat:'%d-%shortMonthName-%y' language: #de onError:'fail' |
|
17757 | 590 |
Date readFrom:'3-dez-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail' |
591 |
Date readFrom:'3-Dez-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail' |
|
592 |
Date readFrom:'3-Dezember-1995' printFormat:'%d %monthName %y' language: #de onError:'fail' |
|
593 |
||
4421 | 594 |
" |
595 |
||
596 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
597 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
598 |
! |
|
599 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
600 |
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString onError:exceptionBlock |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
601 |
"return a new Date, reading a printed representation from aStream. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
602 |
aSqueakFormatArrayOrFormatString may either be a squeak formatArray |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
603 |
1 day position (1, 2 or 3) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
604 |
2 month position (1..3) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
605 |
3 year position (1..3) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
606 |
or a formatString (see printing instance protocol). |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
607 |
All of the %-formats as in the printString are supported here. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
608 |
(i.e. %d, %m and %y, %shortMonthName and %monthName) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
609 |
TODO: make this a general feature of all DateAndTime classes. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
610 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
611 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
612 |
^ self |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
613 |
readFrom:aStringOrStream |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
614 |
printFormat:aSqueakFormatArrayOrFormatString |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
615 |
language:nil |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
616 |
onError:exceptionBlock |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
617 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
618 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
619 |
Date readFrom:'31 December 1992' printFormat:#(1 2 3) onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
620 |
Date readFrom:'19:11:1999' printFormat:#(1 2 3) onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
621 |
Date readFrom:'December, 5 1992' printFormat:#(1 2 3) onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
622 |
Date readFrom:'3-jan-95' printFormat:#(1 2 3) onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
623 |
Date readFrom:'12/31/1992' printFormat:#(1 2 3) onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
624 |
Date readFrom:'15.4.1992' printFormat:#(1 2 3) onError:'wrong date' -> german |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
625 |
Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:'fail' -> german |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
626 |
Date readFrom:'10.4.1992' printFormat:#(1 2 3) onError:['wrong date'] |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
627 |
Date readFrom:'32.4.1992' printFormat:#(1 2 3) onError:['wrong date'] |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
628 |
Date readFrom:'fooBar' printFormat:#(1 2 3) onError:['wrong date'] |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
629 |
Date readFrom:'10.4' printFormat:#(1 2 3) onError:['wrong date'] |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
630 |
Date readFrom:'10041999' printFormat:#(1 2 3) onError:['wrong date'] |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
631 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
632 |
Date readFrom:'31/12/92' printFormat:#(1 2 3) onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
633 |
Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
634 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
635 |
Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
636 |
Date readFrom:'12/01' printFormat:'%m %y' onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
637 |
Date readFrom:'01' printFormat:'%y' onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
638 |
Date readFrom:'30.01' printFormat:'%d %m' onError:'fail' |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
639 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
640 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
641 |
"Created: 16.11.1995 / 22:50:17 / cg" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
642 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
643 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
644 |
|
699 | 645 |
today |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
646 |
"return a date, representing today. |
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
647 |
See also: Time now / Timestamp now." |
699 | 648 |
|
1501 | 649 |
^ self fromOSTime:(OperatingSystem getOSTime) |
699 | 650 |
|
651 |
" |
|
652 |
Date today |
|
653 |
" |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
654 |
|
1501 | 655 |
"Modified: 1.7.1996 / 15:20:16 / cg" |
5548 | 656 |
! |
657 |
||
658 |
tomorrow |
|
659 |
"return a date, representing tomorrow. |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
660 |
See also: Time now / Timestamp now." |
5548 | 661 |
|
662 |
^ Date today addDays:1 |
|
663 |
||
664 |
" |
|
665 |
Date tomorrow |
|
666 |
Date tomorrow dayInWeek |
|
667 |
" |
|
668 |
! |
|
669 |
||
17815 | 670 |
utcToday |
671 |
"return a date, representing today. |
|
672 |
See also: Time now / Timestamp now." |
|
673 |
||
674 |
^ self new fromUtcOSTime:(OperatingSystem getOSTime) |
|
675 |
||
676 |
" |
|
677 |
Date today |
|
678 |
Date utcToday |
|
679 |
" |
|
680 |
||
681 |
"Modified: 1.7.1996 / 15:20:16 / cg" |
|
682 |
! |
|
683 |
||
5548 | 684 |
yesterday |
685 |
"return a date, representing yesterday. |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
686 |
See also: Time now / Timestamp now." |
5548 | 687 |
|
688 |
^ Date today subtractDays:1 |
|
689 |
||
690 |
" |
|
691 |
Date yesterday |
|
692 |
Date yesterday dayInWeek |
|
693 |
" |
|
699 | 694 |
! ! |
695 |
||
7299 | 696 |
!Date class methodsFor:'Compatibility-Dolphin'! |
6872 | 697 |
|
698 |
newDay:day monthIndex:month year:year |
|
699 |
^ self newDay:day month:month year:year |
|
700 |
||
701 |
" |
|
702 |
Date newDay:8 monthIndex:5 year:1993 |
|
703 |
" |
|
704 |
||
705 |
"Modified: 19.4.1996 / 15:28:15 / cg" |
|
706 |
! ! |
|
707 |
||
7646 | 708 |
!Date class methodsFor:'Compatibility-ST80'! |
709 |
||
7648 | 710 |
newDay:day monthNumber:monthIndex year:year |
7646 | 711 |
"ST80 compatibility" |
712 |
||
713 |
^ self newDay:day month:monthIndex year:year |
|
714 |
! ! |
|
715 |
||
7299 | 716 |
!Date class methodsFor:'Compatibility-Squeak'! |
7005 | 717 |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
718 |
current |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
719 |
"return the current date" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
720 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
721 |
^ self today |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
722 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
723 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
724 |
Date current |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
725 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
726 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
727 |
|
7005 | 728 |
fromSeconds:seconds |
729 |
"Answer an instance of me which is 'seconds' seconds after January 1, 1901." |
|
730 |
||
731 |
| secondsInDay | |
|
732 |
||
733 |
secondsInDay := 24 * 60 * 60. |
|
734 |
^self fromDays: seconds // secondsInDay |
|
735 |
||
736 |
" |
|
737 |
Date fromSeconds:0 |
|
738 |
Date fromSeconds:(24 * 60 * 60 * 365) |
|
739 |
" |
|
11181 | 740 |
! |
741 |
||
742 |
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock |
|
743 |
"return a new Date, reading a printed representation from aStream. |
|
744 |
Notice, that this is not the storeString format and |
|
745 |
is different from the format expected by readFrom:" |
|
746 |
||
747 |
^ [ |
|
11182 | 748 |
|str monthString month dayString day year yearString| |
11181 | 749 |
|
750 |
str := aStringOrStream readStream. |
|
11182 | 751 |
monthString := str next:2. |
752 |
dayString := str next:2. |
|
753 |
yearString := str next:4. |
|
754 |
||
755 |
day := Integer readFrom:dayString. |
|
756 |
month := Integer readFrom:monthString. |
|
757 |
year := Integer readFrom:yearString. |
|
11181 | 758 |
|
759 |
self newDay:day month:month year:year |
|
760 |
] on:Error do:exceptionBlock |
|
761 |
||
762 |
" |
|
763 |
Date readMMDDYYYYFrom:'10041999' onError:['wrong date'] |
|
764 |
Date readMMDDYYYYFrom:'100419' onError:['wrong date'] |
|
765 |
||
766 |
Date readMMDDYYYYFrom:'10040001' onError:['wrong date'] |
|
767 |
" |
|
768 |
||
769 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
770 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
771 |
! |
|
772 |
||
773 |
readYYYYMMDDFrom:aStringOrStream onError:exceptionBlock |
|
774 |
"return a new Date, reading a printed representation from aStream. |
|
775 |
Notice, that this is not the storeString format and |
|
776 |
is different from the format expected by readFrom:" |
|
777 |
||
778 |
^ [ |
|
11182 | 779 |
|str monthString month dayString day yearString year| |
11181 | 780 |
|
781 |
str := aStringOrStream readStream. |
|
11182 | 782 |
yearString := str next:4. |
783 |
monthString := str next:2. |
|
784 |
dayString := str next:2. |
|
785 |
||
786 |
day := Integer readFrom:dayString. |
|
787 |
month := Integer readFrom:monthString. |
|
788 |
year := Integer readFrom:yearString. |
|
11181 | 789 |
|
790 |
self newDay:day month:month year:year |
|
791 |
] on:Error do:exceptionBlock |
|
792 |
||
793 |
" |
|
794 |
Date readYYYYMMDDFrom:'19991004' onError:['wrong date'] |
|
11182 | 795 |
Date readYYYYMMDDFrom:'911004' onError:['wrong date'] |
11181 | 796 |
" |
7005 | 797 |
! ! |
798 |
||
11553 | 799 |
!Date class methodsFor:'change & update'! |
800 |
||
801 |
update:something with:aParameter from:changedObject |
|
802 |
((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[ |
|
803 |
"just remember change for next access" |
|
804 |
EnvironmentChange := true |
|
805 |
] |
|
806 |
||
807 |
"Created: 15.6.1996 / 15:19:25 / cg" |
|
808 |
! ! |
|
809 |
||
11127 | 810 |
!Date class methodsFor:'error handling'! |
811 |
||
812 |
conversionErrorSignal |
|
813 |
"return the signal used for conversion error handling" |
|
814 |
||
815 |
^ DateConversionError |
|
816 |
! ! |
|
817 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
818 |
!Date class methodsFor:'general queries'! |
699 | 819 |
|
820 |
abbreviatedNameOfDay:dayIndex |
|
821 |
"given a day index (1..7), return the abbreviated name |
|
822 |
of the day" |
|
823 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
824 |
^ self abbreviatedNameOfDay:dayIndex language:nil |
699 | 825 |
|
826 |
" |
|
827 |
Date abbreviatedNameOfDay:4 |
|
828 |
" |
|
829 |
! |
|
830 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
831 |
abbreviatedNameOfDay:dayIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
832 |
"given a day index (1..7), return the abbreviated name |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
833 |
of the day. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
834 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
835 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
836 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
837 |
^ (self dayAbbrevsForLanguage:lang) at:dayIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
838 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
839 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
840 |
Date abbreviatedNameOfDay:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
841 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
842 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
843 |
|
699 | 844 |
abbreviatedNameOfMonth:monthIndex |
845 |
"given a month index (1..12), return the abbreviated name |
|
846 |
of the month" |
|
847 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
848 |
^ self abbreviatedNameOfMonth:monthIndex language:nil |
699 | 849 |
|
850 |
" |
|
851 |
Date abbreviatedNameOfMonth:11 |
|
852 |
Date abbreviatedNameOfMonth:12 |
|
853 |
" |
|
854 |
! |
|
855 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
856 |
abbreviatedNameOfMonth:monthIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
857 |
"given a month index (1..12), return the abbreviated name |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
858 |
of the month. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
859 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
860 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
861 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
862 |
^ (self monthAbbrevsForLanguage:lang) at:monthIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
863 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
864 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
865 |
Date abbreviatedNameOfMonth:11 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
866 |
Date abbreviatedNameOfMonth:12 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
867 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
868 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
869 |
|
699 | 870 |
dateAndTimeNow |
871 |
"return an array containing the date and time of now" |
|
872 |
||
873 |
^ Time dateAndTimeNow |
|
874 |
||
875 |
" |
|
876 |
Date dateAndTimeNow |
|
877 |
" |
|
878 |
! |
|
879 |
||
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
880 |
dayOfFirstWeekInYear:aYear |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
881 |
"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
|
882 |
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
|
883 |
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
|
884 |
(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
|
885 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
886 |
|day dayInWeekOf1stJan firstThursday firstDayInWeek| |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
887 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
888 |
"/ find the first thursday ... |
11127 | 889 |
day := Date newDay:1 year:aYear. |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
890 |
dayInWeekOf1stJan := day dayInWeek. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
891 |
dayInWeekOf1stJan > 4 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
892 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
893 |
] ifFalse:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
894 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
895 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
896 |
"/ back to the preceeding monday |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
897 |
firstDayInWeek := firstThursday subtractDays:3. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
898 |
^ firstDayInWeek |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
899 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
900 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
901 |
Date dayOfFirstWeekInYear:1998 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
902 |
Date dayOfFirstWeekInYear:1999 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
903 |
Date dayOfFirstWeekInYear:2000 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
904 |
Date dayOfFirstWeekInYear:2001 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
905 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
906 |
! |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
907 |
|
699 | 908 |
dayOfWeek:dayName |
909 |
"given the name of a day (either string or symbol), |
|
910 |
return the day-index (1 for monday; 7 for sunday). |
|
911 |
Return 0 for invalid day name" |
|
912 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
913 |
|d| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
914 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
915 |
d := self dayOfWeek:dayName language:nil. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
916 |
d == 0 ifTrue:[ |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
917 |
d := self dayOfWeek:dayName language:'en'. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
918 |
]. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
919 |
^ d |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
920 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
921 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
922 |
Date dayOfWeek:'wednesday' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
923 |
Date dayOfWeek:'Wednesday' |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
924 |
Date dayOfWeek:'Mittwoch' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
925 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
926 |
! |
6976 | 927 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
928 |
dayOfWeek:dayName language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
929 |
"given the name of a day (either string or symbol), |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
930 |
return the day-index (1 for monday; 7 for sunday). |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
931 |
Return 0 for invalid day name. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
932 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
933 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
934 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
935 |
|idx langDayNames| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
936 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
937 |
langDayNames := self dayNamesForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
938 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
939 |
idx := langDayNames indexOf:dayName. |
6976 | 940 |
idx == 0 ifTrue:[ |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
941 |
idx := langDayNames indexOf:dayName asLowercase. |
6976 | 942 |
]. |
943 |
^ idx |
|
699 | 944 |
|
945 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
946 |
Date dayOfWeek:'wednesday' language:'en' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
947 |
Date dayOfWeek:'Wednesday' language:'en' |
699 | 948 |
" |
949 |
! |
|
950 |
||
951 |
daysInMonth:month forYear:yearInteger |
|
952 |
"given the name of a month and a year, return the number |
|
953 |
of days this month has (modified GNU). |
|
954 |
return 0 if the month name was invalid. |
|
955 |
For your convenience, month maybe an integer or name-string." |
|
956 |
||
957 |
|monthIndex "{ Class: SmallInteger }"| |
|
958 |
||
959 |
month isInteger ifTrue:[ |
|
960 |
monthIndex := month |
|
961 |
] ifFalse:[ |
|
962 |
monthIndex := self indexOfMonth:month |
|
963 |
]. |
|
964 |
||
965 |
^ self daysInMonthIndex:monthIndex forYear:yearInteger |
|
966 |
||
967 |
" |
|
968 |
Date daysInMonth:2 forYear:1980 |
|
969 |
Date daysInMonth:2 forYear:1981 |
|
970 |
Date daysInMonth:'feb' forYear:1981 |
|
971 |
" |
|
972 |
! |
|
973 |
||
974 |
daysInYear:yearInteger |
|
975 |
"return the number of days in a year" |
|
976 |
||
977 |
(self leapYear:yearInteger) ifTrue:[^ 366]. |
|
978 |
^ 365 |
|
979 |
||
980 |
" |
|
981 |
Date daysInYear:1900 |
|
982 |
Date daysInYear:1901 |
|
983 |
Date daysInYear:1904 |
|
984 |
Date daysInYear:1980 |
|
985 |
Date daysInYear:1981 |
|
986 |
" |
|
987 |
! |
|
988 |
||
989 |
daysUntilMonth:month forYear:yearInteger |
|
990 |
"given the name of a month and a year, return the number |
|
991 |
of days from 1st january to last of prev month of that year. |
|
992 |
Return 0 if the month name/index is invalid or is january. |
|
993 |
For your convenience, month maybe an integer or name-string." |
|
994 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
995 |
|monthIndex| |
699 | 996 |
|
997 |
month isInteger ifTrue:[ |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
998 |
monthIndex := month |
699 | 999 |
] ifFalse:[ |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1000 |
monthIndex := self indexOfMonth:month |
699 | 1001 |
]. |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1002 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1003 |
^ self daysUntilMonthIndex:monthIndex forYear:yearInteger |
699 | 1004 |
|
1005 |
" |
|
1006 |
Date daysUntilMonth:'feb' forYear:1993 |
|
1007 |
Date daysUntilMonth:'jan' forYear:1993 |
|
1008 |
" |
|
1009 |
! |
|
1010 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1011 |
defaultFormatString |
8118 | 1012 |
(DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[ |
1013 |
self initNames |
|
1014 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1015 |
^ DefaultFormats at:Language ifAbsent:(DefaultFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1016 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1017 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1018 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1019 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1020 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1021 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1022 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1023 |
|
5778 | 1024 |
firstDayOfYear:inYear |
1025 |
"return the weekDay-index of the 1st-january of the given year. |
|
1026 |
1->monday, 2->tuesday, ... 7->sunday" |
|
1027 |
||
1028 |
| t d | |
|
1029 |
||
1030 |
((inYear < 1) or:[ inYear > 9999]) ifTrue:[ |
|
1031 |
^ 0. |
|
1032 |
]. |
|
1033 |
||
1034 |
"/ normal Gregorian calendar: one extra day per four years |
|
1035 |
t := 4 + inYear + ((inYear + 3) // 4). |
|
1036 |
||
1037 |
inYear > 1800 ifTrue:[ |
|
1038 |
"/ Julian calendar: regular Gregorian less 3 days per 400 |
|
1039 |
t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400). |
|
1040 |
]. |
|
1041 |
inYear > 1752 ifTrue:[ |
|
1042 |
"/ calendar changeover |
|
1043 |
t := t + 3. |
|
1044 |
]. |
|
1045 |
d := t \\ 7. |
|
1046 |
"/ convert from 0 (sunday) .. 6 (saturday) |
|
1047 |
"/ to 1 (munday) .. 7 (sunday) |
|
1048 |
d == 0 ifTrue:[^ 7]. |
|
1049 |
^ d |
|
1050 |
||
1051 |
" |
|
1052 |
self firstDayOfYear:2000 |
|
1053 |
(Date newDay:1 year:2000) dayInWeek |
|
1054 |
self firstDayOfYear:1999 |
|
1055 |
(Date newDay:1 year:1999) dayInWeek |
|
1056 |
self firstDayOfYear:1998 |
|
1057 |
(Date newDay:1 year:1998) dayInWeek |
|
1058 |
self firstDayOfYear:2001 |
|
1059 |
(Date newDay:1 year:2001) dayInWeek |
|
1060 |
self firstDayOfYear:2002 |
|
1061 |
(Date newDay:1 year:2002) dayInWeek |
|
1062 |
self firstDayOfYear:2006 |
|
1063 |
(Date newDay:1 year:2006) dayInWeek |
|
1064 |
||
1065 |
self firstDayOfYear:1800 |
|
1066 |
(Date newDay:1 year:1800) dayInWeek |
|
1067 |
" |
|
1068 |
! |
|
1069 |
||
699 | 1070 |
indexOfMonth:aMonthString |
1071 |
"given the name of a month (either string or symbol), |
|
1072 |
return the month-index (1 for jan; 12 for december). |
|
1073 |
The given string may be a full or abbreviated name, |
|
1074 |
case is ignored. |
|
1075 |
Return 0 for invalid month name." |
|
1076 |
||
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1077 |
|monthIndex| |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1078 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1079 |
monthIndex := self indexOfMonth:aMonthString language:nil. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1080 |
"/ if not found, retry in english |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1081 |
(monthIndex == 0 and:[ Smalltalk language ~= 'en' ]) |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1082 |
ifTrue:[ |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1083 |
monthIndex := self indexOfMonth:aMonthString language:'en'. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1084 |
]. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1085 |
^ monthIndex |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1086 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1087 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1088 |
Date indexOfMonth:'jan' |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1089 |
Date indexOfMonth:'Jan' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1090 |
Date indexOfMonth:'December' |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1091 |
Date indexOfMonth:'Dezember' |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1092 |
Date indexOfMonth:'december' |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1093 |
Date indexOfMonth:'dezember' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1094 |
" |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1095 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1096 |
"Modified: / 08-10-2006 / 14:22:06 / cg" |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1097 |
! |
699 | 1098 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1099 |
indexOfMonth:aMonthString language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1100 |
"given the name of a month (either string or symbol), |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1101 |
return the month-index (1 for jan; 12 for december). |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1102 |
The given string may be a full or abbreviated name, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1103 |
case is ignored. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1104 |
Return 0 for invalid month name. |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1105 |
For nil, Smalltalk language (i.e. the current language setting) is used, |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1106 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1107 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1108 |
|idx name langMonthNames langMonthAbbrevs| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1109 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1110 |
langMonthNames := self monthNamesForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1111 |
langMonthAbbrevs := self monthAbbrevsForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1112 |
|
699 | 1113 |
name := aMonthString asLowercase. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1114 |
idx := langMonthAbbrevs indexOf:name. |
699 | 1115 |
idx ~~ 0 ifTrue:[^ idx]. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1116 |
idx := langMonthNames indexOf:name. |
699 | 1117 |
idx ~~ 0 ifTrue:[^ idx]. |
1118 |
||
1119 |
name at:1 put:(name at:1) asUppercase. |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1120 |
idx := langMonthAbbrevs indexOf:name. |
699 | 1121 |
idx ~~ 0 ifTrue:[^ idx]. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1122 |
idx := langMonthNames indexOf:name. |
699 | 1123 |
idx ~~ 0 ifTrue:[^ idx]. |
1124 |
||
1125 |
^ idx |
|
1126 |
||
1127 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1128 |
Date indexOfMonth:'jan' language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1129 |
Date indexOfMonth:'Jan' language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1130 |
Date indexOfMonth:'December' language:#en |
699 | 1131 |
" |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1132 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1133 |
"Modified: / 08-10-2006 / 14:20:17 / cg" |
699 | 1134 |
! |
1135 |
||
1136 |
leapYear:yearInteger |
|
1137 |
"return true, if yearInteger is a leap year." |
|
1138 |
||
1139 |
|y "{ Class: SmallInteger }"| |
|
1140 |
||
1141 |
y := yearInteger. |
|
1142 |
(y \\ 4 == 0) ifTrue:[ |
|
1143 |
(y \\ 100 ~~ 0) ifTrue:[^ true]. |
|
1144 |
(y \\ 400 == 0) ifTrue:[^ true] |
|
1145 |
]. |
|
1146 |
^ false |
|
1147 |
||
1148 |
" |
|
1149 |
Date leapYear:1992 |
|
1150 |
Date leapYear:1994 |
|
1151 |
Date leapYear:1900 |
|
1152 |
Date leapYear:2000 |
|
1153 |
" |
|
1154 |
! |
|
1155 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1156 |
longFormatString |
8118 | 1157 |
(LongFormats isNil or:[EnvironmentChange]) ifTrue:[ |
1158 |
self initNames |
|
1159 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1160 |
^ LongFormats at:Language ifAbsent:(LongFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1161 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1162 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1163 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1164 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1165 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1166 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1167 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1168 |
|
699 | 1169 |
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger |
1170 |
"given a day-in-year (1..365) return an Array containing the |
|
1171 |
month index and the day-in-month. Return nil if the argument is invalid." |
|
1172 |
||
1173 |
|restDays daysInMonth| |
|
1174 |
||
1175 |
restDays := aDayInYear. |
|
1176 |
restDays < 1 ifTrue:[^ nil]. |
|
1177 |
||
1178 |
1 to:12 do:[:m | |
|
1179 |
daysInMonth := self daysInMonthIndex:m forYear:yearInteger. |
|
1180 |
restDays <= daysInMonth ifTrue:[ |
|
1181 |
^ Array with:m with:restDays |
|
1182 |
]. |
|
1183 |
restDays := restDays - daysInMonth |
|
1184 |
]. |
|
1185 |
restDays > daysInMonth ifTrue:[^ nil]. |
|
1186 |
^ Array with:12 with:restDays |
|
1187 |
||
1188 |
" |
|
1189 |
Date monthAndDayFromDayInYear:66 forYear:1980 |
|
1190 |
Date monthAndDayFromDayInYear:66 forYear:1981 |
|
1191 |
" |
|
1192 |
! |
|
1193 |
||
1194 |
nameOfDay:dayIndex |
|
1195 |
"given a day index (1..7), return the name of the day" |
|
1196 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1197 |
^ self nameOfDay:dayIndex language:nil |
699 | 1198 |
|
1199 |
" |
|
8795 | 1200 |
Date nameOfDay:1 |
699 | 1201 |
Date nameOfDay:4 |
1202 |
" |
|
1203 |
! |
|
1204 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1205 |
nameOfDay:dayIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1206 |
"given a day index (1..7), return the name of the day. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1207 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1208 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1209 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1210 |
^ (self dayNamesForLanguage:lang) at:dayIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1211 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1212 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1213 |
Date nameOfDay:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1214 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1215 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1216 |
|
699 | 1217 |
nameOfMonth:monthIndex |
1218 |
"given a month index (1..12), return the name of the month" |
|
1219 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1220 |
^ self nameOfMonth:monthIndex language:nil |
699 | 1221 |
|
1222 |
" |
|
1223 |
Date nameOfMonth:11 |
|
1224 |
Date nameOfMonth:12 |
|
1225 |
Date nameOfMonth:4 |
|
1226 |
" |
|
1227 |
! |
|
1228 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1229 |
nameOfMonth:monthIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1230 |
"given a month index (1..12), return the name of the month. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1231 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1232 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1233 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1234 |
^ (self monthNamesForLanguage:lang) at:monthIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1235 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1236 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1237 |
Date nameOfMonth:11 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1238 |
Date nameOfMonth:12 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1239 |
Date nameOfMonth:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1240 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1241 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1242 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1243 |
shortFormatString |
8118 | 1244 |
(ShortFormats isNil or:[EnvironmentChange]) ifTrue:[ |
1245 |
self initNames |
|
1246 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1247 |
^ ShortFormats at:Language ifAbsent:(ShortFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1248 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1249 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1250 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1251 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1252 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1253 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1254 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1255 |
|
5548 | 1256 |
weekInYearOf:aDateOrTimestamp |
1257 |
"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
|
1258 |
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
|
1259 |
The above definition can lead to the 1st week starting in the old year!!" |
5548 | 1260 |
|
17815 | 1261 |
|date dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week| |
1262 |
||
1263 |
date := aDateOrTimestamp asDate. |
|
1264 |
||
1265 |
dayInYear := date dayInYear. |
|
1266 |
dayOfFirstWeekInYear := self dayOfFirstWeekInYear:date year. |
|
1267 |
||
1268 |
numDays := date subtractDate:dayOfFirstWeekInYear. |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1269 |
"/ 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
|
1270 |
numDays < 0 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1271 |
"/ not in a week here ... |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1272 |
"/ can be either 52 or 53, depending on the previous year. |
17815 | 1273 |
^ self weekInYearOf:(Date newDay:31 month:12 year:date year - 1) |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1274 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1275 |
|
5548 | 1276 |
"/ compute the week |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1277 |
week := numDays // 7 + 1. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1278 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1279 |
"/ 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
|
1280 |
week == 53 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1281 |
dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1. |
17815 | 1282 |
date >= dayOfFirstWeekInNextYear ifTrue:[ |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1283 |
^ 1 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1284 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1285 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1286 |
^ week |
5548 | 1287 |
|
1288 |
" |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1289 |
Timestamp now weekInYear |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1290 |
Date weekInYearOf:(Date newDay:31 month:12 year:1999) was a friday; |
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1291 |
Date weekInYearOf:(Timestamp newDay:1 year:2000) was a saturday; therefore last week of 1999 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1292 |
Date weekInYearOf:(Timestamp newDay:2 year:2000) was a sunday; therefore last week of 1999 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1293 |
Date weekInYearOf:(Timestamp newDay:3 year:2000) was a monday -> W01 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1294 |
Date weekInYearOf:(Timestamp newDay:4 year:2000) was a tuesday -> W01 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1295 |
Date weekInYearOf:(Timestamp newDay:5 year:2000) was a wed -> W01 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1296 |
Date weekInYearOf:(Timestamp newDay:6 year:2000) was a thursday -> W01 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1297 |
Date weekInYearOf:(Timestamp newDay:7 year:2000) was a fri -> W01 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1298 |
Date weekInYearOf:(Timestamp newDay:8 year:2000) was a sat -> W01 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1299 |
Date weekInYearOf:(Timestamp newDay:9 year:2000) was a sun -> W01 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1300 |
Date weekInYearOf:(Timestamp newDay:10 year:2000) was a monday -> W02 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1301 |
Date weekInYearOf:(Timestamp newDay:16 year:2000) was a sunday -> W02 |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1302 |
Date weekInYearOf:(Timestamp newDay:17 year:2000) was a monday -> W03 |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1303 |
Date weekInYearOf:(Date newDay:1 month:1 year:2001) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1304 |
Date weekInYearOf:(Date newDay:2 month:1 year:2001) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1305 |
Date weekInYearOf:(Date newDay:3 month:1 year:2001) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1306 |
Date weekInYearOf:(Date newDay:24 month:12 year:2001) -> W52 |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1307 |
Date weekInYearOf:(Date newDay:30 month:12 year:2001) -> W52 |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1308 |
Date weekInYearOf:(Date newDay:31 month:12 year:2001) -> W01 |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1309 |
Date weekInYearOf:(Date newDay:1 month:1 year:2002) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1310 |
Date weekInYearOf:(Date newDay:2 month:1 year:2002) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1311 |
Date weekInYearOf:(Date newDay:7 month:1 year:2002) |
5548 | 1312 |
" |
1313 |
! |
|
1314 |
||
699 | 1315 |
yearAsDays: yearInteger |
1316 |
"Returns the number of days since Jan 1, 1901. (GNU) |
|
1317 |
to the first Jan of the year, yearInteger. |
|
1318 |
For 1901 this is zero, for 1902 its 365. |
|
1319 |
Defined for years >= 1901" |
|
1320 |
||
1321 |
|y "{ Class: SmallInteger }"| |
|
1322 |
||
1323 |
y := yearInteger - 1900. |
|
1324 |
y := y - 1. |
|
1325 |
^ (y * 365) |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1326 |
+ (y // 4) |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1327 |
- (y // 100) |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1328 |
+ ((y + 300) // 400) |
699 | 1329 |
|
1330 |
" |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1331 |
Date yearAsDays:5 |
699 | 1332 |
Date yearAsDays:1901 |
1333 |
Date yearAsDays:1902 |
|
1334 |
Date yearAsDays:1903 |
|
1335 |
Date yearAsDays:1904 |
|
1336 |
Date yearAsDays:1905 |
|
1337 |
Date yearAsDays:1994 |
|
1338 |
(Date yearAsDays:2001) - (Date yearAsDays:2000) |
|
1339 |
" |
|
1340 |
! ! |
|
1341 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1342 |
!Date class methodsFor:'obsolete'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1343 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1344 |
day:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1345 |
"return a new Date, given the day, month and year. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1346 |
Obsolete: |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1347 |
use newDay:month:year: for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1348 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1349 |
<resource: #obsolete> |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1350 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1351 |
^ self newDay:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1352 |
! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1353 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1354 |
day:dayInYear year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1355 |
"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
|
1356 |
Obsolete: |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1357 |
use newDay:year: for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1358 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1359 |
<resource: #obsolete> |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1360 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1361 |
^ self newDay:dayInYear year:year |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1362 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1363 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1364 |
isLeapYear:yearInteger |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1365 |
"Return true, if a year is a leap year. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1366 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1367 |
Please use the ST-80 compatible #leapYear for new programs, |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1368 |
since this method will vanish." |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1369 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1370 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1371 |
^ self leapYear:yearInteger |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1372 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1373 |
|
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
1374 |
!Date class methodsFor:'private'! |
1 | 1375 |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1376 |
abbreviatedMonthNamesForLanguage:language |
17757 | 1377 |
|langMonthAbbrevs lang| |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1378 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1379 |
(MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1380 |
self initNames |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1381 |
]. |
17757 | 1382 |
lang := language ? Smalltalk language. |
1383 |
langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:nil. |
|
1384 |
||
1385 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1386 |
langMonthAbbrevs isNil ifTrue:[ |
|
1387 |
self initNamesForLanguage: lang. |
|
1388 |
"/ If language initialization failed, take english monthAbbrevs |
|
1389 |
langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:[MonthAbbrevs at:#en.]. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1390 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1391 |
^ langMonthAbbrevs |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1392 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1393 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1394 |
self abbreviatedMonthNamesForLanguage:#en |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1395 |
self abbreviatedMonthNamesForLanguage:#de |
17757 | 1396 |
self abbreviatedMonthNamesForLanguage:#fr |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1397 |
self abbreviatedMonthNamesForLanguage:#es |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1398 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1399 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1400 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1401 |
dayAbbrevsForLanguage:language |
17757 | 1402 |
|langDayAbbrevs lang| |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1403 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1404 |
(DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1405 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1406 |
]. |
17757 | 1407 |
lang := language ? Smalltalk language. |
1408 |
langDayAbbrevs := DayAbbrevs at:lang ifAbsent:nil. |
|
1409 |
||
1410 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1411 |
langDayAbbrevs isNil ifTrue:[ |
|
1412 |
self initNamesForLanguage: lang. |
|
1413 |
"/ If language initialization failed, take english dayAbbrevs |
|
1414 |
langDayAbbrevs := DayAbbrevs at:lang ifAbsent:[DayAbbrevs at:#en.]. |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1415 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1416 |
^ langDayAbbrevs |
17757 | 1417 |
|
1418 |
" |
|
1419 |
self dayAbbrevsForLanguage:#en |
|
1420 |
self dayAbbrevsForLanguage:#de |
|
1421 |
self dayAbbrevsForLanguage:#fr |
|
1422 |
self dayAbbrevsForLanguage:#es |
|
1423 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1424 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1425 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1426 |
dayNamesForLanguage:language |
17757 | 1427 |
|langDayNames lang| |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1428 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1429 |
(DayNames isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1430 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1431 |
]. |
17757 | 1432 |
lang := language ? Smalltalk language. |
1433 |
langDayNames := DayNames at:lang ifAbsent:nil. |
|
1434 |
||
1435 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1436 |
langDayNames isNil ifTrue:[ |
|
1437 |
self initNamesForLanguage: lang. |
|
1438 |
"/ If language initialization failed, take english dayNames |
|
1439 |
langDayNames := DayNames at:lang ifAbsent:[DayNames at:#en]. |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1440 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1441 |
^ langDayNames |
17757 | 1442 |
|
1443 |
" |
|
1444 |
self dayNamesForLanguage:#en |
|
1445 |
self dayNamesForLanguage:#de |
|
1446 |
self dayNamesForLanguage:#fr |
|
1447 |
self dayNamesForLanguage:#es |
|
1448 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1449 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1450 |
|
699 | 1451 |
daysInMonthIndex: monthIndex forYear: yearInteger |
1452 |
"return the number of days in month monthIndex of |
|
1453 |
year yearInteger (modified GNU). |
|
1454 |
Return 0 for invalid month index. |
|
1455 |
This is the internal version of daysInMonth:forYear:" |
|
1456 |
||
1457 |
|days| |
|
1458 |
||
1459 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
|
1460 |
||
1461 |
days := #(31 28 31 "Jan Feb Mar" |
|
1462 |
30 31 30 "Apr May Jun" |
|
1463 |
31 31 30 "Jul Aug Sep" |
|
1464 |
31 30 31 "Oct Nov Dec" |
|
1465 |
) at: monthIndex. |
|
1466 |
||
1467 |
(monthIndex == 2) ifTrue:[ |
|
1468 |
(self leapYear:yearInteger) ifTrue:[ |
|
1469 |
^ days + 1 |
|
1470 |
] |
|
1471 |
]. |
|
1472 |
^ days |
|
1473 |
||
1474 |
" |
|
1475 |
Date daysInMonthIndex:2 forYear:1994 |
|
1476 |
Date daysInMonthIndex:2 forYear:1980 |
|
1477 |
Date daysInMonthIndex:2 forYear:1981 |
|
1478 |
" |
|
1479 |
! |
|
1480 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1481 |
daysUntilMonthIndex: monthIndex forYear: yearInteger |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1482 |
"return the number of days in month monthIndex of |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1483 |
year yearInteger (modified GNU). |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1484 |
Return 0 for invalid month index. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1485 |
This is the internal version of daysInMonth:forYear:" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1486 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1487 |
|days| |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1488 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1489 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1490 |
|sum| |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1491 |
sum := 0. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1492 |
#(31 28 31 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1493 |
30 31 30 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1494 |
31 31 30 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1495 |
31 30 31 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1496 |
) collect:[:each | |first| first:= sum. sum := sum + each. first] |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1497 |
#(0 31 59 90 120 151 181 212 243 273 304 334) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1498 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1499 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1500 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1501 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1502 |
days := #(0 31 59 90 120 151 181 212 243 273 304 334) at: monthIndex. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1503 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1504 |
(monthIndex > 2) ifTrue:[ |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1505 |
(self leapYear:yearInteger) ifTrue:[ |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1506 |
^ days + 1 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1507 |
] |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1508 |
]. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1509 |
^ days |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1510 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1511 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1512 |
Date daysUntilMonthIndex:3 forYear:1994 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1513 |
Date daysUntilMonthIndex:3 forYear:1980 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1514 |
Date daysUntilMonthIndex:3 forYear:1981 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1515 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1516 |
! |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1517 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1518 |
monthAbbrevsForLanguage:language |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1519 |
<resource: #obsolete> |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1520 |
"obsolete" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1521 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1522 |
^ self abbreviatedMonthNamesForLanguage:language |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1523 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1524 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1525 |
monthNamesForLanguage:language |
17757 | 1526 |
|langMonthNames lang| |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1527 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1528 |
(MonthNames isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1529 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1530 |
]. |
17757 | 1531 |
lang := language ? Smalltalk language. |
1532 |
langMonthNames := MonthNames at:lang ifAbsent:nil. |
|
1533 |
||
1534 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1535 |
langMonthNames isNil ifTrue:[ |
|
1536 |
self initNamesForLanguage: lang. |
|
1537 |
"/ If language initialization failed, take english monthNames |
|
1538 |
langMonthNames := MonthNames at:lang ifAbsent:[MonthNames at:#en.]. |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1539 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1540 |
^ langMonthNames |
54 | 1541 |
! ! |
1542 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1543 |
!Date class methodsFor:'private-encoding/decoding'! |
54 | 1544 |
|
1545 |
encodeYear:y month:m day:d |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1546 |
"the internal encoding is strictly private, |
92 | 1547 |
and should not be used outside." |
1548 |
||
54 | 1549 |
^ (((y * 100) + m) * 100) + d |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1550 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1551 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1552 |
readDatePartFrom:str format:fmt language:languageOrNil |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1553 |
"read a single component (such as %shortName) from str" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1554 |
|
17757 | 1555 |
|dayName monthName day month year format string | |
1556 |
||
1557 |
format := fmt. |
|
1558 |
string := str throughAnyForWhich:[:ch | ch isNationalAlphaNumeric]. |
|
1559 |
||
1560 |
((format sameAs:'dayName') or:[format sameAs:'shortDayName']) ifTrue:[ |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1561 |
"/ skipped, in case the format is 'monday, 23rd of may...' - not used for decoding |
17757 | 1562 |
dayName := string. |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1563 |
^ nil. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1564 |
]. |
17757 | 1565 |
(format sameAs:'d') ifTrue:[ |
1566 |
day := Integer readFrom:string. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1567 |
^ #day -> day |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1568 |
]. |
17757 | 1569 |
|
1570 |
(format sameAs:'m') ifTrue:[ |
|
1571 |
month := Integer readFrom:string. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1572 |
^ #month -> month |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1573 |
]. |
17757 | 1574 |
(format sameAs:'monthName') ifTrue:[ |
1575 |
monthName := string. |
|
1576 |
month := (Date monthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m]. |
|
1577 |
"/ month == 0 ifTrue:[self error:'invalid month name']. |
|
1578 |
^ #month -> month |
|
1579 |
]. |
|
1580 |
(format sameAs:'shortMonthName') ifTrue:[ |
|
1581 |
monthName := string. |
|
1582 |
month := (Date abbreviatedMonthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m]. |
|
1583 |
"/ month == 0 ifTrue:[self error:'invalid month name']. |
|
1584 |
^ #month -> month |
|
1585 |
]. |
|
1586 |
||
1587 |
format = 'y' ifTrue:[ |
|
1588 |
year := Integer readFrom:string. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1589 |
year < 100 ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1590 |
^ #year -> (year + 2000) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1591 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1592 |
^ #year -> year |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1593 |
]. |
17757 | 1594 |
format = 'Y' ifTrue:[ |
1595 |
year := Integer readFrom:string. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1596 |
year >= 100 ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1597 |
^ #year -> year |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1598 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1599 |
^ #year -> (year + 2000) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1600 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1601 |
self error:'unknown format specifier' |
54 | 1602 |
! ! |
1603 |
||
7258 | 1604 |
!Date class methodsFor:'private-instance creation'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1605 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1606 |
fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1607 |
"return a date, representing the date given by the operatingSystem time. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1608 |
This somewhat clumsy implementation hides the OS's date representation |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1609 |
(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
|
1610 |
Dont use this method, the osTime representation is totally unportable." |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1611 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1612 |
^ self basicNew fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1613 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1614 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1615 |
Date fromOSTime:0 -> on UNIX: this should return 1st Jan 1970 |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1616 |
thats where Unix time starts |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1617 |
On other systems, it may be something different. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1618 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1619 |
Date fromOSTime:(24*60*60*1000) -> on UNIX: the day after |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1620 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1621 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1622 |
|
7261 | 1623 |
!Date methodsFor:'Compatibility-ANSI'! |
6419 | 1624 |
|
1625 |
dayOfWeek |
|
1626 |
"return the week-day of the receiver - 1 is sunday, 7 for saturday. |
|
1627 |
WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday). |
|
1628 |
" |
|
1629 |
||
1630 |
|d| |
|
1631 |
||
1632 |
d := self dayInWeek. |
|
1633 |
d == 7 ifTrue:[ |
|
1634 |
^ 1 |
|
1635 |
]. |
|
1636 |
^ d + 1 |
|
1637 |
||
1638 |
" |
|
1639 |
Date today dayOfWeek |
|
1640 |
Date today dayInWeek |
|
1641 |
" |
|
1642 |
! |
|
1643 |
||
1644 |
dayOfWeekAbbreviation |
|
1645 |
"return the short week-day of the receiver as a string. |
|
1646 |
The returned string depends on the language setting. |
|
1647 |
Expect things like 'mon', 'tue' ..." |
|
1648 |
||
1649 |
^ self abbreviatedDayName |
|
1650 |
||
1651 |
" |
|
1652 |
Date today dayOfWeekAbbreviation |
|
1653 |
" |
|
1654 |
! |
|
1655 |
||
1656 |
dayOfWeekName |
|
1657 |
"return the week-day of the receiver as a string. |
|
1658 |
The returned string depends on the language setting. |
|
1659 |
Expect things like 'monday', 'tuesday' ..." |
|
1660 |
||
1661 |
^ self weekday |
|
1662 |
||
1663 |
" |
|
1664 |
Date today dayOfWeekName |
|
1665 |
Date today dayOfWeekAbbreviation |
|
1666 |
" |
|
1667 |
! |
|
1668 |
||
1669 |
dayOfYear |
|
1670 |
"return the day-nr within the year of the receiver - 1..365/366" |
|
1671 |
||
1672 |
^ self dayInYear |
|
1673 |
||
1674 |
" |
|
1675 |
Date today dayOfYear |
|
1676 |
" |
|
1677 |
! |
|
1678 |
||
1679 |
monthAbbreviation |
|
1680 |
"return the month of the receiver as a string. |
|
1681 |
The returned string depends on the language setting. |
|
1682 |
Expect things like 'jan', 'feb' ..." |
|
1683 |
||
1684 |
^ self abbreviatedMonthName |
|
1685 |
||
1686 |
" |
|
1687 |
Date today monthAbbreviation |
|
1688 |
" |
|
1689 |
! ! |
|
1690 |
||
7261 | 1691 |
!Date methodsFor:'Compatibility-ST80'! |
5515 | 1692 |
|
11740 | 1693 |
firstDayInMonth |
1694 |
"Return the first day in the month of the receiver" |
|
1695 |
||
1696 |
^ self subtractDays:(self dayOfMonth - 1) |
|
1697 |
||
1698 |
" |
|
1699 |
Date today |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1700 |
Date today firstDayInMonth |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1701 |
Date today firstDayInMonth subtractDays:1 |
11740 | 1702 |
(Date today subtractDays:30) firstDayInMonth |
1703 |
(Date today subtractDays:122) firstDayInMonth |
|
1704 |
(Date today subtractDays:154) firstDayInMonth |
|
1705 |
" |
|
1706 |
! |
|
1707 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1708 |
lastDayInMonth |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1709 |
"Return the last day in the month in which the receiver is." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1710 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1711 |
^ self addDays:(self daysInMonth - self day). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1712 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1713 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1714 |
Date today |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1715 |
Date today lastDayInMonth |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1716 |
Date today lastDayInMonth addDays:1 |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1717 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1718 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1719 |
|
11664 | 1720 |
next:dayName |
1721 |
"Return the next date whose weekday name is dayName. |
|
1722 |
Caveat; dayName is expected to be in the current language" |
|
1723 |
||
1724 |
|ti ni| |
|
1725 |
||
1726 |
ti := self weekdayIndex. |
|
1727 |
ni := (self class dayOfWeek:dayName). |
|
1728 |
^ self addDays:(ni > ti ifTrue:[ ni-ti ] ifFalse:[ 7+ni-ti ]) |
|
1729 |
||
1730 |
" |
|
1731 |
Date today |
|
1732 |
Date today next:#Friday |
|
1733 |
Date today next:#Sunday |
|
1734 |
Date today next:#Monday |
|
1735 |
Date today next:#Thursday |
|
1736 |
Date today next:#WednesDay |
|
1737 |
" |
|
1738 |
! |
|
1739 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1740 |
nextDayWithIndex:dayIndex |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1741 |
"Return the next date whose weekday name is dayName. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1742 |
dayIndex is Monday=1, ... , Sunday=7" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1743 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1744 |
|ti| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1745 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1746 |
self assert:(dayIndex between:1 and:7). |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1747 |
ti := self weekdayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1748 |
^ self addDays:(dayIndex > ti ifTrue:[ dayIndex-ti ] ifFalse:[ 7+dayIndex-ti ]) |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1749 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1750 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1751 |
Date today |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1752 |
Date today nextDayWithIndex:5 - next Friday |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1753 |
Date today nextDayWithIndex:7 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1754 |
Date today nextDayWithIndex:1 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1755 |
Date today nextDayWithIndex:4 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1756 |
Date today nextDayWithIndex:3 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1757 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1758 |
! |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1759 |
|
6976 | 1760 |
previous:dayName |
1761 |
"Return the previous date whose weekday name is dayName. |
|
1762 |
Caveat; dayName is expected to be in the current language" |
|
1763 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1764 |
^ self previousDayWithIndex:(self class dayOfWeek:dayName). |
6976 | 1765 |
|
1766 |
" |
|
11664 | 1767 |
Date today |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1768 |
Date today previous:#Montag |
6976 | 1769 |
Date today previous:#Monday |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1770 |
|
11664 | 1771 |
Date today previous:#Friday |
1772 |
Date today previous:#Sunday |
|
1773 |
Date today previous:#Monday |
|
1774 |
Date today previous:#Thursday |
|
1775 |
Date today previous:#WednesDay |
|
1776 |
Date today previous:#TuesDay |
|
6976 | 1777 |
" |
1778 |
! |
|
1779 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1780 |
previousDayWithIndex:dayIndex |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1781 |
"Return the previous date whose weekday name is dayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1782 |
dayIndex is Monday=1, ... , Sunday=7" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1783 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1784 |
|ti| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1785 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1786 |
self assert:(dayIndex between:1 and:7). |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1787 |
ti := self weekdayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1788 |
^ self subtractDays:(((ti - dayIndex - 1) \\ 7) + 1) |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1789 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1790 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1791 |
Date today |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1792 |
Date today previousDayWithIndex:1 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1793 |
Date today previousDayWithIndex:5 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1794 |
Date today previousDayWithIndex:7 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1795 |
Date today previousDayWithIndex:4 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1796 |
Date today previousDayWithIndex:3 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1797 |
Date today previousDayWithIndex:2 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1798 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1799 |
! |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1800 |
|
7023 | 1801 |
printFormat:aFormatArray |
1802 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
1803 |
Return a string containing a printed representation of the receiver. |
|
1804 |
The formatArray argument consists of 6 or 7 integers which control |
|
1805 |
the resulting string. The entries are: |
|
1806 |
1 day position (1, 2 or 3) |
|
1807 |
2 month position (1..3) |
|
1808 |
3 year position (1..3) |
|
1809 |
4 asciiValue of separator character or separator character |
|
1810 |
or collection of 2 separator characters |
|
1811 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
1812 |
4: abbreviated uppercase 5: full uppercase) |
|
1813 |
6 year format (1 include century; 2 exclude century) |
|
1814 |
7 (optional) true/false. |
|
1815 |
if true, print numbers in 2-digit format |
|
1816 |
(i.e. with leading zeros); |
|
1817 |
Taken as false, if ommited |
|
1818 |
||
1819 |
Day and monthnames are in the currently active language. |
|
1820 |
||
1821 |
This method supports more options than the ST-80 version; month formats |
|
1822 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
1823 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
1824 |
||
1825 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
1826 |
This is an ST-80 compatibility method - I would have choosen another |
|
1827 |
(less cryptic) formatString ... |
|
1828 |
" |
|
1829 |
||
7961 | 1830 |
^ self printFormat:aFormatArray forLanguage:nil |
1831 |
||
1832 |
" |
|
1833 |
Date today printFormat:#(1 2 3 '' 1 2) |
|
1834 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
1835 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
|
1836 |
Date today printFormat:#(2 1 3 32 3 1) |
|
1837 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
1838 |
Date today printFormat:#(1 2 3 $- 2 1) |
|
1839 |
Date today printFormat:#(1 2 3 $- 4 1) |
|
1840 |
" |
|
1841 |
! |
|
1842 |
||
1843 |
printFormat:aFormatArray forLanguage:languageOrNil |
|
1844 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
1845 |
Return a string containing a printed representation of the receiver. |
|
1846 |
The formatArray argument consists of 6 or 7 integers which control |
|
1847 |
the resulting string. The entries are: |
|
1848 |
1 day position (1, 2 or 3) |
|
1849 |
2 month position (1..3) |
|
1850 |
3 year position (1..3) |
|
1851 |
4 asciiValue of separator character or separator character |
|
1852 |
or collection of 2 separator characters |
|
1853 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
1854 |
4: abbreviated uppercase 5: full uppercase) |
|
1855 |
6 year format (1 include century; 2 exclude century) |
|
1856 |
7 (optional) true/false. |
|
1857 |
if true, print numbers in 2-digit format |
|
1858 |
(i.e. with leading zeros); |
|
1859 |
Taken as false, if ommited |
|
1860 |
||
1861 |
Day and monthnames are in the currently active language. |
|
1862 |
||
1863 |
This method supports more options than the ST-80 version; month formats |
|
1864 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
1865 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
1866 |
||
1867 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
1868 |
This is an ST-80 compatibility method - I would have choosen another |
|
1869 |
(less cryptic) formatString ... |
|
1870 |
" |
|
1871 |
||
7023 | 1872 |
|mf upperCase day month year components sep1 sep2 leadingZeros| |
1873 |
||
1874 |
aFormatArray size > 6 ifTrue:[ |
|
1875 |
leadingZeros := aFormatArray at:7 |
|
1876 |
] ifFalse:[ |
|
1877 |
leadingZeros := false. |
|
1878 |
]. |
|
1879 |
||
1880 |
components := Array new:3. |
|
1881 |
day := self day. |
|
1882 |
leadingZeros ifTrue:[ |
|
1883 |
day := day printStringLeftPaddedTo:2 with:$0 |
|
1884 |
] ifFalse:[ |
|
1885 |
day := day printString |
|
1886 |
]. |
|
1887 |
components at:(aFormatArray at:1) put:day. |
|
1888 |
||
1889 |
upperCase := false. |
|
1890 |
mf := aFormatArray at:5. |
|
1891 |
(mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true]. |
|
1892 |
||
1893 |
mf == 1 ifTrue:[ |
|
1894 |
month := self month. |
|
1895 |
leadingZeros ifTrue:[ |
|
1896 |
month := month printStringLeftPaddedTo:2 with:$0 |
|
1897 |
] ifFalse:[ |
|
1898 |
month := month printString |
|
1899 |
] |
|
1900 |
] ifFalse:[ |
|
1901 |
mf == 2 ifTrue:[ |
|
7961 | 1902 |
month := self abbreviatedMonthNameForLanguage:languageOrNil |
7023 | 1903 |
] ifFalse:[ |
7961 | 1904 |
month := self monthNameForLanguage:languageOrNil |
7023 | 1905 |
] |
1906 |
]. |
|
1907 |
upperCase ifTrue:[month := month asUppercase]. |
|
1908 |
components at:(aFormatArray at:2) put:month. |
|
1909 |
||
1910 |
year := self year. |
|
1911 |
(aFormatArray at:6) == 2 ifTrue:[ |
|
1912 |
year := year \\ 100. |
|
1913 |
year := year printStringLeftPaddedTo:2 with:$0 |
|
1914 |
]. |
|
1915 |
year := year printString. |
|
1916 |
components at:(aFormatArray at:3) put:year. |
|
1917 |
||
1918 |
sep1 := sep2 := (aFormatArray at:4). |
|
1919 |
sep1 isString ifFalse:[ |
|
1920 |
sep1 isCollection ifTrue:[ |
|
1921 |
sep2 := (sep1 at:2). |
|
1922 |
sep1 := (sep1 at:1). |
|
1923 |
] ifFalse:[ |
|
1924 |
sep1 := sep2 := sep1 asCharacter |
|
1925 |
] |
|
1926 |
]. |
|
1927 |
||
1928 |
^ (components at:1) |
|
1929 |
, sep1 asString |
|
1930 |
, (components at:2) |
|
1931 |
, sep2 asString |
|
1932 |
, (components at:3) |
|
1933 |
||
1934 |
" |
|
7961 | 1935 |
Date today printFormat:#(1 2 3 '' 1 2) |
1936 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
7023 | 1937 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
1938 |
Date today printFormat:#(2 1 3 32 3 1) |
|
1939 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
7961 | 1940 |
Date today printFormat:#(1 2 3 $- 2 1) forLanguage:#en |
1941 |
Date today printFormat:#(1 2 3 $- 4 1) forLanguage:#en |
|
1942 |
" |
|
1943 |
! |
|
1944 |
||
1945 |
printFormat:aFormatArray forLanguage:languageOrNil on:aStream |
|
1946 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
1947 |
in printFormat:. |
|
1948 |
Append a printed representation of the receiver to aStream. |
|
1949 |
The argument, aFormatString controls the format, as described |
|
1950 |
in the #printFormat: method. |
|
1951 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
1952 |
||
1953 |
aStream nextPutAll:(self printFormat:aFormatArray forLanguage:languageOrNil) |
|
1954 |
||
1955 |
||
1956 |
"european formats: |
|
1957 |
||
1958 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
1959 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
1960 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1961 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
1962 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
1963 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
1964 |
||
1965 |
US formats: |
|
1966 |
||
1967 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
1968 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
1969 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
1970 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
1971 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
1972 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1973 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
7023 | 1974 |
" |
1975 |
! |
|
1976 |
||
1977 |
printFormat:aFormatArray on:aStream |
|
1978 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
1979 |
in printFormat:. |
|
1980 |
Append a printed representation of the receiver to aStream. |
|
1981 |
The argument, aFormatString controls the format, as described |
|
1982 |
in the #printFormat: method. |
|
1983 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
1984 |
||
1985 |
aStream nextPutAll:(self printFormat:aFormatArray) |
|
1986 |
||
1987 |
||
1988 |
"european formats: |
|
1989 |
||
1990 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
1991 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
1992 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1993 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
1994 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
1995 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
1996 |
||
1997 |
US formats: |
|
1998 |
||
1999 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
2000 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
2001 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
2002 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
2003 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
2004 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
2005 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
2006 |
" |
|
2007 |
! |
|
2008 |
||
5515 | 2009 |
shortPrintString |
2010 |
"dummy - for now" |
|
2011 |
||
2012 |
^ self printString |
|
2013 |
||
2014 |
"Created: 20.6.1997 / 17:16:48 / cg" |
|
6976 | 2015 |
! |
2016 |
||
2017 |
weekdayIndex |
|
2018 |
"Return the day index; Monday=1, ... , Sunday=7" |
|
2019 |
||
2020 |
^ (self asDays + 1) \\ 7 + 1 "1 January 1901 was a Tuesday" |
|
2021 |
||
2022 |
" |
|
2023 |
Date today dayName |
|
2024 |
Date today weekdayIndex |
|
2025 |
" |
|
5515 | 2026 |
! ! |
2027 |
||
7261 | 2028 |
!Date methodsFor:'Compatibility-Squeak'! |
4407 | 2029 |
|
2030 |
mmddyyyy |
|
4462 | 2031 |
"return a printed representation of the receiver in the |
2032 |
form mmddyyyy. |
|
2033 |
The receiver can be reconstructed with: |
|
2034 |
Date readMMDDYYYYFrom:aStringOrStream onError:[...]" |
|
2035 |
||
11182 | 2036 |
^ self printStringFormat:'%m%d%y' |
2037 |
||
2038 |
"/ ^ (self month printStringLeftPaddedTo:2 with:$0) |
|
2039 |
"/ , (self day printStringLeftPaddedTo:2 with:$0) |
|
2040 |
"/ , (self year printStringLeftPaddedTo:4 with:$0) |
|
4407 | 2041 |
|
2042 |
" |
|
2043 |
Date today mmddyyyy |
|
2044 |
" |
|
2045 |
! ! |
|
2046 |
||
699 | 2047 |
!Date methodsFor:'accessing'! |
241 | 2048 |
|
699 | 2049 |
abbreviatedDayName |
2050 |
"return the short week-day of the receiver as a string. |
|
2051 |
The returned string depends on the language setting. |
|
2052 |
Expect things like 'mon', 'tue' ..." |
|
54 | 2053 |
|
699 | 2054 |
^ self class abbreviatedNameOfDay:(self dayInWeek) |
92 | 2055 |
|
2056 |
" |
|
699 | 2057 |
Date today abbreviatedDayName |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2058 |
(Date newDay:15 month:4 year:1959) abbreviatedDayName |
92 | 2059 |
" |
2060 |
! |
|
2061 |
||
699 | 2062 |
abbreviatedMonthName |
2063 |
"return the month of the receiver as a string. |
|
2064 |
The returned string depends on the language setting. |
|
2065 |
Expect things like 'jan', 'feb' ..." |
|
54 | 2066 |
|
699 | 2067 |
^ self class abbreviatedNameOfMonth:(self month) |
68 | 2068 |
|
92 | 2069 |
" |
699 | 2070 |
Date today abbreviatedMonthName |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2071 |
(Date newDay:15 month:4 year:1959) abbreviatedMonthName |
92 | 2072 |
" |
2073 |
! |
|
2074 |
||
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2075 |
abbreviatedMonthNameForLanguage:lang |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2076 |
"return the month of the receiver as a string. |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2077 |
The returned string depends on the language setting. |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2078 |
Expect things like 'jan', 'feb' ..." |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2079 |
|
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2080 |
^ self class abbreviatedNameOfMonth:(self month) language:lang |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2081 |
|
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2082 |
" |
7961 | 2083 |
Date today abbreviatedMonthNameForLanguage:#en |
2084 |
Date today abbreviatedMonthNameForLanguage:#de |
|
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2085 |
" |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2086 |
! |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2087 |
|
92 | 2088 |
asDays |
2089 |
"return the number of days elapsed since 01-Jan-1901 |
|
2090 |
and the receiver's day; starts with 0 for 1-1-1901. |
|
2091 |
Date>>fromDays: is the reverse operation. |
|
2092 |
For ST-80 compatibility." |
|
68 | 2093 |
|
2094 |
|yr| |
|
2095 |
||
2096 |
yr := self year. |
|
2097 |
^ (self class yearAsDays:yr) |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2098 |
+ (self class daysUntilMonthIndex:self month forYear:yr) |
68 | 2099 |
+ self day |
85 | 2100 |
- 1 |
68 | 2101 |
|
92 | 2102 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2103 |
(Date newDay: 5 month: 8 year: 1962) asDays -> should be 22496 |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2104 |
(Date newDay: 1 month: 1 year: 1901) asDays -> 0 |
92 | 2105 |
Date today asDays |
2106 |
Date fromDays:(Date today asDays + 7) |
|
2107 |
" |
|
77 | 2108 |
! |
2109 |
||
2110 |
asSeconds |
|
92 | 2111 |
"return the seconds between 1.jan.1901 and the same time in the receivers |
2112 |
day. (i.e. midnight to midnight). |
|
1501 | 2113 |
This does not include any leapSeconds ... strictly speaking, this is incorrect. |
77 | 2114 |
ST-80 compatibility." |
2115 |
||
92 | 2116 |
^ 60*60*24 * self asDays |
77 | 2117 |
|
92 | 2118 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2119 |
(Date newDay: 5 month: 8 year: 1962) asSeconds |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2120 |
(Date newDay: 1 month: 1 year: 1901) asSeconds |
92 | 2121 |
(Date today addDays:7) asSeconds - Date today asSeconds |
1501 | 2122 |
" |
2123 |
||
2124 |
"Modified: 1.7.1996 / 14:19:17 / cg" |
|
699 | 2125 |
! |
2126 |
||
2127 |
day |
|
2128 |
"return the day (1..31) of the receiver" |
|
2129 |
||
2130 |
^ dateEncoding \\ 100 |
|
2131 |
||
8626 | 2132 |
"example: |
699 | 2133 |
Date today day |
2134 |
" |
|
2135 |
! |
|
2136 |
||
2137 |
dayInWeek |
|
5778 | 2138 |
"return the week-day of the receiver - 1 for monday, 7 for sunday. |
6419 | 2139 |
WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday). |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2140 |
WARNING: does not care for pre-gregorian dates |
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2141 |
(i.e. do not use this for dates before 1583) |
5778 | 2142 |
" |
699 | 2143 |
|
3256
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2144 |
|wday| |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2145 |
|
5778 | 2146 |
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
|
2147 |
+ self asDays) \\ 7 + 1. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2148 |
wday < 1 ifTrue:[ |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2149 |
wday := wday + 7 |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2150 |
]. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2151 |
^ wday |
699 | 2152 |
|
2153 |
" |
|
5778 | 2154 |
Date today dayInWeek |
5548 | 2155 |
Date tomorrow dayInWeek |
2156 |
Date yesterday dayInWeek |
|
5778 | 2157 |
(Date today subtractDays:2) dayInWeek |
3257 | 2158 |
Date today weekday |
5548 | 2159 |
Date tomorrow weekday |
2160 |
Date yesterday weekday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2161 |
(Date newDay:15 month:4 year:1959) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2162 |
(Date newDay:1 month:1 year:1901) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2163 |
(Date newDay:31 month:12 year:1900) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2164 |
(Date newDay:31 month:12 year:1899) dayInWeek |
699 | 2165 |
" |
1501 | 2166 |
|
3257 | 2167 |
"Modified: / 1.2.1998 / 14:10:27 / cg" |
699 | 2168 |
! |
2169 |
||
5548 | 2170 |
dayInYear |
2171 |
"return the day-nr within the year of the receiver - 1 .. 365/366" |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2172 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2173 |
" |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2174 |
|daysSoFar| |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2175 |
daysSoFar := 0. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2176 |
#(0 31 28 31 30 31 30 31 31 30 31 30) collect:[:i| daysSoFar := daysSoFar + i] |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2177 |
" |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2178 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2179 |
|days month| |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2180 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2181 |
month := self month. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2182 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2183 |
days := #(0 31 59 90 120 151 181 212 243 273 304 334) at:month. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2184 |
days := days + self day. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2185 |
(month > 2 and:[self class leapYear:self year]) ifTrue:[ |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2186 |
days := days + 1. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2187 |
]. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2188 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2189 |
^ days |
5548 | 2190 |
|
2191 |
" |
|
2192 |
Date today dayInYear |
|
2193 |
(Date newDay:1 year:1999) dayInYear |
|
2194 |
(Date newDay:1 year:2000) dayInYear |
|
2195 |
(Date newDay:2 year:2000) dayInYear |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2196 |
(Date newDay:59 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2197 |
(Date newDay:60 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2198 |
(Date newDay:61 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2199 |
(Date newDay:366 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2200 |
(Date newDay:59 year:2005) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2201 |
(Date newDay:60 year:2005) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2202 |
(Date newDay:365 year:2005) dayInYear |
5548 | 2203 |
" |
2204 |
! |
|
2205 |
||
77 | 2206 |
dayOfMonth |
2207 |
"Answer the day of the month represented by me. |
|
2208 |
Same as day; for ST-80 compatibility." |
|
2209 |
||
2210 |
^ self day |
|
92 | 2211 |
|
2212 |
" |
|
2213 |
Date today dayOfMonth |
|
2214 |
" |
|
2215 |
! |
|
2216 |
||
2217 |
daysInMonth |
|
2218 |
"return the number of days in the month of the receiver" |
|
2219 |
||
2220 |
^ Date daysInMonth:(self month) forYear:(self year) |
|
2221 |
||
2222 |
" |
|
2223 |
Date today daysInMonth |
|
2224 |
" |
|
2225 |
! |
|
2226 |
||
2227 |
daysInYear |
|
2228 |
"return the number of days in the year of the receiver" |
|
2229 |
||
2230 |
^ Date daysInYear:(self year) |
|
2231 |
||
2232 |
" |
|
2233 |
Date today daysInYear |
|
2234 |
" |
|
2235 |
! |
|
2236 |
||
5778 | 2237 |
daysLeftInMonth |
2238 |
"return the number of days left in the month of the receiver" |
|
2239 |
||
2240 |
^ self daysInMonth - self day |
|
2241 |
||
2242 |
" |
|
2243 |
Date today daysLeftInMonth |
|
2244 |
" |
|
2245 |
! |
|
2246 |
||
92 | 2247 |
daysLeftInYear |
11079
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2248 |
"return the number of days left in the year of the receiver. |
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2249 |
Today is excluded from the count (i.e. in a non-leap-year, |
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2250 |
the first january will return 364)" |
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2251 |
|
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2252 |
^ (Date daysInYear:(self year)) - self dayOfYear |
92 | 2253 |
|
2254 |
" |
|
5282 | 2255 |
Date today daysLeftInYear |
92 | 2256 |
" |
77 | 2257 |
! |
2258 |
||
17815 | 2259 |
isLeapYear |
699 | 2260 |
"return true, if the receivers year is a leap year" |
68 | 2261 |
|
699 | 2262 |
^ Date leapYear:(self year) |
68 | 2263 |
|
92 | 2264 |
" |
17815 | 2265 |
Date today isLeapYear |
2266 |
(Date newDay:1 month:1 year:1992) isLeapYear |
|
92 | 2267 |
" |
68 | 2268 |
! |
2269 |
||
699 | 2270 |
month |
2271 |
"return the month (1..12) of the receiver" |
|
92 | 2272 |
|
699 | 2273 |
^ (dateEncoding // 100) \\ 100 |
68 | 2274 |
|
92 | 2275 |
" |
699 | 2276 |
Date today month |
92 | 2277 |
" |
68 | 2278 |
! |
2279 |
||
77 | 2280 |
monthIndex |
2281 |
"return the index of the month (e.g. Feb.=2). |
|
2282 |
Same as month; for ST-80 compatibility." |
|
2283 |
||
2284 |
^ self month |
|
2285 |
! |
|
2286 |
||
68 | 2287 |
monthName |
2288 |
"return the month of the receiver as a string. |
|
2289 |
The returned string depends on the language setting. |
|
2290 |
Expect things like 'january', 'february' ..." |
|
2291 |
||
2292 |
^ self class nameOfMonth:(self month) |
|
2293 |
||
92 | 2294 |
" |
2295 |
Date today monthName |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2296 |
(Date newDay:15 month:4 year:1959) monthName |
92 | 2297 |
" |
68 | 2298 |
! |
2299 |
||
7961 | 2300 |
monthNameForLanguage:languageOrNil |
2301 |
"return the month of the receiver as a string. |
|
2302 |
The returned string depends on the language setting. |
|
2303 |
Expect things like 'january', 'february' ..." |
|
2304 |
||
2305 |
^ self class nameOfMonth:(self month) language:languageOrNil |
|
2306 |
||
2307 |
" |
|
2308 |
Date today monthName |
|
2309 |
Date today monthNameForLanguage:#en |
|
2310 |
" |
|
2311 |
! |
|
2312 |
||
5548 | 2313 |
weekInYear |
2314 |
"return the week number of the receiver - 1 for Jan, 1st. |
|
2315 |
each week is Mon .. Sun (i.e. Sunday belongs to the previous week)" |
|
2316 |
||
2317 |
^ self class weekInYearOf:self |
|
2318 |
||
2319 |
" |
|
2320 |
Date today weekInYear |
|
2321 |
(Date newDay:1 year:2000) weekInYear was a saturday |
|
2322 |
(Date newDay:2 year:2000) weekInYear was a sunday |
|
2323 |
(Date newDay:3 year:2000) weekInYear was a monday |
|
2324 |
(Date newDay:4 year:2000) weekInYear was a tuesday |
|
2325 |
(Date newDay:5 year:2000) weekInYear was a wed |
|
2326 |
(Date newDay:6 year:2000) weekInYear was a thursday |
|
2327 |
(Date newDay:7 year:2000) weekInYear was a fri |
|
2328 |
(Date newDay:8 year:2000) weekInYear was a sat |
|
2329 |
(Date newDay:9 year:2000) weekInYear was a sun |
|
2330 |
(Date newDay:10 year:2000) weekInYear was a monday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2331 |
(Date newDay:3 month:1 year:2001) weekInYear |
5548 | 2332 |
" |
2333 |
! |
|
2334 |
||
699 | 2335 |
weekday |
2336 |
"return the week-day of the receiver as a string. |
|
68 | 2337 |
The returned string depends on the language setting. |
699 | 2338 |
Expect things like 'monday', 'tuesday' ... |
2339 |
For ST-80 compatibility" |
|
2340 |
||
2341 |
^ self class nameOfDay:(self dayInWeek) |
|
2342 |
||
2343 |
" |
|
2344 |
Date today weekday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2345 |
(Date newDay:15 month:4 year:1959) weekday |
699 | 2346 |
" |
2347 |
! |
|
2348 |
||
2349 |
year |
|
2350 |
"return the year (1..12) of the receiver" |
|
2351 |
||
2352 |
^ dateEncoding // (100*100) |
|
68 | 2353 |
|
699 | 2354 |
" |
2355 |
Date today year |
|
2356 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2357 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2358 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2359 |
year:year month:month day:day |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2360 |
dateEncoding := self class encodeYear:year month:month day:day |
699 | 2361 |
! ! |
2362 |
||
2363 |
!Date methodsFor:'arithmetic'! |
|
2364 |
||
8201 | 2365 |
+ days |
2366 |
"return a new date representing 'days' after the receiver. |
|
2367 |
The argument should be some kind of integer. |
|
2368 |
This is the same as #addDays." |
|
2369 |
||
2370 |
^ self class fromDays:(self asDays + days) |
|
2371 |
||
2372 |
" |
|
2373 |
Date today + 7. |
|
2374 |
||
2375 |
Date today to:(Date today + 28) by:7 do:[:date| |
|
2376 |
Transcript show:date weekday; show:', '; showCr:date |
|
2377 |
]. |
|
2378 |
" |
|
2379 |
! |
|
2380 |
||
2381 |
- aDateOrNumberOfDays |
|
2382 |
"return the delta in days (anInteger) between 2 dates or |
|
2383 |
subtract a number of days from a date returning a Date" |
|
2384 |
||
2385 |
aDateOrNumberOfDays class == self class ifTrue:[ |
|
2386 |
^ self asDays - aDateOrNumberOfDays asDays |
|
2387 |
]. |
|
2388 |
||
2389 |
^ self class fromDays:(self asDays - aDateOrNumberOfDays asInteger) |
|
2390 |
||
2391 |
" |
|
2392 |
Date today - Date yesterday |
|
2393 |
Date today - 3 |
|
2394 |
" |
|
2395 |
! |
|
2396 |
||
699 | 2397 |
addDays:days |
2398 |
"return a new date representing 'days' after the receiver. |
|
2399 |
The argument should be some kind of integer. |
|
2400 |
For ST-80 compatibility." |
|
2401 |
||
2402 |
^ self class fromDays:(self asDays + days) |
|
2403 |
||
2404 |
" |
|
2405 |
Date today addDays:7 |
|
2406 |
" |
|
2407 |
! |
|
2408 |
||
9262 | 2409 |
daysSince:aDate |
2410 |
"return the number of days between the receiver and the argument, |
|
2411 |
aDate, which should be some kind of date" |
|
2412 |
||
2413 |
^ self asDays - aDate asDays |
|
2414 |
||
2415 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2416 |
Date today daysSince:(Date newDay:1 month:1 year:1901) |
9262 | 2417 |
" |
2418 |
! |
|
2419 |
||
699 | 2420 |
daysUntil:aDate |
2421 |
"return the number of days between the receiver and the argument, |
|
8201 | 2422 |
aDate, which should be some kind of date" |
699 | 2423 |
|
2424 |
^ aDate asDays - self asDays |
|
68 | 2425 |
|
92 | 2426 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2427 |
(Date newDay:24 month:12 year:1994) daysUntil:(Date day:1 month:1 year:1995) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2428 |
(Date newDay:1 month:2 year:1992) daysUntil:(Date day:1 month:3 year:1992) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2429 |
(Date newDay:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994) |
699 | 2430 |
|
2431 |
|delta| |
|
2432 |
delta := Date today |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2433 |
daysUntil:(Date newDay:25 month:12 year:Date today year). |
699 | 2434 |
Transcript show:'still '; |
8201 | 2435 |
show:delta ; |
2436 |
showCR:' days till xmas' |
|
699 | 2437 |
" |
2438 |
! |
|
2439 |
||
11741 | 2440 |
firstDayInPreviousMonth:nMonths |
11742
09f7e7b1c93b
changed #firstDayInPreviousMonth:
Claus Gittinger <cg@exept.de>
parents:
11741
diff
changeset
|
2441 |
"Return the first day of a previous month (0=this month, 1=prev. month, etc.)" |
11741 | 2442 |
|
2443 |
|month year| |
|
2444 |
||
2445 |
month := self month. |
|
2446 |
year := self year. |
|
2447 |
month := month - nMonths. |
|
2448 |
month < 1 ifTrue:[ |
|
2449 |
year := year - 1 - (month negated // 12). |
|
2450 |
month := (12 - (month negated \\ 12)). |
|
2451 |
]. |
|
2452 |
||
2453 |
^ Date newDay:1 month:month year:year. |
|
2454 |
||
2455 |
" |
|
2456 |
(Date newDay:3 month:6 year:2009) firstDayInMonth |
|
2457 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:0 |
|
2458 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:5 |
|
2459 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:6 |
|
2460 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:7 |
|
2461 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:17 |
|
2462 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:18 |
|
2463 |
" |
|
2464 |
! |
|
2465 |
||
2466 |
firstDayOfPreviousMonth:nMonths |
|
2467 |
"Return the first day of a previous month (0=this month)" |
|
2468 |
||
2469 |
|month year| |
|
2470 |
||
2471 |
month := self month. |
|
2472 |
year := self year. |
|
2473 |
month := month - nMonths. |
|
2474 |
month < 1 ifTrue:[ |
|
2475 |
year := year - 1 - (month negated // 12). |
|
2476 |
month := (12 - (month negated \\ 12)). |
|
2477 |
]. |
|
2478 |
||
2479 |
^ Date newDay:1 month:month year:year. |
|
2480 |
||
2481 |
" |
|
2482 |
(Date newDay:3 month:6 year:2009) firstDayInMonth |
|
2483 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:0 |
|
2484 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:5 |
|
2485 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:6 |
|
2486 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:7 |
|
2487 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:17 |
|
2488 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:18 |
|
2489 |
" |
|
2490 |
! |
|
2491 |
||
699 | 2492 |
subtractDate:aDate |
2493 |
"return the number of days between the receiver and aDate" |
|
2494 |
||
2495 |
^ self asDays - aDate asDays |
|
2496 |
||
2497 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2498 |
(Date newDay:1 month:1 year:1995) subtractDate:(Date newDay:24 month:12 year:1994) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2499 |
(Date newDay:1 month:3 year:1992) subtractDate:(Date newDay:1 month:2 year:1992) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2500 |
(Date newDay:1 month:3 year:1994) subtractDate:(Date newDay:1 month:2 year:1994) |
699 | 2501 |
" |
2502 |
! |
|
2503 |
||
2504 |
subtractDays:days |
|
2505 |
"return a new date representing 'days' before the receiver. |
|
2506 |
The argument should be some kind of integer. |
|
2507 |
For ST-80 compatibility" |
|
2508 |
||
2509 |
^ self class fromDays:(self asDays - days) |
|
2510 |
||
2511 |
" |
|
2512 |
Date today subtractDays:7 |
|
92 | 2513 |
" |
1 | 2514 |
! ! |
2515 |
||
2516 |
!Date methodsFor:'comparing'! |
|
2517 |
||
29 | 2518 |
< aDate |
2519 |
"return true, if the date represented by the receiver |
|
2520 |
is before the argument, aDate" |
|
2521 |
||
54 | 2522 |
(aDate isMemberOf:Date) ifTrue:[ |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2523 |
^ dateEncoding < aDate dateEncoding |
54 | 2524 |
]. |
29 | 2525 |
|
54 | 2526 |
"the argument must understand year, month and day to be |
2527 |
comparable, whatever it is" |
|
2528 |
||
17757 | 2529 |
^ dateEncoding < (Date encodeYear:aDate year month:aDate month day:aDate day) |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2530 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2531 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2532 |
Date today < (Date day:24 month:12 year:2000) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2533 |
Date today < (Date day:24 month:12 year:1900) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2534 |
Date today < Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2535 |
Date today-1 < Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2536 |
" |
29 | 2537 |
! |
1 | 2538 |
|
2539 |
= aDate |
|
2540 |
"return true, if the date represented by the receiver |
|
2541 |
is the same as the one represented by argument, aDate" |
|
2542 |
||
155 | 2543 |
(aDate isMemberOf:Date) ifFalse:[^ false]. |
2544 |
||
2545 |
^ dateEncoding = aDate dateEncoding |
|
54 | 2546 |
|
2547 |
"the argument must understand year, month and day to be |
|
2548 |
comparable, whatever it is" |
|
2549 |
||
155 | 2550 |
" |
54 | 2551 |
^ dateEncoding = (Date encodeYear:aDate year |
155 | 2552 |
month:aDate month |
2553 |
day:aDate day) |
|
2554 |
" |
|
68 | 2555 |
"Date today = ((Date today plusDays:7) minusDays:7)" |
92 | 2556 |
! |
2557 |
||
699 | 2558 |
> aDate |
2559 |
"return true, if the date represented by the receiver |
|
2560 |
is after the argument, aDate" |
|
2561 |
||
2562 |
(aDate isMemberOf:Date) ifTrue:[ |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2563 |
^ dateEncoding > aDate dateEncoding |
699 | 2564 |
]. |
2565 |
||
2566 |
"the argument must understand year, month and day to be |
|
2567 |
comparable, whatever it is" |
|
2568 |
||
17757 | 2569 |
^ dateEncoding > (Date encodeYear:aDate year month:aDate month day:aDate day) |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2570 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2571 |
" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2572 |
Date today > (Date newDay:24 month:12 year:2099) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2573 |
Date today > (Date newDay:24 month:12 year:1900) |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2574 |
Date today > Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2575 |
Date today+1 > Timestamp now |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2576 |
" |
699 | 2577 |
! |
2578 |
||
92 | 2579 |
hash |
2580 |
"return an integer useful for hashing on dates" |
|
2581 |
||
2582 |
^ dateEncoding |
|
1 | 2583 |
! ! |
2584 |
||
1501 | 2585 |
!Date methodsFor:'converting'! |
2586 |
||
4408 | 2587 |
asDate |
2588 |
"return the receiver" |
|
2589 |
||
2590 |
^ self |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2591 |
! |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2592 |
|
17815 | 2593 |
asLocalTimestamp |
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2594 |
"return an TimeStamp instance, representing midnight of last night" |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2595 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2596 |
^ Timestamp |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2597 |
year:(self year) month:(self month) day:(self day) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2598 |
hour:0 minute:0 second:0 millisecond:0 |
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2599 |
|
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2600 |
" |
17815 | 2601 |
Date today asLocalTimestamp |
2602 |
" |
|
2603 |
! |
|
2604 |
||
2605 |
asTimestamp |
|
2606 |
"return an TimeStamp instance, representing midnight of last night" |
|
2607 |
||
2608 |
^ self asLocalTimestamp |
|
2609 |
||
2610 |
" |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2611 |
Date today asTimestamp |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2612 |
" |
17815 | 2613 |
! |
2614 |
||
2615 |
asUtcTimestamp |
|
2616 |
"return an TimeStamp instance, representing midnight of last night" |
|
2617 |
||
2618 |
^ UtcTimestamp |
|
2619 |
year:(self year) month:(self month) day:(self day) |
|
2620 |
hour:0 minute:0 second:0 millisecond:0 |
|
2621 |
||
2622 |
" |
|
2623 |
Date today asUtcTimestamp |
|
2624 |
" |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
2625 |
! ! |
1501 | 2626 |
|
8201 | 2627 |
!Date methodsFor:'obsolete'! |
2628 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2629 |
asAbsoluteTime |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2630 |
"deprecated, use #asTimestamp" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2631 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2632 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2633 |
self obsoleteMethodWarning:'use #asTimestamp'. |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2634 |
^ self asTimestamp |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2635 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2636 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2637 |
dayCount |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2638 |
"return the number of days since 1st. Jan. 1901; |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2639 |
starting with 0 for this date. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2640 |
Date>>fromDays: is the reverse operation. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2641 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2642 |
please use asDays for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2643 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2644 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2645 |
^ self asDays. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2646 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2647 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2648 |
dayName |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2649 |
"return the week-day of the receiver as a string. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2650 |
The returned string depends on the language setting. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2651 |
Expect things like 'monday', 'tuesday' ... |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2652 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2653 |
use #weekday for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2654 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2655 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2656 |
^ self weekday |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2657 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2658 |
|
17815 | 2659 |
leap |
2660 |
"return true, if the receivers year is a leap year" |
|
2661 |
<resource: #obsolete> |
|
2662 |
||
2663 |
^ self isLeapYear |
|
2664 |
||
2665 |
" |
|
2666 |
Date today leap |
|
2667 |
(Date newDay:1 month:1 year:1992) leap |
|
2668 |
" |
|
2669 |
! |
|
2670 |
||
8201 | 2671 |
minusDays:days |
2672 |
"return a new date representing 'days' before the receiver. |
|
2673 |
The argument should be some kind of integer. |
|
2674 |
Obsolete: |
|
2675 |
Please dont use this method since it will vanish. |
|
2676 |
Use #subtractDays: instead for ST-80 compatibility." |
|
2677 |
||
2678 |
<resource: #obsolete> |
|
2679 |
||
2680 |
self obsoleteMethodWarning:'use #substractDays:'. |
|
2681 |
^ self subtractDays:days |
|
2682 |
! |
|
2683 |
||
2684 |
plusDays:days |
|
2685 |
"return a new date representing 'days' after the receiver. |
|
2686 |
The argument should be some kind of integer. |
|
2687 |
Obsolete: |
|
2688 |
Please dont use this method since it will vanish. |
|
2689 |
Use #addDays: instead for ST-80 compatibility." |
|
2690 |
||
2691 |
<resource: #obsolete> |
|
2692 |
||
2693 |
self obsoleteMethodWarning:'use #addDays:'. |
|
2694 |
^ self addDays:days |
|
2695 |
! ! |
|
2696 |
||
54 | 2697 |
!Date methodsFor:'printing & storing'! |
1 | 2698 |
|
5778 | 2699 |
addPrintBindingsTo:aDictionary |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2700 |
self addPrintBindingsTo:aDictionary language:nil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2701 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2702 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2703 |
addPrintBindingsTo:aDictionary language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2704 |
"private print support: add bindings for printing to aDictionary. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2705 |
languageOrNil can only be #en or nil for the current language. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2706 |
valid format items are: |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2707 |
%d - day, 01..31 0-padded to length 2 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2708 |
%m - month, 01..12 0-padded to length 2 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2709 |
%w - week in year, 00..53 0-padded to length 2 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2710 |
%y - year, full i.e. 1999, 2004 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2711 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2712 |
special: |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2713 |
%D - day - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2714 |
%M - month - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2715 |
%W - week in year - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2716 |
%Y - year, last 2 digits only i.e. 99, 04 (danger: year 2k bug) |
5778 | 2717 |
|
17815 | 2718 |
%(weekDay) - day in week (1->monday, 2->tuesday, ... ,7->sunday) |
2719 |
||
2720 |
%(dayName) - full day name |
|
2721 |
%(DayName) - full day name, first character uppercase |
|
2722 |
%(DAYNAME) - full day name, all uppercase |
|
2723 |
||
2724 |
%(monthName) - full month name |
|
2725 |
%(MonthName) - full month name, first character uppercase |
|
2726 |
%(MONTHNAME) - full month name, all uppercase |
|
2727 |
||
2728 |
%(shortDayName) - short (abbreviated) day name |
|
2729 |
%(ShortDayName) - short (abbreviated) day name, first character uppercase |
|
2730 |
%(SHORTDAYNAME) - short (abbreviated) day name, all uppercase |
|
2731 |
||
2732 |
%(shortMonthName) - short (abbreviated) month name |
|
2733 |
%(ShortMonthName) - short (abbreviated) month name, first character uppercase |
|
2734 |
%(SHORTMONTHNAME) - short (abbreviated) month name, all uppercase |
|
2735 |
||
2736 |
%(nth) - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
2737 |
%(weekDayNth) - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
|
2738 |
%(weekNth) - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')" |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2739 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2740 |
|day ds dsPadded0 dsPaddedB month ms msPadded0 msPaddedB |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2741 |
year weekInYear monthName shortMonthName |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2742 |
dayInWeek dayOfWeek dayName shortDayName ws wsPadded0| |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2743 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2744 |
day := self day. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2745 |
ds := day printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2746 |
dsPaddedB := day printStringLeftPaddedTo:2. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2747 |
dsPadded0 := day printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2748 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2749 |
month := self month. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2750 |
ms := month printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2751 |
msPaddedB := month printStringLeftPaddedTo:2. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2752 |
msPadded0 := month printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2753 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2754 |
year := self year. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2755 |
weekInYear := self weekInYear. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2756 |
ws := weekInYear printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2757 |
wsPadded0 := weekInYear printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2758 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2759 |
dayInWeek := self dayInWeek. "/ 1 .. 7 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2760 |
dayOfWeek := self dayOfWeek. "/ 0 .. 6 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2761 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2762 |
monthName := self class nameOfMonth:(self month) language:languageOrNil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2763 |
dayName := self class nameOfDay:dayInWeek language:languageOrNil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2764 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2765 |
aDictionary at:#day put:dsPadded0. "/ 0-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2766 |
aDictionary at:#daypadded put:dsPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2767 |
aDictionary at:#dayPadded put:dsPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2768 |
aDictionary at:#Day put:ds. "/ unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2769 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2770 |
aDictionary at:#month put:msPadded0. "/ 0-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2771 |
aDictionary at:#monthPadded put:msPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2772 |
aDictionary at:#monthpadded put:msPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2773 |
aDictionary at:#Month put:ms. "/ unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2774 |
aDictionary at:#mon put:msPadded0. "/ 0-padded - for backward compatibility only |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2775 |
aDictionary at:#Mon put:ms. "/ unpadded - for backward compatibility only |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2776 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2777 |
aDictionary at:#year put:year. "/ padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2778 |
aDictionary at:#week put:wsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2779 |
aDictionary at:#Week put:ws. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2780 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2781 |
year ~~ Date today year ifTrue:[ |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2782 |
aDictionary at:#yearOrTime put:(' ' , year printString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2783 |
]. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2784 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2785 |
aDictionary at:$d put:dsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2786 |
aDictionary at:$D put:ds. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2787 |
aDictionary at:$m put:msPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2788 |
aDictionary at:$M put:ms. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2789 |
aDictionary at:$y put:year. |
17747 | 2790 |
aDictionary at:$Y put:((year \\ 100) printStringLeftPaddedTo:2 with:$0). |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2791 |
aDictionary at:$w put:wsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2792 |
aDictionary at:$W put:ws. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2793 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2794 |
aDictionary at:#monthName put:monthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2795 |
aDictionary at:#monthname put:monthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2796 |
aDictionary at:#MonthName put:monthName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2797 |
aDictionary at:#MONTHNAME put:monthName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2798 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2799 |
aDictionary at:#dayName put:dayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2800 |
aDictionary at:#dayname put:dayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2801 |
aDictionary at:#DayName put:dayName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2802 |
aDictionary at:#DAYNAME put:dayName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2803 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2804 |
aDictionary at:#weekDay put:dayInWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2805 |
aDictionary at:#weekday put:dayInWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2806 |
aDictionary at:#weekDayUS put:dayOfWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2807 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2808 |
aDictionary at:#shortDayName put:(shortDayName := self class abbreviatedNameOfDay:(self dayInWeek) language:languageOrNil). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2809 |
aDictionary at:#shortdayname put:shortDayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2810 |
aDictionary at:#ShortDayName put:shortDayName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2811 |
aDictionary at:#SHORTDAYNAME put:shortDayName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2812 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2813 |
aDictionary at:#shortMonthName put:(shortMonthName := self class abbreviatedNameOfMonth:(self month) language:languageOrNil). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2814 |
aDictionary at:#shortmonthname put:shortMonthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2815 |
aDictionary at:#ShortMonthName put:shortMonthName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2816 |
aDictionary at:#SHORTMONTHNAME put:shortMonthName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2817 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2818 |
aDictionary at:#nth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:day \\ 10 + 1). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2819 |
"/ 0 1 2 3 4 5 6 7 8 9 |
17815 | 2820 |
aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:(dayOfWeek-1) \\ 10 + 1). |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2821 |
"/ 0 1 2 3 4 5 6 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2822 |
aDictionary at:#weekNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th' 'th' 'th' 'th') at:weekInYear \\ 10 + 1). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2823 |
"/ 0 1 2 3 4 5 6 7 8 9 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2824 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2825 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2826 |
printOn:aStream |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2827 |
"append a printed representation of the receiver to aStream" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2828 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2829 |
self printOn:aStream format:(self class defaultFormatString) language:nil. |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2830 |
|
5778 | 2831 |
" |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2832 |
Date today printOn:Transcript. Transcript cr. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2833 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2834 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2835 |
"Modified: 27.8.1995 / 01:01:49 / claus" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2836 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2837 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2838 |
printOn:aStream format:aFormatStringOrSqueakFormatArray |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2839 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2840 |
see #addPrintBindingsTo: for a list of valid format strings" |
5778 | 2841 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2842 |
self printOn:aStream format:aFormatStringOrSqueakFormatArray language:nil. |
5778 | 2843 |
|
2844 |
" |
|
2845 |
Date today printOn:Transcript format:'%y%m%d' (iso format) |
|
2846 |
Date today printOn:Transcript format:'%y-%m-%d' (iso format) |
|
2847 |
Date today printOn:Transcript format:'%y-W%w' (iso format - working week) |
|
2848 |
Date today printOn:Transcript format:'%d-%m-%y' (european trivia format) |
|
2849 |
Date today printOn:Transcript format:'%m/%d/%y' (us trivia format) |
|
2850 |
Date today printOn:Transcript format:'%D-%(monthName)-%y' (us trivia format) |
|
2851 |
Date today printOn:Transcript format:'%D-%(MonthName)-%y' (us trivia format) |
|
2852 |
Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
2853 |
Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
2854 |
Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
2855 |
Date today printOn:Transcript format:'%d%m%Y' (millenium bug format - danger) |
|
2856 |
Date today printOn:Transcript format:'Today is the %(weekDay) day of the week' |
|
2857 |
" |
|
7023 | 2858 |
" |
2859 |
String streamContents:[:s | |
|
2860 |
Date today printOn:s format:#(1 2 3 $/ 1 2) |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2861 |
] |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2862 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2863 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2864 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2865 |
printOn:aStream format:aFormatStringOrSqueakFormatArray language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2866 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2867 |
languageOrNil can only be #en or nil for the current language. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2868 |
see #addPrintBindingsTo: for a list of valid format strings" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2869 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2870 |
|dict| |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2871 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2872 |
aFormatStringOrSqueakFormatArray isArray ifTrue:[ |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2873 |
"backward compatibility: a squeak/st80 format array" |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2874 |
self printFormat:aFormatStringOrSqueakFormatArray on:aStream. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2875 |
^ self. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2876 |
]. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2877 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2878 |
dict := IdentityDictionary new. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2879 |
self addPrintBindingsTo:dict language:languageOrNil. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2880 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2881 |
aFormatStringOrSqueakFormatArray expandPlaceholdersWith:dict on:aStream |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2882 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2883 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2884 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2885 |
Date today |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2886 |
printOn:Transcript |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2887 |
format:'%y%m%d' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2888 |
language:#en |
7023 | 2889 |
" |
5778 | 2890 |
! |
2891 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2892 |
printOn:aStream language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2893 |
"append a printed representation of the receiver to aStream. |
8179 | 2894 |
The argument languageOrNil can only be #en or nil for the current language." |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2895 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2896 |
|format| |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2897 |
|
8118 | 2898 |
(DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[ |
8145 | 2899 |
self class initNames |
8118 | 2900 |
]. |
8179 | 2901 |
format := DefaultFormats at:(languageOrNil ? Language) ifAbsent:[DefaultFormats at:#en]. |
2902 |
self printOn:aStream format:format language:languageOrNil. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2903 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2904 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2905 |
Date today printOn:Transcript language:#en |
17815 | 2906 |
Date today printOn:Transcript language:#de |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2907 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2908 |
|
8179 | 2909 |
"Modified: / 27-08-1995 / 01:01:49 / claus" |
2910 |
"Modified: / 12-03-2004 / 19:23:54 / cg" |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2911 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2912 |
|
7023 | 2913 |
printStringFormat:aFormatStringOrArray |
5778 | 2914 |
"print using a format string; |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2915 |
see #addPrintBindingsTo: for a list of valid format strings" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2916 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2917 |
^ self printStringFormat:aFormatStringOrArray language:nil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2918 |
|
5778 | 2919 |
" |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2920 |
Date today printStringFormat:'%y%m%d' (iso format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2921 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2922 |
Date today printStringFormat:'%y-W%w' (iso format - working week) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2923 |
Date today printStringFormat:'%d-%m-%y' (european trivia format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2924 |
Date today printStringFormat:'%m/%d/%y' (us trivia format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2925 |
Date today printStringFormat:'%D-%(monthName)-%y' (us trivia format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2926 |
Date today printStringFormat:'%D-%(MonthName)-%y' (us trivia format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2927 |
Date today printStringFormat:'%D-%(MONTHNAME)-%y' (us trivia format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2928 |
Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2929 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2930 |
Date today printStringFormat:'%d%m%Y' (millenium bug format - danger) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2931 |
Date today printStringFormat:'Today is day %(weekDay) of the week' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2932 |
Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2933 |
Date today printStringFormat:'Today is the %(Day)%(nth) day of the month' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2934 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2935 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2936 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2937 |
printStringFormat:aFormatStringOrArray language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2938 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2939 |
languageOrNil can only be #en or nil for the current language. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2940 |
see #addPrintBindingsTo: for a list of valid format strings" |
5778 | 2941 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2942 |
|s| |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2943 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2944 |
s := WriteStream on:(String new:20). |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2945 |
self printOn:s format:aFormatStringOrArray language:languageOrNil. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2946 |
^ s contents. |
5778 | 2947 |
|
2948 |
" |
|
2949 |
Date today printStringFormat:'%y%m%d' (iso format) |
|
2950 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
|
2951 |
Date today printStringFormat:'%y-W%w' (iso format - working week) |
|
2952 |
Date today printStringFormat:'%d-%m-%y' (european trivia format) |
|
2953 |
Date today printStringFormat:'%m/%d/%y' (us trivia format) |
|
2954 |
Date today printStringFormat:'%D-%(monthName)-%y' (us trivia format) |
|
2955 |
Date today printStringFormat:'%D-%(MonthName)-%y' (us trivia format) |
|
2956 |
Date today printStringFormat:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
2957 |
Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
2958 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
2959 |
Date today printStringFormat:'%d%m%Y' (millenium bug format - danger) |
|
7327 | 2960 |
Date today printStringFormat:'Today is day %(weekDay) of the week' |
2961 |
Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week' |
|
2962 |
Date today printStringFormat:'Today is the %(Day)%(nth) day of the month' |
|
5778 | 2963 |
" |
2964 |
! |
|
2965 |
||
699 | 2966 |
storeOn:aStream |
2967 |
"append a representation to aStream, from which the receiver |
|
2968 |
can be reconstructed" |
|
2969 |
||
2970 |
aStream nextPutAll:'('; nextPutAll:'Date day:'. |
|
2971 |
self day printOn:aStream. |
|
2972 |
aStream nextPutAll:' month:'. |
|
2973 |
self month printOn:aStream. |
|
2974 |
aStream nextPutAll:' year:'. |
|
2975 |
self year printOn:aStream. |
|
2976 |
aStream nextPutAll:')' |
|
2977 |
||
2978 |
" |
|
2979 |
Date today storeOn:Transcript |
|
2980 |
Date today storeString |
|
2981 |
" |
|
1 | 2982 |
! ! |
699 | 2983 |
|
7258 | 2984 |
!Date methodsFor:'private-accessing'! |
699 | 2985 |
|
2986 |
dateEncoding |
|
2987 |
"the internal encoding is stricktly private, |
|
2988 |
and should not be used outside." |
|
2989 |
||
2990 |
^ dateEncoding |
|
2991 |
! |
|
2992 |
||
2993 |
dateEncoding:anInteger |
|
2994 |
"the internal encoding is stricktly private, |
|
2995 |
and should not be used outside." |
|
2996 |
||
2997 |
dateEncoding := anInteger |
|
2998 |
! |
|
2999 |
||
3000 |
fromOSTime:osTime |
|
17815 | 3001 |
"set my dateEncoding as date in the local timezone from an OS time. |
699 | 3002 |
This somewhat clumsy implementation hides the OS's date representation |
3003 |
(i.e. makes this class independent of what the OS starts its time values with). |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3004 |
Don't use this method, the osTime representation is totally unportable." |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3005 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3006 |
|v| |
5858 | 3007 |
|
3008 |
v := OperatingSystem computeTimeAndDateFrom:osTime. |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3009 |
dateEncoding := self class encodeYear:v year month:v month day:v day |
1501 | 3010 |
|
3011 |
"Modified: 1.7.1996 / 15:23:12 / cg" |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3012 |
! |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3013 |
|
17815 | 3014 |
fromUtcOSTime:osTime |
3015 |
"set my dateEncoding as UTC date from an OS time. |
|
3016 |
This somewhat clumsy implementation hides the OS's date representation |
|
3017 |
(i.e. makes this class independent of what the OS starts its time values with). |
|
3018 |
Don't use this method, the osTime representation is totally unportable." |
|
3019 |
||
3020 |
|v| |
|
3021 |
||
3022 |
v := OperatingSystem computeUTCTimeAndDateFrom:osTime. |
|
3023 |
dateEncoding := self class encodeYear:v year month:v month day:v day |
|
3024 |
||
3025 |
"Modified: 1.7.1996 / 15:23:12 / cg" |
|
3026 |
! |
|
3027 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3028 |
getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3029 |
"compatibility with Timestamp for comparing" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3030 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3031 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3032 |
((Timestamp epoch addDays:365) asDate asDays - 365) -> 25202 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3033 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3034 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3035 |
^ 1000 * 60*60*24 * (self asDays - 25202) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3036 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3037 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3038 |
Date today asTimestamp getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3039 |
- |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3040 |
Date today getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3041 |
" |
699 | 3042 |
! ! |
3043 |
||
11176 | 3044 |
!Date methodsFor:'visiting'! |
3045 |
||
3046 |
acceptVisitor:aVisitor with:aParameter |
|
3047 |
||
3048 |
^ aVisitor visitDate:self with:aParameter |
|
3049 |
! ! |
|
3050 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
3051 |
!Date class methodsFor:'documentation'! |
699 | 3052 |
|
3053 |
version |
|
17815 | 3054 |
^ '$Id: Date.st 10604 2011-02-04 23:09:23Z vranyj1 $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
3055 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
3056 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
3057 |
version_CVS |
17815 | 3058 |
^ 'Header: /cvs/stx/stx/libbasic/Date.st,v 1.138 2011/01/24 19:56:01 stefan Exp ' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
3059 |
! |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
3060 |
|
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
3061 |
version_SVN |
17815 | 3062 |
^ '$Id: Date.st 10604 2011-02-04 23:09:23Z vranyj1 $' |
699 | 3063 |
! ! |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
3064 |
|
699 | 3065 |
Date initialize! |
17767 | 3066 |
|
17772
6e0b3c06c364
Method reverted to r10532
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17767
diff
changeset
|
3067 |
|
17780 | 3068 |
|
17807 | 3069 |
|
17814 | 3070 |
|
17815 | 3071 |