author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 12 Jul 2010 17:20:36 +0100 | |
branch | jv |
changeset 17780 | b6e42c92eba0 |
parent 17772 | 6e0b3c06c364 |
child 17807 | 06cc6c49e291 |
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 |
||
670 |
yesterday |
|
671 |
"return a date, representing yesterday. |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
672 |
See also: Time now / Timestamp now." |
5548 | 673 |
|
674 |
^ Date today subtractDays:1 |
|
675 |
||
676 |
" |
|
677 |
Date yesterday |
|
678 |
Date yesterday dayInWeek |
|
679 |
" |
|
699 | 680 |
! ! |
681 |
||
7299 | 682 |
!Date class methodsFor:'Compatibility-Dolphin'! |
6872 | 683 |
|
684 |
newDay:day monthIndex:month year:year |
|
685 |
^ self newDay:day month:month year:year |
|
686 |
||
687 |
" |
|
688 |
Date newDay:8 monthIndex:5 year:1993 |
|
689 |
" |
|
690 |
||
691 |
"Modified: 19.4.1996 / 15:28:15 / cg" |
|
692 |
! ! |
|
693 |
||
7646 | 694 |
!Date class methodsFor:'Compatibility-ST80'! |
695 |
||
7648 | 696 |
newDay:day monthNumber:monthIndex year:year |
7646 | 697 |
"ST80 compatibility" |
698 |
||
699 |
^ self newDay:day month:monthIndex year:year |
|
700 |
! ! |
|
701 |
||
7299 | 702 |
!Date class methodsFor:'Compatibility-Squeak'! |
7005 | 703 |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
704 |
current |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
705 |
"return the current date" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
706 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
707 |
^ self today |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
708 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
709 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
710 |
Date current |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
711 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
712 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
713 |
|
7005 | 714 |
fromSeconds:seconds |
715 |
"Answer an instance of me which is 'seconds' seconds after January 1, 1901." |
|
716 |
||
717 |
| secondsInDay | |
|
718 |
||
719 |
secondsInDay := 24 * 60 * 60. |
|
720 |
^self fromDays: seconds // secondsInDay |
|
721 |
||
722 |
" |
|
723 |
Date fromSeconds:0 |
|
724 |
Date fromSeconds:(24 * 60 * 60 * 365) |
|
725 |
" |
|
11181 | 726 |
! |
727 |
||
728 |
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock |
|
729 |
"return a new Date, reading a printed representation from aStream. |
|
730 |
Notice, that this is not the storeString format and |
|
731 |
is different from the format expected by readFrom:" |
|
732 |
||
733 |
^ [ |
|
11182 | 734 |
|str monthString month dayString day year yearString| |
11181 | 735 |
|
736 |
str := aStringOrStream readStream. |
|
11182 | 737 |
monthString := str next:2. |
738 |
dayString := str next:2. |
|
739 |
yearString := str next:4. |
|
740 |
||
741 |
day := Integer readFrom:dayString. |
|
742 |
month := Integer readFrom:monthString. |
|
743 |
year := Integer readFrom:yearString. |
|
11181 | 744 |
|
745 |
self newDay:day month:month year:year |
|
746 |
] on:Error do:exceptionBlock |
|
747 |
||
748 |
" |
|
749 |
Date readMMDDYYYYFrom:'10041999' onError:['wrong date'] |
|
750 |
Date readMMDDYYYYFrom:'100419' onError:['wrong date'] |
|
751 |
||
752 |
Date readMMDDYYYYFrom:'10040001' onError:['wrong date'] |
|
753 |
" |
|
754 |
||
755 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
756 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
757 |
! |
|
758 |
||
759 |
readYYYYMMDDFrom:aStringOrStream onError:exceptionBlock |
|
760 |
"return a new Date, reading a printed representation from aStream. |
|
761 |
Notice, that this is not the storeString format and |
|
762 |
is different from the format expected by readFrom:" |
|
763 |
||
764 |
^ [ |
|
11182 | 765 |
|str monthString month dayString day yearString year| |
11181 | 766 |
|
767 |
str := aStringOrStream readStream. |
|
11182 | 768 |
yearString := str next:4. |
769 |
monthString := str next:2. |
|
770 |
dayString := str next:2. |
|
771 |
||
772 |
day := Integer readFrom:dayString. |
|
773 |
month := Integer readFrom:monthString. |
|
774 |
year := Integer readFrom:yearString. |
|
11181 | 775 |
|
776 |
self newDay:day month:month year:year |
|
777 |
] on:Error do:exceptionBlock |
|
778 |
||
779 |
" |
|
780 |
Date readYYYYMMDDFrom:'19991004' onError:['wrong date'] |
|
11182 | 781 |
Date readYYYYMMDDFrom:'911004' onError:['wrong date'] |
11181 | 782 |
" |
7005 | 783 |
! ! |
784 |
||
11553 | 785 |
!Date class methodsFor:'change & update'! |
786 |
||
787 |
update:something with:aParameter from:changedObject |
|
788 |
((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[ |
|
789 |
"just remember change for next access" |
|
790 |
EnvironmentChange := true |
|
791 |
] |
|
792 |
||
793 |
"Created: 15.6.1996 / 15:19:25 / cg" |
|
794 |
! ! |
|
795 |
||
11127 | 796 |
!Date class methodsFor:'error handling'! |
797 |
||
798 |
conversionErrorSignal |
|
799 |
"return the signal used for conversion error handling" |
|
800 |
||
801 |
^ DateConversionError |
|
802 |
! ! |
|
803 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
804 |
!Date class methodsFor:'general queries'! |
699 | 805 |
|
806 |
abbreviatedNameOfDay:dayIndex |
|
807 |
"given a day index (1..7), return the abbreviated name |
|
808 |
of the day" |
|
809 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
810 |
^ self abbreviatedNameOfDay:dayIndex language:nil |
699 | 811 |
|
812 |
" |
|
813 |
Date abbreviatedNameOfDay:4 |
|
814 |
" |
|
815 |
! |
|
816 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
817 |
abbreviatedNameOfDay:dayIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
818 |
"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
|
819 |
of the day. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
820 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
821 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
822 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
823 |
^ (self dayAbbrevsForLanguage:lang) at:dayIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
824 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
825 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
826 |
Date abbreviatedNameOfDay:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
827 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
828 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
829 |
|
699 | 830 |
abbreviatedNameOfMonth:monthIndex |
831 |
"given a month index (1..12), return the abbreviated name |
|
832 |
of the month" |
|
833 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
834 |
^ self abbreviatedNameOfMonth:monthIndex language:nil |
699 | 835 |
|
836 |
" |
|
837 |
Date abbreviatedNameOfMonth:11 |
|
838 |
Date abbreviatedNameOfMonth:12 |
|
839 |
" |
|
840 |
! |
|
841 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
842 |
abbreviatedNameOfMonth:monthIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
843 |
"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
|
844 |
of the month. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
845 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
846 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
847 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
848 |
^ (self monthAbbrevsForLanguage:lang) at:monthIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
849 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
850 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
851 |
Date abbreviatedNameOfMonth:11 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
852 |
Date abbreviatedNameOfMonth:12 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
853 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
854 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
855 |
|
699 | 856 |
dateAndTimeNow |
857 |
"return an array containing the date and time of now" |
|
858 |
||
859 |
^ Time dateAndTimeNow |
|
860 |
||
861 |
" |
|
862 |
Date dateAndTimeNow |
|
863 |
" |
|
864 |
! |
|
865 |
||
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
866 |
dayOfFirstWeekInYear:aYear |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
867 |
"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
|
868 |
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
|
869 |
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
|
870 |
(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
|
871 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
872 |
|day dayInWeekOf1stJan firstThursday firstDayInWeek| |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
873 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
874 |
"/ find the first thursday ... |
11127 | 875 |
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
|
876 |
dayInWeekOf1stJan := day dayInWeek. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
877 |
dayInWeekOf1stJan > 4 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
878 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
879 |
] ifFalse:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
880 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
881 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
882 |
"/ back to the preceeding monday |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
883 |
firstDayInWeek := firstThursday subtractDays:3. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
884 |
^ firstDayInWeek |
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 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
887 |
Date dayOfFirstWeekInYear:1998 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
888 |
Date dayOfFirstWeekInYear:1999 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
889 |
Date dayOfFirstWeekInYear:2000 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
890 |
Date dayOfFirstWeekInYear:2001 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
891 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
892 |
! |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
893 |
|
699 | 894 |
dayOfWeek:dayName |
895 |
"given the name of a day (either string or symbol), |
|
896 |
return the day-index (1 for monday; 7 for sunday). |
|
897 |
Return 0 for invalid day name" |
|
898 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
899 |
|d| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
900 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
901 |
d := self dayOfWeek:dayName language:nil. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
902 |
d == 0 ifTrue:[ |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
903 |
d := self dayOfWeek:dayName language:'en'. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
904 |
]. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
905 |
^ d |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
906 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
907 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
908 |
Date dayOfWeek:'wednesday' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
909 |
Date dayOfWeek:'Wednesday' |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
910 |
Date dayOfWeek:'Mittwoch' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
911 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
912 |
! |
6976 | 913 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
914 |
dayOfWeek:dayName language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
915 |
"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
|
916 |
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
|
917 |
Return 0 for invalid day name. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
918 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
919 |
for unknown languages, english is used." |
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 |
|idx langDayNames| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
922 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
923 |
langDayNames := self dayNamesForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
924 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
925 |
idx := langDayNames indexOf:dayName. |
6976 | 926 |
idx == 0 ifTrue:[ |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
927 |
idx := langDayNames indexOf:dayName asLowercase. |
6976 | 928 |
]. |
929 |
^ idx |
|
699 | 930 |
|
931 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
932 |
Date dayOfWeek:'wednesday' language:'en' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
933 |
Date dayOfWeek:'Wednesday' language:'en' |
699 | 934 |
" |
935 |
! |
|
936 |
||
937 |
daysInMonth:month forYear:yearInteger |
|
938 |
"given the name of a month and a year, return the number |
|
939 |
of days this month has (modified GNU). |
|
940 |
return 0 if the month name was invalid. |
|
941 |
For your convenience, month maybe an integer or name-string." |
|
942 |
||
943 |
|monthIndex "{ Class: SmallInteger }"| |
|
944 |
||
945 |
month isInteger ifTrue:[ |
|
946 |
monthIndex := month |
|
947 |
] ifFalse:[ |
|
948 |
monthIndex := self indexOfMonth:month |
|
949 |
]. |
|
950 |
||
951 |
^ self daysInMonthIndex:monthIndex forYear:yearInteger |
|
952 |
||
953 |
" |
|
954 |
Date daysInMonth:2 forYear:1980 |
|
955 |
Date daysInMonth:2 forYear:1981 |
|
956 |
Date daysInMonth:'feb' forYear:1981 |
|
957 |
" |
|
958 |
! |
|
959 |
||
960 |
daysInYear:yearInteger |
|
961 |
"return the number of days in a year" |
|
962 |
||
963 |
(self leapYear:yearInteger) ifTrue:[^ 366]. |
|
964 |
^ 365 |
|
965 |
||
966 |
" |
|
967 |
Date daysInYear:1900 |
|
968 |
Date daysInYear:1901 |
|
969 |
Date daysInYear:1904 |
|
970 |
Date daysInYear:1980 |
|
971 |
Date daysInYear:1981 |
|
972 |
" |
|
973 |
! |
|
974 |
||
975 |
daysUntilMonth:month forYear:yearInteger |
|
976 |
"given the name of a month and a year, return the number |
|
977 |
of days from 1st january to last of prev month of that year. |
|
978 |
Return 0 if the month name/index is invalid or is january. |
|
979 |
For your convenience, month maybe an integer or name-string." |
|
980 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
981 |
|monthIndex| |
699 | 982 |
|
983 |
month isInteger ifTrue:[ |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
984 |
monthIndex := month |
699 | 985 |
] ifFalse:[ |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
986 |
monthIndex := self indexOfMonth:month |
699 | 987 |
]. |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
988 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
989 |
^ self daysUntilMonthIndex:monthIndex forYear:yearInteger |
699 | 990 |
|
991 |
" |
|
992 |
Date daysUntilMonth:'feb' forYear:1993 |
|
993 |
Date daysUntilMonth:'jan' forYear:1993 |
|
994 |
" |
|
995 |
! |
|
996 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
997 |
defaultFormatString |
8118 | 998 |
(DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[ |
999 |
self initNames |
|
1000 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1001 |
^ DefaultFormats at:Language ifAbsent:(DefaultFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1002 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1003 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1004 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1005 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1006 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1007 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1008 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1009 |
|
5778 | 1010 |
firstDayOfYear:inYear |
1011 |
"return the weekDay-index of the 1st-january of the given year. |
|
1012 |
1->monday, 2->tuesday, ... 7->sunday" |
|
1013 |
||
1014 |
| t d | |
|
1015 |
||
1016 |
((inYear < 1) or:[ inYear > 9999]) ifTrue:[ |
|
1017 |
^ 0. |
|
1018 |
]. |
|
1019 |
||
1020 |
"/ normal Gregorian calendar: one extra day per four years |
|
1021 |
t := 4 + inYear + ((inYear + 3) // 4). |
|
1022 |
||
1023 |
inYear > 1800 ifTrue:[ |
|
1024 |
"/ Julian calendar: regular Gregorian less 3 days per 400 |
|
1025 |
t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400). |
|
1026 |
]. |
|
1027 |
inYear > 1752 ifTrue:[ |
|
1028 |
"/ calendar changeover |
|
1029 |
t := t + 3. |
|
1030 |
]. |
|
1031 |
d := t \\ 7. |
|
1032 |
"/ convert from 0 (sunday) .. 6 (saturday) |
|
1033 |
"/ to 1 (munday) .. 7 (sunday) |
|
1034 |
d == 0 ifTrue:[^ 7]. |
|
1035 |
^ d |
|
1036 |
||
1037 |
" |
|
1038 |
self firstDayOfYear:2000 |
|
1039 |
(Date newDay:1 year:2000) dayInWeek |
|
1040 |
self firstDayOfYear:1999 |
|
1041 |
(Date newDay:1 year:1999) dayInWeek |
|
1042 |
self firstDayOfYear:1998 |
|
1043 |
(Date newDay:1 year:1998) dayInWeek |
|
1044 |
self firstDayOfYear:2001 |
|
1045 |
(Date newDay:1 year:2001) dayInWeek |
|
1046 |
self firstDayOfYear:2002 |
|
1047 |
(Date newDay:1 year:2002) dayInWeek |
|
1048 |
self firstDayOfYear:2006 |
|
1049 |
(Date newDay:1 year:2006) dayInWeek |
|
1050 |
||
1051 |
self firstDayOfYear:1800 |
|
1052 |
(Date newDay:1 year:1800) dayInWeek |
|
1053 |
" |
|
1054 |
! |
|
1055 |
||
699 | 1056 |
indexOfMonth:aMonthString |
1057 |
"given the name of a month (either string or symbol), |
|
1058 |
return the month-index (1 for jan; 12 for december). |
|
1059 |
The given string may be a full or abbreviated name, |
|
1060 |
case is ignored. |
|
1061 |
Return 0 for invalid month name." |
|
1062 |
||
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1063 |
|monthIndex| |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1064 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1065 |
monthIndex := self indexOfMonth:aMonthString language:nil. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1066 |
"/ if not found, retry in english |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1067 |
(monthIndex == 0 and:[ Smalltalk language ~= 'en' ]) |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1068 |
ifTrue:[ |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1069 |
monthIndex := self indexOfMonth:aMonthString language:'en'. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1070 |
]. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1071 |
^ monthIndex |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1072 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1073 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1074 |
Date indexOfMonth:'jan' |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1075 |
Date indexOfMonth:'Jan' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1076 |
Date indexOfMonth:'December' |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1077 |
Date indexOfMonth:'Dezember' |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1078 |
Date indexOfMonth:'december' |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1079 |
Date indexOfMonth:'dezember' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1080 |
" |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1081 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1082 |
"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
|
1083 |
! |
699 | 1084 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1085 |
indexOfMonth:aMonthString language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1086 |
"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
|
1087 |
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
|
1088 |
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
|
1089 |
case is ignored. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1090 |
Return 0 for invalid month name. |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1091 |
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
|
1092 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1093 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1094 |
|idx name langMonthNames langMonthAbbrevs| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1095 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1096 |
langMonthNames := self monthNamesForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1097 |
langMonthAbbrevs := self monthAbbrevsForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1098 |
|
699 | 1099 |
name := aMonthString asLowercase. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1100 |
idx := langMonthAbbrevs indexOf:name. |
699 | 1101 |
idx ~~ 0 ifTrue:[^ idx]. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1102 |
idx := langMonthNames indexOf:name. |
699 | 1103 |
idx ~~ 0 ifTrue:[^ idx]. |
1104 |
||
1105 |
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
|
1106 |
idx := langMonthAbbrevs indexOf:name. |
699 | 1107 |
idx ~~ 0 ifTrue:[^ idx]. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1108 |
idx := langMonthNames indexOf:name. |
699 | 1109 |
idx ~~ 0 ifTrue:[^ idx]. |
1110 |
||
1111 |
^ idx |
|
1112 |
||
1113 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1114 |
Date indexOfMonth:'jan' language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1115 |
Date indexOfMonth:'Jan' language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1116 |
Date indexOfMonth:'December' language:#en |
699 | 1117 |
" |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1118 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1119 |
"Modified: / 08-10-2006 / 14:20:17 / cg" |
699 | 1120 |
! |
1121 |
||
1122 |
leapYear:yearInteger |
|
1123 |
"return true, if yearInteger is a leap year." |
|
1124 |
||
1125 |
|y "{ Class: SmallInteger }"| |
|
1126 |
||
1127 |
y := yearInteger. |
|
1128 |
(y \\ 4 == 0) ifTrue:[ |
|
1129 |
(y \\ 100 ~~ 0) ifTrue:[^ true]. |
|
1130 |
(y \\ 400 == 0) ifTrue:[^ true] |
|
1131 |
]. |
|
1132 |
^ false |
|
1133 |
||
1134 |
" |
|
1135 |
Date leapYear:1992 |
|
1136 |
Date leapYear:1994 |
|
1137 |
Date leapYear:1900 |
|
1138 |
Date leapYear:2000 |
|
1139 |
" |
|
1140 |
! |
|
1141 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1142 |
longFormatString |
8118 | 1143 |
(LongFormats isNil or:[EnvironmentChange]) ifTrue:[ |
1144 |
self initNames |
|
1145 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1146 |
^ LongFormats at:Language ifAbsent:(LongFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1147 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1148 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1149 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1150 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1151 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1152 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1153 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1154 |
|
699 | 1155 |
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger |
1156 |
"given a day-in-year (1..365) return an Array containing the |
|
1157 |
month index and the day-in-month. Return nil if the argument is invalid." |
|
1158 |
||
1159 |
|restDays daysInMonth| |
|
1160 |
||
1161 |
restDays := aDayInYear. |
|
1162 |
restDays < 1 ifTrue:[^ nil]. |
|
1163 |
||
1164 |
1 to:12 do:[:m | |
|
1165 |
daysInMonth := self daysInMonthIndex:m forYear:yearInteger. |
|
1166 |
restDays <= daysInMonth ifTrue:[ |
|
1167 |
^ Array with:m with:restDays |
|
1168 |
]. |
|
1169 |
restDays := restDays - daysInMonth |
|
1170 |
]. |
|
1171 |
restDays > daysInMonth ifTrue:[^ nil]. |
|
1172 |
^ Array with:12 with:restDays |
|
1173 |
||
1174 |
" |
|
1175 |
Date monthAndDayFromDayInYear:66 forYear:1980 |
|
1176 |
Date monthAndDayFromDayInYear:66 forYear:1981 |
|
1177 |
" |
|
1178 |
! |
|
1179 |
||
1180 |
nameOfDay:dayIndex |
|
1181 |
"given a day index (1..7), return the name of the day" |
|
1182 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1183 |
^ self nameOfDay:dayIndex language:nil |
699 | 1184 |
|
1185 |
" |
|
8795 | 1186 |
Date nameOfDay:1 |
699 | 1187 |
Date nameOfDay:4 |
1188 |
" |
|
1189 |
! |
|
1190 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1191 |
nameOfDay:dayIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1192 |
"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
|
1193 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1194 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1195 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1196 |
^ (self dayNamesForLanguage:lang) at:dayIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1197 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1198 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1199 |
Date nameOfDay:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1200 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1201 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1202 |
|
699 | 1203 |
nameOfMonth:monthIndex |
1204 |
"given a month index (1..12), return the name of the month" |
|
1205 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1206 |
^ self nameOfMonth:monthIndex language:nil |
699 | 1207 |
|
1208 |
" |
|
1209 |
Date nameOfMonth:11 |
|
1210 |
Date nameOfMonth:12 |
|
1211 |
Date nameOfMonth:4 |
|
1212 |
" |
|
1213 |
! |
|
1214 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1215 |
nameOfMonth:monthIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1216 |
"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
|
1217 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1218 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1219 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1220 |
^ (self monthNamesForLanguage:lang) at:monthIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1221 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1222 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1223 |
Date nameOfMonth:11 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1224 |
Date nameOfMonth:12 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1225 |
Date nameOfMonth:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1226 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1227 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1228 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1229 |
shortFormatString |
8118 | 1230 |
(ShortFormats isNil or:[EnvironmentChange]) ifTrue:[ |
1231 |
self initNames |
|
1232 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1233 |
^ ShortFormats at:Language ifAbsent:(ShortFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1234 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1235 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1236 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1237 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1238 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1239 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1240 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1241 |
|
5548 | 1242 |
weekInYearOf:aDateOrTimestamp |
1243 |
"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
|
1244 |
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
|
1245 |
The above definition can lead to the 1st week starting in the old year!!" |
5548 | 1246 |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1247 |
|dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week| |
5548 | 1248 |
|
1249 |
dayInYear := aDateOrTimestamp dayInYear. |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1250 |
dayOfFirstWeekInYear := self dayOfFirstWeekInYear:aDateOrTimestamp year. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1251 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1252 |
numDays := aDateOrTimestamp asDate subtractDate:dayOfFirstWeekInYear asDate. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1253 |
"/ 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
|
1254 |
numDays < 0 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1255 |
"/ not in a week here ... |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1256 |
"/ can be either 52 or 53, depending on the previous year. |
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1257 |
^ self weekInYearOf:(Date newDay:31 month:12 year:aDateOrTimestamp year - 1) |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1258 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1259 |
|
5548 | 1260 |
"/ compute the week |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1261 |
week := numDays // 7 + 1. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1262 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1263 |
"/ 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
|
1264 |
week == 53 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1265 |
dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1266 |
aDateOrTimestamp asDate >= dayOfFirstWeekInNextYear asDate ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1267 |
^ 1 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1268 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1269 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1270 |
^ week |
5548 | 1271 |
|
1272 |
" |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1273 |
Timestamp now weekInYear |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1274 |
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
|
1275 |
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
|
1276 |
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
|
1277 |
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
|
1278 |
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
|
1279 |
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
|
1280 |
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
|
1281 |
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
|
1282 |
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
|
1283 |
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
|
1284 |
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
|
1285 |
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
|
1286 |
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
|
1287 |
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
|
1288 |
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
|
1289 |
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
|
1290 |
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
|
1291 |
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
|
1292 |
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
|
1293 |
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
|
1294 |
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
|
1295 |
Date weekInYearOf:(Date newDay:7 month:1 year:2002) |
5548 | 1296 |
" |
1297 |
! |
|
1298 |
||
699 | 1299 |
yearAsDays: yearInteger |
1300 |
"Returns the number of days since Jan 1, 1901. (GNU) |
|
1301 |
to the first Jan of the year, yearInteger. |
|
1302 |
For 1901 this is zero, for 1902 its 365. |
|
1303 |
Defined for years >= 1901" |
|
1304 |
||
1305 |
|y "{ Class: SmallInteger }"| |
|
1306 |
||
1307 |
y := yearInteger - 1900. |
|
1308 |
y := y - 1. |
|
1309 |
^ (y * 365) |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1310 |
+ (y // 4) |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1311 |
- (y // 100) |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1312 |
+ ((y + 300) // 400) |
699 | 1313 |
|
1314 |
" |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1315 |
Date yearAsDays:5 |
699 | 1316 |
Date yearAsDays:1901 |
1317 |
Date yearAsDays:1902 |
|
1318 |
Date yearAsDays:1903 |
|
1319 |
Date yearAsDays:1904 |
|
1320 |
Date yearAsDays:1905 |
|
1321 |
Date yearAsDays:1994 |
|
1322 |
(Date yearAsDays:2001) - (Date yearAsDays:2000) |
|
1323 |
" |
|
1324 |
! ! |
|
1325 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1326 |
!Date class methodsFor:'obsolete'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1327 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1328 |
day:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1329 |
"return a new Date, given the day, month and year. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1330 |
Obsolete: |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1331 |
use newDay:month:year: for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1332 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1333 |
<resource: #obsolete> |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1334 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1335 |
^ self newDay:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1336 |
! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1337 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1338 |
day:dayInYear year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1339 |
"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
|
1340 |
Obsolete: |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1341 |
use newDay:year: for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1342 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1343 |
<resource: #obsolete> |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1344 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1345 |
^ self newDay:dayInYear year:year |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1346 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1347 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1348 |
isLeapYear:yearInteger |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1349 |
"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
|
1350 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1351 |
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
|
1352 |
since this method will vanish." |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1353 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1354 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1355 |
^ self leapYear:yearInteger |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1356 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1357 |
|
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
1358 |
!Date class methodsFor:'private'! |
1 | 1359 |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1360 |
abbreviatedMonthNamesForLanguage:language |
17757 | 1361 |
|langMonthAbbrevs lang| |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1362 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1363 |
(MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1364 |
self initNames |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1365 |
]. |
17757 | 1366 |
lang := language ? Smalltalk language. |
1367 |
langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:nil. |
|
1368 |
||
1369 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1370 |
langMonthAbbrevs isNil ifTrue:[ |
|
1371 |
self initNamesForLanguage: lang. |
|
1372 |
"/ If language initialization failed, take english monthAbbrevs |
|
1373 |
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
|
1374 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1375 |
^ langMonthAbbrevs |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1376 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1377 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1378 |
self abbreviatedMonthNamesForLanguage:#en |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1379 |
self abbreviatedMonthNamesForLanguage:#de |
17757 | 1380 |
self abbreviatedMonthNamesForLanguage:#fr |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1381 |
self abbreviatedMonthNamesForLanguage:#es |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1382 |
" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1383 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1384 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1385 |
dayAbbrevsForLanguage:language |
17757 | 1386 |
|langDayAbbrevs lang| |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1387 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1388 |
(DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1389 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1390 |
]. |
17757 | 1391 |
lang := language ? Smalltalk language. |
1392 |
langDayAbbrevs := DayAbbrevs at:lang ifAbsent:nil. |
|
1393 |
||
1394 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1395 |
langDayAbbrevs isNil ifTrue:[ |
|
1396 |
self initNamesForLanguage: lang. |
|
1397 |
"/ If language initialization failed, take english dayAbbrevs |
|
1398 |
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
|
1399 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1400 |
^ langDayAbbrevs |
17757 | 1401 |
|
1402 |
" |
|
1403 |
self dayAbbrevsForLanguage:#en |
|
1404 |
self dayAbbrevsForLanguage:#de |
|
1405 |
self dayAbbrevsForLanguage:#fr |
|
1406 |
self dayAbbrevsForLanguage:#es |
|
1407 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1408 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1409 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1410 |
dayNamesForLanguage:language |
17757 | 1411 |
|langDayNames lang| |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1412 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1413 |
(DayNames isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1414 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1415 |
]. |
17757 | 1416 |
lang := language ? Smalltalk language. |
1417 |
langDayNames := DayNames at:lang ifAbsent:nil. |
|
1418 |
||
1419 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1420 |
langDayNames isNil ifTrue:[ |
|
1421 |
self initNamesForLanguage: lang. |
|
1422 |
"/ If language initialization failed, take english dayNames |
|
1423 |
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
|
1424 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1425 |
^ langDayNames |
17757 | 1426 |
|
1427 |
" |
|
1428 |
self dayNamesForLanguage:#en |
|
1429 |
self dayNamesForLanguage:#de |
|
1430 |
self dayNamesForLanguage:#fr |
|
1431 |
self dayNamesForLanguage:#es |
|
1432 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1433 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1434 |
|
699 | 1435 |
daysInMonthIndex: monthIndex forYear: yearInteger |
1436 |
"return the number of days in month monthIndex of |
|
1437 |
year yearInteger (modified GNU). |
|
1438 |
Return 0 for invalid month index. |
|
1439 |
This is the internal version of daysInMonth:forYear:" |
|
1440 |
||
1441 |
|days| |
|
1442 |
||
1443 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
|
1444 |
||
1445 |
days := #(31 28 31 "Jan Feb Mar" |
|
1446 |
30 31 30 "Apr May Jun" |
|
1447 |
31 31 30 "Jul Aug Sep" |
|
1448 |
31 30 31 "Oct Nov Dec" |
|
1449 |
) at: monthIndex. |
|
1450 |
||
1451 |
(monthIndex == 2) ifTrue:[ |
|
1452 |
(self leapYear:yearInteger) ifTrue:[ |
|
1453 |
^ days + 1 |
|
1454 |
] |
|
1455 |
]. |
|
1456 |
^ days |
|
1457 |
||
1458 |
" |
|
1459 |
Date daysInMonthIndex:2 forYear:1994 |
|
1460 |
Date daysInMonthIndex:2 forYear:1980 |
|
1461 |
Date daysInMonthIndex:2 forYear:1981 |
|
1462 |
" |
|
1463 |
! |
|
1464 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1465 |
daysUntilMonthIndex: monthIndex forYear: yearInteger |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1466 |
"return the number of days in month monthIndex of |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1467 |
year yearInteger (modified GNU). |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1468 |
Return 0 for invalid month index. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1469 |
This is the internal version of daysInMonth:forYear:" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1470 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1471 |
|days| |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1472 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1473 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1474 |
|sum| |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1475 |
sum := 0. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1476 |
#(31 28 31 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1477 |
30 31 30 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1478 |
31 31 30 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1479 |
31 30 31 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1480 |
) collect:[:each | |first| first:= sum. sum := sum + each. first] |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1481 |
#(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
|
1482 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1483 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1484 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1485 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1486 |
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
|
1487 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1488 |
(monthIndex > 2) ifTrue:[ |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1489 |
(self leapYear:yearInteger) ifTrue:[ |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1490 |
^ days + 1 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1491 |
] |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1492 |
]. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1493 |
^ days |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1494 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1495 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1496 |
Date daysUntilMonthIndex:3 forYear:1994 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1497 |
Date daysUntilMonthIndex:3 forYear:1980 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1498 |
Date daysUntilMonthIndex:3 forYear:1981 |
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 |
! |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1501 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1502 |
monthAbbrevsForLanguage:language |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1503 |
<resource: #obsolete> |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1504 |
"obsolete" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1505 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1506 |
^ self abbreviatedMonthNamesForLanguage:language |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1507 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1508 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1509 |
monthNamesForLanguage:language |
17757 | 1510 |
|langMonthNames lang| |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1511 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1512 |
(MonthNames isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1513 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1514 |
]. |
17757 | 1515 |
lang := language ? Smalltalk language. |
1516 |
langMonthNames := MonthNames at:lang ifAbsent:nil. |
|
1517 |
||
1518 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1519 |
langMonthNames isNil ifTrue:[ |
|
1520 |
self initNamesForLanguage: lang. |
|
1521 |
"/ If language initialization failed, take english monthNames |
|
1522 |
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
|
1523 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1524 |
^ langMonthNames |
54 | 1525 |
! ! |
1526 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1527 |
!Date class methodsFor:'private-encoding/decoding'! |
54 | 1528 |
|
1529 |
encodeYear:y month:m day:d |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1530 |
"the internal encoding is strictly private, |
92 | 1531 |
and should not be used outside." |
1532 |
||
54 | 1533 |
^ (((y * 100) + m) * 100) + d |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1534 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1535 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1536 |
readDatePartFrom:str format:fmt language:languageOrNil |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1537 |
"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
|
1538 |
|
17757 | 1539 |
|dayName monthName day month year format string | |
1540 |
||
1541 |
format := fmt. |
|
1542 |
string := str throughAnyForWhich:[:ch | ch isNationalAlphaNumeric]. |
|
1543 |
||
1544 |
((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
|
1545 |
"/ skipped, in case the format is 'monday, 23rd of may...' - not used for decoding |
17757 | 1546 |
dayName := string. |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1547 |
^ nil. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1548 |
]. |
17757 | 1549 |
(format sameAs:'d') ifTrue:[ |
1550 |
day := Integer readFrom:string. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1551 |
^ #day -> day |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1552 |
]. |
17757 | 1553 |
|
1554 |
(format sameAs:'m') ifTrue:[ |
|
1555 |
month := Integer readFrom:string. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1556 |
^ #month -> month |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1557 |
]. |
17757 | 1558 |
(format sameAs:'monthName') ifTrue:[ |
1559 |
monthName := string. |
|
1560 |
month := (Date monthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m]. |
|
1561 |
"/ month == 0 ifTrue:[self error:'invalid month name']. |
|
1562 |
^ #month -> month |
|
1563 |
]. |
|
1564 |
(format sameAs:'shortMonthName') ifTrue:[ |
|
1565 |
monthName := string. |
|
1566 |
month := (Date abbreviatedMonthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m]. |
|
1567 |
"/ month == 0 ifTrue:[self error:'invalid month name']. |
|
1568 |
^ #month -> month |
|
1569 |
]. |
|
1570 |
||
1571 |
format = 'y' ifTrue:[ |
|
1572 |
year := Integer readFrom:string. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1573 |
year < 100 ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1574 |
^ #year -> (year + 2000) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1575 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1576 |
^ #year -> year |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1577 |
]. |
17757 | 1578 |
format = 'Y' ifTrue:[ |
1579 |
year := Integer readFrom:string. |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1580 |
year >= 100 ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1581 |
^ #year -> year |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1582 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1583 |
^ #year -> (year + 2000) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1584 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1585 |
self error:'unknown format specifier' |
54 | 1586 |
! ! |
1587 |
||
7258 | 1588 |
!Date class methodsFor:'private-instance creation'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1589 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1590 |
fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1591 |
"return a date, representing the date given by the operatingSystem time. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1592 |
This somewhat clumsy implementation hides the OS's date representation |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1593 |
(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
|
1594 |
Dont use this method, the osTime representation is totally unportable." |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1595 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1596 |
^ self basicNew fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1597 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1598 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1599 |
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
|
1600 |
thats where Unix time starts |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1601 |
On other systems, it may be something different. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1602 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1603 |
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
|
1604 |
" |
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 |
|
7261 | 1607 |
!Date methodsFor:'Compatibility-ANSI'! |
6419 | 1608 |
|
1609 |
dayOfWeek |
|
1610 |
"return the week-day of the receiver - 1 is sunday, 7 for saturday. |
|
1611 |
WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday). |
|
1612 |
" |
|
1613 |
||
1614 |
|d| |
|
1615 |
||
1616 |
d := self dayInWeek. |
|
1617 |
d == 7 ifTrue:[ |
|
1618 |
^ 1 |
|
1619 |
]. |
|
1620 |
^ d + 1 |
|
1621 |
||
1622 |
" |
|
1623 |
Date today dayOfWeek |
|
1624 |
Date today dayInWeek |
|
1625 |
" |
|
1626 |
! |
|
1627 |
||
1628 |
dayOfWeekAbbreviation |
|
1629 |
"return the short week-day of the receiver as a string. |
|
1630 |
The returned string depends on the language setting. |
|
1631 |
Expect things like 'mon', 'tue' ..." |
|
1632 |
||
1633 |
^ self abbreviatedDayName |
|
1634 |
||
1635 |
" |
|
1636 |
Date today dayOfWeekAbbreviation |
|
1637 |
" |
|
1638 |
! |
|
1639 |
||
1640 |
dayOfWeekName |
|
1641 |
"return the week-day of the receiver as a string. |
|
1642 |
The returned string depends on the language setting. |
|
1643 |
Expect things like 'monday', 'tuesday' ..." |
|
1644 |
||
1645 |
^ self weekday |
|
1646 |
||
1647 |
" |
|
1648 |
Date today dayOfWeekName |
|
1649 |
Date today dayOfWeekAbbreviation |
|
1650 |
" |
|
1651 |
! |
|
1652 |
||
1653 |
dayOfYear |
|
1654 |
"return the day-nr within the year of the receiver - 1..365/366" |
|
1655 |
||
1656 |
^ self dayInYear |
|
1657 |
||
1658 |
" |
|
1659 |
Date today dayOfYear |
|
1660 |
" |
|
1661 |
! |
|
1662 |
||
1663 |
isLeapYear |
|
1664 |
"return true, if the receivers year is a leap year" |
|
1665 |
||
1666 |
^ self leap |
|
1667 |
||
1668 |
" |
|
1669 |
Date today isLeapYear |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1670 |
(Date newDay:1 month:1 year:1992) isLeapYear |
6419 | 1671 |
" |
1672 |
! |
|
1673 |
||
1674 |
monthAbbreviation |
|
1675 |
"return the month of the receiver as a string. |
|
1676 |
The returned string depends on the language setting. |
|
1677 |
Expect things like 'jan', 'feb' ..." |
|
1678 |
||
1679 |
^ self abbreviatedMonthName |
|
1680 |
||
1681 |
" |
|
1682 |
Date today monthAbbreviation |
|
1683 |
" |
|
1684 |
! ! |
|
1685 |
||
7261 | 1686 |
!Date methodsFor:'Compatibility-ST80'! |
5515 | 1687 |
|
11740 | 1688 |
firstDayInMonth |
1689 |
"Return the first day in the month of the receiver" |
|
1690 |
||
1691 |
^ self subtractDays:(self dayOfMonth - 1) |
|
1692 |
||
1693 |
" |
|
1694 |
Date today |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1695 |
Date today firstDayInMonth |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1696 |
Date today firstDayInMonth subtractDays:1 |
11740 | 1697 |
(Date today subtractDays:30) firstDayInMonth |
1698 |
(Date today subtractDays:122) firstDayInMonth |
|
1699 |
(Date today subtractDays:154) firstDayInMonth |
|
1700 |
" |
|
1701 |
! |
|
1702 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1703 |
lastDayInMonth |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1704 |
"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
|
1705 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1706 |
^ self addDays:(self daysInMonth - self day). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1707 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1708 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1709 |
Date today |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1710 |
Date today lastDayInMonth |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1711 |
Date today lastDayInMonth addDays:1 |
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 |
|
11664 | 1715 |
next:dayName |
1716 |
"Return the next date whose weekday name is dayName. |
|
1717 |
Caveat; dayName is expected to be in the current language" |
|
1718 |
||
1719 |
|ti ni| |
|
1720 |
||
1721 |
ti := self weekdayIndex. |
|
1722 |
ni := (self class dayOfWeek:dayName). |
|
1723 |
^ self addDays:(ni > ti ifTrue:[ ni-ti ] ifFalse:[ 7+ni-ti ]) |
|
1724 |
||
1725 |
" |
|
1726 |
Date today |
|
1727 |
Date today next:#Friday |
|
1728 |
Date today next:#Sunday |
|
1729 |
Date today next:#Monday |
|
1730 |
Date today next:#Thursday |
|
1731 |
Date today next:#WednesDay |
|
1732 |
" |
|
1733 |
! |
|
1734 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1735 |
nextDayWithIndex:dayIndex |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1736 |
"Return the next date whose weekday name is dayName. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1737 |
dayIndex is Monday=1, ... , Sunday=7" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1738 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1739 |
|ti| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1740 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1741 |
self assert:(dayIndex between:1 and:7). |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1742 |
ti := self weekdayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1743 |
^ self addDays:(dayIndex > ti ifTrue:[ dayIndex-ti ] ifFalse:[ 7+dayIndex-ti ]) |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1744 |
|
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 |
Date today |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1747 |
Date today nextDayWithIndex:5 - next Friday |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1748 |
Date today nextDayWithIndex:7 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1749 |
Date today nextDayWithIndex:1 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1750 |
Date today nextDayWithIndex:4 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1751 |
Date today nextDayWithIndex:3 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1752 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1753 |
! |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1754 |
|
6976 | 1755 |
previous:dayName |
1756 |
"Return the previous date whose weekday name is dayName. |
|
1757 |
Caveat; dayName is expected to be in the current language" |
|
1758 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1759 |
^ self previousDayWithIndex:(self class dayOfWeek:dayName). |
6976 | 1760 |
|
1761 |
" |
|
11664 | 1762 |
Date today |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1763 |
Date today previous:#Montag |
6976 | 1764 |
Date today previous:#Monday |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1765 |
|
11664 | 1766 |
Date today previous:#Friday |
1767 |
Date today previous:#Sunday |
|
1768 |
Date today previous:#Monday |
|
1769 |
Date today previous:#Thursday |
|
1770 |
Date today previous:#WednesDay |
|
1771 |
Date today previous:#TuesDay |
|
6976 | 1772 |
" |
1773 |
! |
|
1774 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1775 |
previousDayWithIndex:dayIndex |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1776 |
"Return the previous date whose weekday name is dayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1777 |
dayIndex is Monday=1, ... , Sunday=7" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1778 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1779 |
|ti| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1780 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1781 |
self assert:(dayIndex between:1 and:7). |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1782 |
ti := self weekdayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1783 |
^ self subtractDays:(((ti - dayIndex - 1) \\ 7) + 1) |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1784 |
|
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 |
Date today |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1787 |
Date today previousDayWithIndex:1 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1788 |
Date today previousDayWithIndex:5 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1789 |
Date today previousDayWithIndex:7 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1790 |
Date today previousDayWithIndex:4 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1791 |
Date today previousDayWithIndex:3 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1792 |
Date today previousDayWithIndex:2 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1793 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1794 |
! |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1795 |
|
7023 | 1796 |
printFormat:aFormatArray |
1797 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
1798 |
Return a string containing a printed representation of the receiver. |
|
1799 |
The formatArray argument consists of 6 or 7 integers which control |
|
1800 |
the resulting string. The entries are: |
|
1801 |
1 day position (1, 2 or 3) |
|
1802 |
2 month position (1..3) |
|
1803 |
3 year position (1..3) |
|
1804 |
4 asciiValue of separator character or separator character |
|
1805 |
or collection of 2 separator characters |
|
1806 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
1807 |
4: abbreviated uppercase 5: full uppercase) |
|
1808 |
6 year format (1 include century; 2 exclude century) |
|
1809 |
7 (optional) true/false. |
|
1810 |
if true, print numbers in 2-digit format |
|
1811 |
(i.e. with leading zeros); |
|
1812 |
Taken as false, if ommited |
|
1813 |
||
1814 |
Day and monthnames are in the currently active language. |
|
1815 |
||
1816 |
This method supports more options than the ST-80 version; month formats |
|
1817 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
1818 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
1819 |
||
1820 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
1821 |
This is an ST-80 compatibility method - I would have choosen another |
|
1822 |
(less cryptic) formatString ... |
|
1823 |
" |
|
1824 |
||
7961 | 1825 |
^ self printFormat:aFormatArray forLanguage:nil |
1826 |
||
1827 |
" |
|
1828 |
Date today printFormat:#(1 2 3 '' 1 2) |
|
1829 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
1830 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
|
1831 |
Date today printFormat:#(2 1 3 32 3 1) |
|
1832 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
1833 |
Date today printFormat:#(1 2 3 $- 2 1) |
|
1834 |
Date today printFormat:#(1 2 3 $- 4 1) |
|
1835 |
" |
|
1836 |
! |
|
1837 |
||
1838 |
printFormat:aFormatArray forLanguage:languageOrNil |
|
1839 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
1840 |
Return a string containing a printed representation of the receiver. |
|
1841 |
The formatArray argument consists of 6 or 7 integers which control |
|
1842 |
the resulting string. The entries are: |
|
1843 |
1 day position (1, 2 or 3) |
|
1844 |
2 month position (1..3) |
|
1845 |
3 year position (1..3) |
|
1846 |
4 asciiValue of separator character or separator character |
|
1847 |
or collection of 2 separator characters |
|
1848 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
1849 |
4: abbreviated uppercase 5: full uppercase) |
|
1850 |
6 year format (1 include century; 2 exclude century) |
|
1851 |
7 (optional) true/false. |
|
1852 |
if true, print numbers in 2-digit format |
|
1853 |
(i.e. with leading zeros); |
|
1854 |
Taken as false, if ommited |
|
1855 |
||
1856 |
Day and monthnames are in the currently active language. |
|
1857 |
||
1858 |
This method supports more options than the ST-80 version; month formats |
|
1859 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
1860 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
1861 |
||
1862 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
1863 |
This is an ST-80 compatibility method - I would have choosen another |
|
1864 |
(less cryptic) formatString ... |
|
1865 |
" |
|
1866 |
||
7023 | 1867 |
|mf upperCase day month year components sep1 sep2 leadingZeros| |
1868 |
||
1869 |
aFormatArray size > 6 ifTrue:[ |
|
1870 |
leadingZeros := aFormatArray at:7 |
|
1871 |
] ifFalse:[ |
|
1872 |
leadingZeros := false. |
|
1873 |
]. |
|
1874 |
||
1875 |
components := Array new:3. |
|
1876 |
day := self day. |
|
1877 |
leadingZeros ifTrue:[ |
|
1878 |
day := day printStringLeftPaddedTo:2 with:$0 |
|
1879 |
] ifFalse:[ |
|
1880 |
day := day printString |
|
1881 |
]. |
|
1882 |
components at:(aFormatArray at:1) put:day. |
|
1883 |
||
1884 |
upperCase := false. |
|
1885 |
mf := aFormatArray at:5. |
|
1886 |
(mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true]. |
|
1887 |
||
1888 |
mf == 1 ifTrue:[ |
|
1889 |
month := self month. |
|
1890 |
leadingZeros ifTrue:[ |
|
1891 |
month := month printStringLeftPaddedTo:2 with:$0 |
|
1892 |
] ifFalse:[ |
|
1893 |
month := month printString |
|
1894 |
] |
|
1895 |
] ifFalse:[ |
|
1896 |
mf == 2 ifTrue:[ |
|
7961 | 1897 |
month := self abbreviatedMonthNameForLanguage:languageOrNil |
7023 | 1898 |
] ifFalse:[ |
7961 | 1899 |
month := self monthNameForLanguage:languageOrNil |
7023 | 1900 |
] |
1901 |
]. |
|
1902 |
upperCase ifTrue:[month := month asUppercase]. |
|
1903 |
components at:(aFormatArray at:2) put:month. |
|
1904 |
||
1905 |
year := self year. |
|
1906 |
(aFormatArray at:6) == 2 ifTrue:[ |
|
1907 |
year := year \\ 100. |
|
1908 |
year := year printStringLeftPaddedTo:2 with:$0 |
|
1909 |
]. |
|
1910 |
year := year printString. |
|
1911 |
components at:(aFormatArray at:3) put:year. |
|
1912 |
||
1913 |
sep1 := sep2 := (aFormatArray at:4). |
|
1914 |
sep1 isString ifFalse:[ |
|
1915 |
sep1 isCollection ifTrue:[ |
|
1916 |
sep2 := (sep1 at:2). |
|
1917 |
sep1 := (sep1 at:1). |
|
1918 |
] ifFalse:[ |
|
1919 |
sep1 := sep2 := sep1 asCharacter |
|
1920 |
] |
|
1921 |
]. |
|
1922 |
||
1923 |
^ (components at:1) |
|
1924 |
, sep1 asString |
|
1925 |
, (components at:2) |
|
1926 |
, sep2 asString |
|
1927 |
, (components at:3) |
|
1928 |
||
1929 |
" |
|
7961 | 1930 |
Date today printFormat:#(1 2 3 '' 1 2) |
1931 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
7023 | 1932 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
1933 |
Date today printFormat:#(2 1 3 32 3 1) |
|
1934 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
7961 | 1935 |
Date today printFormat:#(1 2 3 $- 2 1) forLanguage:#en |
1936 |
Date today printFormat:#(1 2 3 $- 4 1) forLanguage:#en |
|
1937 |
" |
|
1938 |
! |
|
1939 |
||
1940 |
printFormat:aFormatArray forLanguage:languageOrNil on:aStream |
|
1941 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
1942 |
in printFormat:. |
|
1943 |
Append a printed representation of the receiver to aStream. |
|
1944 |
The argument, aFormatString controls the format, as described |
|
1945 |
in the #printFormat: method. |
|
1946 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
1947 |
||
1948 |
aStream nextPutAll:(self printFormat:aFormatArray forLanguage:languageOrNil) |
|
1949 |
||
1950 |
||
1951 |
"european formats: |
|
1952 |
||
1953 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
1954 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
1955 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1956 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
1957 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
1958 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
1959 |
||
1960 |
US formats: |
|
1961 |
||
1962 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
1963 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
1964 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
1965 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
1966 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
1967 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1968 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
7023 | 1969 |
" |
1970 |
! |
|
1971 |
||
1972 |
printFormat:aFormatArray on:aStream |
|
1973 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
1974 |
in printFormat:. |
|
1975 |
Append a printed representation of the receiver to aStream. |
|
1976 |
The argument, aFormatString controls the format, as described |
|
1977 |
in the #printFormat: method. |
|
1978 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
1979 |
||
1980 |
aStream nextPutAll:(self printFormat:aFormatArray) |
|
1981 |
||
1982 |
||
1983 |
"european formats: |
|
1984 |
||
1985 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
1986 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
1987 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1988 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
1989 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
1990 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
1991 |
||
1992 |
US formats: |
|
1993 |
||
1994 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
1995 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
1996 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
1997 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
1998 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
1999 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
2000 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
2001 |
" |
|
2002 |
! |
|
2003 |
||
5515 | 2004 |
shortPrintString |
2005 |
"dummy - for now" |
|
2006 |
||
2007 |
^ self printString |
|
2008 |
||
2009 |
"Created: 20.6.1997 / 17:16:48 / cg" |
|
6976 | 2010 |
! |
2011 |
||
2012 |
weekdayIndex |
|
2013 |
"Return the day index; Monday=1, ... , Sunday=7" |
|
2014 |
||
2015 |
^ (self asDays + 1) \\ 7 + 1 "1 January 1901 was a Tuesday" |
|
2016 |
||
2017 |
" |
|
2018 |
Date today dayName |
|
2019 |
Date today weekdayIndex |
|
2020 |
" |
|
5515 | 2021 |
! ! |
2022 |
||
7261 | 2023 |
!Date methodsFor:'Compatibility-Squeak'! |
4407 | 2024 |
|
2025 |
mmddyyyy |
|
4462 | 2026 |
"return a printed representation of the receiver in the |
2027 |
form mmddyyyy. |
|
2028 |
The receiver can be reconstructed with: |
|
2029 |
Date readMMDDYYYYFrom:aStringOrStream onError:[...]" |
|
2030 |
||
11182 | 2031 |
^ self printStringFormat:'%m%d%y' |
2032 |
||
2033 |
"/ ^ (self month printStringLeftPaddedTo:2 with:$0) |
|
2034 |
"/ , (self day printStringLeftPaddedTo:2 with:$0) |
|
2035 |
"/ , (self year printStringLeftPaddedTo:4 with:$0) |
|
4407 | 2036 |
|
2037 |
" |
|
2038 |
Date today mmddyyyy |
|
2039 |
" |
|
11181 | 2040 |
! |
2041 |
||
2042 |
yyyymmdd |
|
2043 |
"return a printed representation of the receiver in the |
|
2044 |
form yyyymmdd. |
|
2045 |
The receiver can be reconstructed with: |
|
2046 |
Date readYYYYMMDDFrom:aStringOrStream onError:[...]" |
|
2047 |
||
11182 | 2048 |
^ self printStringFormat:'%y%m%d' |
2049 |
||
2050 |
"/ ^ (self year printStringLeftPaddedTo:4 with:$0) |
|
2051 |
"/ , (self month printStringLeftPaddedTo:2 with:$0) |
|
2052 |
"/ , (self day printStringLeftPaddedTo:2 with:$0) |
|
11181 | 2053 |
|
2054 |
" |
|
11182 | 2055 |
Date today yyyymmdd |
11181 | 2056 |
" |
4407 | 2057 |
! ! |
2058 |
||
699 | 2059 |
!Date methodsFor:'accessing'! |
241 | 2060 |
|
699 | 2061 |
abbreviatedDayName |
2062 |
"return the short week-day of the receiver as a string. |
|
2063 |
The returned string depends on the language setting. |
|
2064 |
Expect things like 'mon', 'tue' ..." |
|
54 | 2065 |
|
699 | 2066 |
^ self class abbreviatedNameOfDay:(self dayInWeek) |
92 | 2067 |
|
2068 |
" |
|
699 | 2069 |
Date today abbreviatedDayName |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2070 |
(Date newDay:15 month:4 year:1959) abbreviatedDayName |
92 | 2071 |
" |
2072 |
! |
|
2073 |
||
699 | 2074 |
abbreviatedMonthName |
2075 |
"return the month of the receiver as a string. |
|
2076 |
The returned string depends on the language setting. |
|
2077 |
Expect things like 'jan', 'feb' ..." |
|
54 | 2078 |
|
699 | 2079 |
^ self class abbreviatedNameOfMonth:(self month) |
68 | 2080 |
|
92 | 2081 |
" |
699 | 2082 |
Date today abbreviatedMonthName |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2083 |
(Date newDay:15 month:4 year:1959) abbreviatedMonthName |
92 | 2084 |
" |
2085 |
! |
|
2086 |
||
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2087 |
abbreviatedMonthNameForLanguage:lang |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2088 |
"return the month of the receiver as a string. |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2089 |
The returned string depends on the language setting. |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2090 |
Expect things like 'jan', 'feb' ..." |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2091 |
|
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2092 |
^ self class abbreviatedNameOfMonth:(self month) language:lang |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2093 |
|
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2094 |
" |
7961 | 2095 |
Date today abbreviatedMonthNameForLanguage:#en |
2096 |
Date today abbreviatedMonthNameForLanguage:#de |
|
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2097 |
" |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2098 |
! |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2099 |
|
92 | 2100 |
asDays |
2101 |
"return the number of days elapsed since 01-Jan-1901 |
|
2102 |
and the receiver's day; starts with 0 for 1-1-1901. |
|
2103 |
Date>>fromDays: is the reverse operation. |
|
2104 |
For ST-80 compatibility." |
|
68 | 2105 |
|
2106 |
|yr| |
|
2107 |
||
2108 |
yr := self year. |
|
2109 |
^ (self class yearAsDays:yr) |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2110 |
+ (self class daysUntilMonthIndex:self month forYear:yr) |
68 | 2111 |
+ self day |
85 | 2112 |
- 1 |
68 | 2113 |
|
92 | 2114 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2115 |
(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
|
2116 |
(Date newDay: 1 month: 1 year: 1901) asDays -> 0 |
92 | 2117 |
Date today asDays |
2118 |
Date fromDays:(Date today asDays + 7) |
|
2119 |
" |
|
77 | 2120 |
! |
2121 |
||
2122 |
asSeconds |
|
92 | 2123 |
"return the seconds between 1.jan.1901 and the same time in the receivers |
2124 |
day. (i.e. midnight to midnight). |
|
1501 | 2125 |
This does not include any leapSeconds ... strictly speaking, this is incorrect. |
77 | 2126 |
ST-80 compatibility." |
2127 |
||
92 | 2128 |
^ 60*60*24 * self asDays |
77 | 2129 |
|
92 | 2130 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2131 |
(Date newDay: 5 month: 8 year: 1962) asSeconds |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2132 |
(Date newDay: 1 month: 1 year: 1901) asSeconds |
92 | 2133 |
(Date today addDays:7) asSeconds - Date today asSeconds |
1501 | 2134 |
" |
2135 |
||
2136 |
"Modified: 1.7.1996 / 14:19:17 / cg" |
|
699 | 2137 |
! |
2138 |
||
2139 |
day |
|
2140 |
"return the day (1..31) of the receiver" |
|
2141 |
||
2142 |
^ dateEncoding \\ 100 |
|
2143 |
||
8626 | 2144 |
"example: |
699 | 2145 |
Date today day |
2146 |
" |
|
2147 |
! |
|
2148 |
||
2149 |
dayInWeek |
|
5778 | 2150 |
"return the week-day of the receiver - 1 for monday, 7 for sunday. |
6419 | 2151 |
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
|
2152 |
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
|
2153 |
(i.e. do not use this for dates before 1583) |
5778 | 2154 |
" |
699 | 2155 |
|
3256
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2156 |
|wday| |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2157 |
|
5778 | 2158 |
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
|
2159 |
+ self asDays) \\ 7 + 1. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2160 |
wday < 1 ifTrue:[ |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2161 |
wday := wday + 7 |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2162 |
]. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2163 |
^ wday |
699 | 2164 |
|
2165 |
" |
|
5778 | 2166 |
Date today dayInWeek |
5548 | 2167 |
Date tomorrow dayInWeek |
2168 |
Date yesterday dayInWeek |
|
5778 | 2169 |
(Date today subtractDays:2) dayInWeek |
3257 | 2170 |
Date today weekday |
5548 | 2171 |
Date tomorrow weekday |
2172 |
Date yesterday weekday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2173 |
(Date newDay:15 month:4 year:1959) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2174 |
(Date newDay:1 month:1 year:1901) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2175 |
(Date newDay:31 month:12 year:1900) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2176 |
(Date newDay:31 month:12 year:1899) dayInWeek |
699 | 2177 |
" |
1501 | 2178 |
|
3257 | 2179 |
"Modified: / 1.2.1998 / 14:10:27 / cg" |
699 | 2180 |
! |
2181 |
||
5548 | 2182 |
dayInYear |
2183 |
"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
|
2184 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2185 |
" |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2186 |
|daysSoFar| |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2187 |
daysSoFar := 0. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2188 |
#(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
|
2189 |
" |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2190 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2191 |
|days month| |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2192 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2193 |
month := self month. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2194 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2195 |
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
|
2196 |
days := days + self day. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2197 |
(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
|
2198 |
days := days + 1. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2199 |
]. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2200 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2201 |
^ days |
5548 | 2202 |
|
2203 |
" |
|
2204 |
Date today dayInYear |
|
2205 |
(Date newDay:1 year:1999) dayInYear |
|
2206 |
(Date newDay:1 year:2000) dayInYear |
|
2207 |
(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
|
2208 |
(Date newDay:59 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2209 |
(Date newDay:60 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2210 |
(Date newDay:61 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2211 |
(Date newDay:366 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2212 |
(Date newDay:59 year:2005) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2213 |
(Date newDay:60 year:2005) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2214 |
(Date newDay:365 year:2005) dayInYear |
5548 | 2215 |
" |
2216 |
! |
|
2217 |
||
77 | 2218 |
dayOfMonth |
2219 |
"Answer the day of the month represented by me. |
|
2220 |
Same as day; for ST-80 compatibility." |
|
2221 |
||
2222 |
^ self day |
|
92 | 2223 |
|
2224 |
" |
|
2225 |
Date today dayOfMonth |
|
2226 |
" |
|
2227 |
! |
|
2228 |
||
2229 |
daysInMonth |
|
2230 |
"return the number of days in the month of the receiver" |
|
2231 |
||
2232 |
^ Date daysInMonth:(self month) forYear:(self year) |
|
2233 |
||
2234 |
" |
|
2235 |
Date today daysInMonth |
|
2236 |
" |
|
2237 |
! |
|
2238 |
||
2239 |
daysInYear |
|
2240 |
"return the number of days in the year of the receiver" |
|
2241 |
||
2242 |
^ Date daysInYear:(self year) |
|
2243 |
||
2244 |
" |
|
2245 |
Date today daysInYear |
|
2246 |
" |
|
2247 |
! |
|
2248 |
||
5778 | 2249 |
daysLeftInMonth |
2250 |
"return the number of days left in the month of the receiver" |
|
2251 |
||
2252 |
^ self daysInMonth - self day |
|
2253 |
||
2254 |
" |
|
2255 |
Date today daysLeftInMonth |
|
2256 |
" |
|
2257 |
! |
|
2258 |
||
92 | 2259 |
daysLeftInYear |
11079
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2260 |
"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
|
2261 |
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
|
2262 |
the first january will return 364)" |
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2263 |
|
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2264 |
^ (Date daysInYear:(self year)) - self dayOfYear |
92 | 2265 |
|
2266 |
" |
|
5282 | 2267 |
Date today daysLeftInYear |
92 | 2268 |
" |
77 | 2269 |
! |
2270 |
||
699 | 2271 |
leap |
2272 |
"return true, if the receivers year is a leap year" |
|
68 | 2273 |
|
699 | 2274 |
^ Date leapYear:(self year) |
68 | 2275 |
|
92 | 2276 |
" |
699 | 2277 |
Date today leap |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2278 |
(Date newDay:1 month:1 year:1992) leap |
92 | 2279 |
" |
68 | 2280 |
! |
2281 |
||
699 | 2282 |
month |
2283 |
"return the month (1..12) of the receiver" |
|
92 | 2284 |
|
699 | 2285 |
^ (dateEncoding // 100) \\ 100 |
68 | 2286 |
|
92 | 2287 |
" |
699 | 2288 |
Date today month |
92 | 2289 |
" |
68 | 2290 |
! |
2291 |
||
77 | 2292 |
monthIndex |
2293 |
"return the index of the month (e.g. Feb.=2). |
|
2294 |
Same as month; for ST-80 compatibility." |
|
2295 |
||
2296 |
^ self month |
|
2297 |
! |
|
2298 |
||
68 | 2299 |
monthName |
2300 |
"return the month of the receiver as a string. |
|
2301 |
The returned string depends on the language setting. |
|
2302 |
Expect things like 'january', 'february' ..." |
|
2303 |
||
2304 |
^ self class nameOfMonth:(self month) |
|
2305 |
||
92 | 2306 |
" |
2307 |
Date today monthName |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2308 |
(Date newDay:15 month:4 year:1959) monthName |
92 | 2309 |
" |
68 | 2310 |
! |
2311 |
||
7961 | 2312 |
monthNameForLanguage:languageOrNil |
2313 |
"return the month of the receiver as a string. |
|
2314 |
The returned string depends on the language setting. |
|
2315 |
Expect things like 'january', 'february' ..." |
|
2316 |
||
2317 |
^ self class nameOfMonth:(self month) language:languageOrNil |
|
2318 |
||
2319 |
" |
|
2320 |
Date today monthName |
|
2321 |
Date today monthNameForLanguage:#en |
|
2322 |
" |
|
2323 |
! |
|
2324 |
||
5548 | 2325 |
weekInYear |
2326 |
"return the week number of the receiver - 1 for Jan, 1st. |
|
2327 |
each week is Mon .. Sun (i.e. Sunday belongs to the previous week)" |
|
2328 |
||
2329 |
^ self class weekInYearOf:self |
|
2330 |
||
2331 |
" |
|
2332 |
Date today weekInYear |
|
2333 |
(Date newDay:1 year:2000) weekInYear was a saturday |
|
2334 |
(Date newDay:2 year:2000) weekInYear was a sunday |
|
2335 |
(Date newDay:3 year:2000) weekInYear was a monday |
|
2336 |
(Date newDay:4 year:2000) weekInYear was a tuesday |
|
2337 |
(Date newDay:5 year:2000) weekInYear was a wed |
|
2338 |
(Date newDay:6 year:2000) weekInYear was a thursday |
|
2339 |
(Date newDay:7 year:2000) weekInYear was a fri |
|
2340 |
(Date newDay:8 year:2000) weekInYear was a sat |
|
2341 |
(Date newDay:9 year:2000) weekInYear was a sun |
|
2342 |
(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
|
2343 |
(Date newDay:3 month:1 year:2001) weekInYear |
5548 | 2344 |
" |
2345 |
! |
|
2346 |
||
699 | 2347 |
weekday |
2348 |
"return the week-day of the receiver as a string. |
|
68 | 2349 |
The returned string depends on the language setting. |
699 | 2350 |
Expect things like 'monday', 'tuesday' ... |
2351 |
For ST-80 compatibility" |
|
2352 |
||
2353 |
^ self class nameOfDay:(self dayInWeek) |
|
2354 |
||
2355 |
" |
|
2356 |
Date today weekday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2357 |
(Date newDay:15 month:4 year:1959) weekday |
699 | 2358 |
" |
2359 |
! |
|
2360 |
||
2361 |
year |
|
2362 |
"return the year (1..12) of the receiver" |
|
2363 |
||
2364 |
^ dateEncoding // (100*100) |
|
68 | 2365 |
|
699 | 2366 |
" |
2367 |
Date today year |
|
2368 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2369 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2370 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2371 |
year:year month:month day:day |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2372 |
dateEncoding := self class encodeYear:year month:month day:day |
699 | 2373 |
! ! |
2374 |
||
2375 |
!Date methodsFor:'arithmetic'! |
|
2376 |
||
8201 | 2377 |
+ days |
2378 |
"return a new date representing 'days' after the receiver. |
|
2379 |
The argument should be some kind of integer. |
|
2380 |
This is the same as #addDays." |
|
2381 |
||
2382 |
^ self class fromDays:(self asDays + days) |
|
2383 |
||
2384 |
" |
|
2385 |
Date today + 7. |
|
2386 |
||
2387 |
Date today to:(Date today + 28) by:7 do:[:date| |
|
2388 |
Transcript show:date weekday; show:', '; showCr:date |
|
2389 |
]. |
|
2390 |
" |
|
2391 |
! |
|
2392 |
||
2393 |
- aDateOrNumberOfDays |
|
2394 |
"return the delta in days (anInteger) between 2 dates or |
|
2395 |
subtract a number of days from a date returning a Date" |
|
2396 |
||
2397 |
aDateOrNumberOfDays class == self class ifTrue:[ |
|
2398 |
^ self asDays - aDateOrNumberOfDays asDays |
|
2399 |
]. |
|
2400 |
||
2401 |
^ self class fromDays:(self asDays - aDateOrNumberOfDays asInteger) |
|
2402 |
||
2403 |
" |
|
2404 |
Date today - Date yesterday |
|
2405 |
Date today - 3 |
|
2406 |
" |
|
2407 |
! |
|
2408 |
||
699 | 2409 |
addDays:days |
2410 |
"return a new date representing 'days' after the receiver. |
|
2411 |
The argument should be some kind of integer. |
|
2412 |
For ST-80 compatibility." |
|
2413 |
||
2414 |
^ self class fromDays:(self asDays + days) |
|
2415 |
||
2416 |
" |
|
2417 |
Date today addDays:7 |
|
2418 |
" |
|
2419 |
! |
|
2420 |
||
9262 | 2421 |
daysSince:aDate |
2422 |
"return the number of days between the receiver and the argument, |
|
2423 |
aDate, which should be some kind of date" |
|
2424 |
||
2425 |
^ self asDays - aDate asDays |
|
2426 |
||
2427 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2428 |
Date today daysSince:(Date newDay:1 month:1 year:1901) |
9262 | 2429 |
" |
2430 |
! |
|
2431 |
||
699 | 2432 |
daysUntil:aDate |
2433 |
"return the number of days between the receiver and the argument, |
|
8201 | 2434 |
aDate, which should be some kind of date" |
699 | 2435 |
|
2436 |
^ aDate asDays - self asDays |
|
68 | 2437 |
|
92 | 2438 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2439 |
(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
|
2440 |
(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
|
2441 |
(Date newDay:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994) |
699 | 2442 |
|
2443 |
|delta| |
|
2444 |
delta := Date today |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2445 |
daysUntil:(Date newDay:25 month:12 year:Date today year). |
699 | 2446 |
Transcript show:'still '; |
8201 | 2447 |
show:delta ; |
2448 |
showCR:' days till xmas' |
|
699 | 2449 |
" |
2450 |
! |
|
2451 |
||
11741 | 2452 |
firstDayInPreviousMonth:nMonths |
11742
09f7e7b1c93b
changed #firstDayInPreviousMonth:
Claus Gittinger <cg@exept.de>
parents:
11741
diff
changeset
|
2453 |
"Return the first day of a previous month (0=this month, 1=prev. month, etc.)" |
11741 | 2454 |
|
2455 |
|month year| |
|
2456 |
||
2457 |
month := self month. |
|
2458 |
year := self year. |
|
2459 |
month := month - nMonths. |
|
2460 |
month < 1 ifTrue:[ |
|
2461 |
year := year - 1 - (month negated // 12). |
|
2462 |
month := (12 - (month negated \\ 12)). |
|
2463 |
]. |
|
2464 |
||
2465 |
^ Date newDay:1 month:month year:year. |
|
2466 |
||
2467 |
" |
|
2468 |
(Date newDay:3 month:6 year:2009) firstDayInMonth |
|
2469 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:0 |
|
2470 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:5 |
|
2471 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:6 |
|
2472 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:7 |
|
2473 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:17 |
|
2474 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:18 |
|
2475 |
" |
|
2476 |
! |
|
2477 |
||
2478 |
firstDayOfPreviousMonth:nMonths |
|
2479 |
"Return the first day of a previous month (0=this month)" |
|
2480 |
||
2481 |
|month year| |
|
2482 |
||
2483 |
month := self month. |
|
2484 |
year := self year. |
|
2485 |
month := month - nMonths. |
|
2486 |
month < 1 ifTrue:[ |
|
2487 |
year := year - 1 - (month negated // 12). |
|
2488 |
month := (12 - (month negated \\ 12)). |
|
2489 |
]. |
|
2490 |
||
2491 |
^ Date newDay:1 month:month year:year. |
|
2492 |
||
2493 |
" |
|
2494 |
(Date newDay:3 month:6 year:2009) firstDayInMonth |
|
2495 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:0 |
|
2496 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:5 |
|
2497 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:6 |
|
2498 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:7 |
|
2499 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:17 |
|
2500 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:18 |
|
2501 |
" |
|
2502 |
! |
|
2503 |
||
699 | 2504 |
subtractDate:aDate |
2505 |
"return the number of days between the receiver and aDate" |
|
2506 |
||
2507 |
^ self asDays - aDate asDays |
|
2508 |
||
2509 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2510 |
(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
|
2511 |
(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
|
2512 |
(Date newDay:1 month:3 year:1994) subtractDate:(Date newDay:1 month:2 year:1994) |
699 | 2513 |
" |
2514 |
! |
|
2515 |
||
2516 |
subtractDays:days |
|
2517 |
"return a new date representing 'days' before the receiver. |
|
2518 |
The argument should be some kind of integer. |
|
2519 |
For ST-80 compatibility" |
|
2520 |
||
2521 |
^ self class fromDays:(self asDays - days) |
|
2522 |
||
2523 |
" |
|
2524 |
Date today subtractDays:7 |
|
92 | 2525 |
" |
1 | 2526 |
! ! |
2527 |
||
2528 |
!Date methodsFor:'comparing'! |
|
2529 |
||
29 | 2530 |
< aDate |
2531 |
"return true, if the date represented by the receiver |
|
2532 |
is before the argument, aDate" |
|
2533 |
||
54 | 2534 |
(aDate isMemberOf:Date) ifTrue:[ |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2535 |
^ dateEncoding < aDate dateEncoding |
54 | 2536 |
]. |
29 | 2537 |
|
54 | 2538 |
"the argument must understand year, month and day to be |
2539 |
comparable, whatever it is" |
|
2540 |
||
17757 | 2541 |
^ 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
|
2542 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2543 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2544 |
Date today < (Date day:24 month:12 year:2000) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2545 |
Date today < (Date day:24 month:12 year:1900) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2546 |
Date today < Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2547 |
Date today-1 < Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2548 |
" |
29 | 2549 |
! |
1 | 2550 |
|
2551 |
= aDate |
|
2552 |
"return true, if the date represented by the receiver |
|
2553 |
is the same as the one represented by argument, aDate" |
|
2554 |
||
155 | 2555 |
(aDate isMemberOf:Date) ifFalse:[^ false]. |
2556 |
||
2557 |
^ dateEncoding = aDate dateEncoding |
|
54 | 2558 |
|
2559 |
"the argument must understand year, month and day to be |
|
2560 |
comparable, whatever it is" |
|
2561 |
||
155 | 2562 |
" |
54 | 2563 |
^ dateEncoding = (Date encodeYear:aDate year |
155 | 2564 |
month:aDate month |
2565 |
day:aDate day) |
|
2566 |
" |
|
68 | 2567 |
"Date today = ((Date today plusDays:7) minusDays:7)" |
92 | 2568 |
! |
2569 |
||
699 | 2570 |
> aDate |
2571 |
"return true, if the date represented by the receiver |
|
2572 |
is after the argument, aDate" |
|
2573 |
||
2574 |
(aDate isMemberOf:Date) ifTrue:[ |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2575 |
^ dateEncoding > aDate dateEncoding |
699 | 2576 |
]. |
2577 |
||
2578 |
"the argument must understand year, month and day to be |
|
2579 |
comparable, whatever it is" |
|
2580 |
||
17757 | 2581 |
^ 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
|
2582 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2583 |
" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2584 |
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
|
2585 |
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
|
2586 |
Date today > Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2587 |
Date today+1 > Timestamp now |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2588 |
" |
699 | 2589 |
! |
2590 |
||
92 | 2591 |
hash |
2592 |
"return an integer useful for hashing on dates" |
|
2593 |
||
2594 |
^ dateEncoding |
|
1 | 2595 |
! ! |
2596 |
||
1501 | 2597 |
!Date methodsFor:'converting'! |
2598 |
||
4408 | 2599 |
asDate |
2600 |
"return the receiver" |
|
2601 |
||
2602 |
^ self |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2603 |
! |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2604 |
|
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2605 |
asTimestamp |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2606 |
"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
|
2607 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2608 |
^ Timestamp |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2609 |
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
|
2610 |
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
|
2611 |
|
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2612 |
" |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2613 |
Date today asTimestamp |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2614 |
" |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
2615 |
! ! |
1501 | 2616 |
|
8201 | 2617 |
!Date methodsFor:'obsolete'! |
2618 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2619 |
asAbsoluteTime |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2620 |
"deprecated, use #asTimestamp" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2621 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2622 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2623 |
self obsoleteMethodWarning:'use #asTimestamp'. |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2624 |
^ self asTimestamp |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2625 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2626 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2627 |
dayCount |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2628 |
"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
|
2629 |
starting with 0 for this date. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2630 |
Date>>fromDays: is the reverse operation. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2631 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2632 |
please use asDays for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2633 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2634 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2635 |
^ self asDays. |
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 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2638 |
dayName |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2639 |
"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
|
2640 |
The returned string depends on the language setting. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2641 |
Expect things like 'monday', 'tuesday' ... |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2642 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2643 |
use #weekday for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2644 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2645 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2646 |
^ self weekday |
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 |
|
8201 | 2649 |
minusDays:days |
2650 |
"return a new date representing 'days' before the receiver. |
|
2651 |
The argument should be some kind of integer. |
|
2652 |
Obsolete: |
|
2653 |
Please dont use this method since it will vanish. |
|
2654 |
Use #subtractDays: instead for ST-80 compatibility." |
|
2655 |
||
2656 |
<resource: #obsolete> |
|
2657 |
||
2658 |
self obsoleteMethodWarning:'use #substractDays:'. |
|
2659 |
^ self subtractDays:days |
|
2660 |
! |
|
2661 |
||
2662 |
plusDays:days |
|
2663 |
"return a new date representing 'days' after the receiver. |
|
2664 |
The argument should be some kind of integer. |
|
2665 |
Obsolete: |
|
2666 |
Please dont use this method since it will vanish. |
|
2667 |
Use #addDays: instead for ST-80 compatibility." |
|
2668 |
||
2669 |
<resource: #obsolete> |
|
2670 |
||
2671 |
self obsoleteMethodWarning:'use #addDays:'. |
|
2672 |
^ self addDays:days |
|
2673 |
! ! |
|
2674 |
||
54 | 2675 |
!Date methodsFor:'printing & storing'! |
1 | 2676 |
|
5778 | 2677 |
addPrintBindingsTo:aDictionary |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2678 |
self addPrintBindingsTo:aDictionary language:nil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2679 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2680 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2681 |
addPrintBindingsTo:aDictionary language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2682 |
"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
|
2683 |
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
|
2684 |
valid format items are: |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2685 |
%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
|
2686 |
%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
|
2687 |
%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
|
2688 |
%y - year, full i.e. 1999, 2004 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2689 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2690 |
special: |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2691 |
%D - day - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2692 |
%M - month - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2693 |
%W - week in year - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2694 |
%Y - year, last 2 digits only i.e. 99, 04 (danger: year 2k bug) |
5778 | 2695 |
|
2696 |
%weekDay - day in week (1->monday, 2->tuesday, ... ,7->sunday) |
|
2697 |
||
2698 |
%dayName - full day name |
|
2699 |
%DayName - full day name, first character uppercase |
|
2700 |
%DAYNAME - full day name, all uppercase |
|
2701 |
||
2702 |
%monthName - full month name |
|
2703 |
%MonthName - full month name, first character uppercase |
|
2704 |
%MONTHNAME - full month name, all uppercase |
|
2705 |
||
2706 |
%shortDayName - short (abbreviated) day name |
|
2707 |
%ShortDayName - short (abbreviated) day name, first character uppercase |
|
2708 |
%SHORTDAYNAME - short (abbreviated) day name, all uppercase |
|
2709 |
||
2710 |
%shortMonthName - short (abbreviated) month name |
|
2711 |
%ShortMonthName - short (abbreviated) month name, first character uppercase |
|
2712 |
%SHORTMONTHNAME - short (abbreviated) month name, all uppercase |
|
2713 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2714 |
%nth - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2715 |
%weekDayNth - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2716 |
%weekNth - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2717 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2718 |
|day ds dsPadded0 dsPaddedB month ms msPadded0 msPaddedB |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2719 |
year weekInYear monthName shortMonthName |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2720 |
dayInWeek dayOfWeek dayName shortDayName ws wsPadded0| |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2721 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2722 |
day := self day. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2723 |
ds := day printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2724 |
dsPaddedB := day printStringLeftPaddedTo:2. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2725 |
dsPadded0 := day printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2726 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2727 |
month := self month. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2728 |
ms := month printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2729 |
msPaddedB := month printStringLeftPaddedTo:2. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2730 |
msPadded0 := month printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2731 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2732 |
year := self year. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2733 |
weekInYear := self weekInYear. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2734 |
ws := weekInYear printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2735 |
wsPadded0 := weekInYear printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2736 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2737 |
dayInWeek := self dayInWeek. "/ 1 .. 7 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2738 |
dayOfWeek := self dayOfWeek. "/ 0 .. 6 |
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 |
monthName := self class nameOfMonth:(self month) language:languageOrNil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2741 |
dayName := self class nameOfDay:dayInWeek language:languageOrNil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2742 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2743 |
aDictionary at:#day put:dsPadded0. "/ 0-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2744 |
aDictionary at:#daypadded put:dsPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2745 |
aDictionary at:#dayPadded put:dsPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2746 |
aDictionary at:#Day put:ds. "/ unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2747 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2748 |
aDictionary at:#month put:msPadded0. "/ 0-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2749 |
aDictionary at:#monthPadded put:msPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2750 |
aDictionary at:#monthpadded put:msPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2751 |
aDictionary at:#Month put:ms. "/ unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2752 |
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
|
2753 |
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
|
2754 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2755 |
aDictionary at:#year put:year. "/ padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2756 |
aDictionary at:#week put:wsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2757 |
aDictionary at:#Week put:ws. |
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 |
year ~~ Date today year ifTrue:[ |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2760 |
aDictionary at:#yearOrTime put:(' ' , year printString). |
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 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2763 |
aDictionary at:$d put:dsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2764 |
aDictionary at:$D put:ds. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2765 |
aDictionary at:$m put:msPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2766 |
aDictionary at:$M put:ms. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2767 |
aDictionary at:$y put:year. |
17747 | 2768 |
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
|
2769 |
aDictionary at:$w put:wsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2770 |
aDictionary at:$W put:ws. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2771 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2772 |
aDictionary at:#monthName put:monthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2773 |
aDictionary at:#monthname put:monthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2774 |
aDictionary at:#MonthName put:monthName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2775 |
aDictionary at:#MONTHNAME put:monthName asUppercase. |
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:#dayName put:dayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2778 |
aDictionary at:#dayname put:dayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2779 |
aDictionary at:#DayName put:dayName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2780 |
aDictionary at:#DAYNAME put:dayName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2781 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2782 |
aDictionary at:#weekDay put:dayInWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2783 |
aDictionary at:#weekday put:dayInWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2784 |
aDictionary at:#weekDayUS put:dayOfWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2785 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2786 |
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
|
2787 |
aDictionary at:#shortdayname put:shortDayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2788 |
aDictionary at:#ShortDayName put:shortDayName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2789 |
aDictionary at:#SHORTDAYNAME put:shortDayName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2790 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2791 |
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
|
2792 |
aDictionary at:#shortmonthname put:shortMonthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2793 |
aDictionary at:#ShortMonthName put:shortMonthName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2794 |
aDictionary at:#SHORTMONTHNAME put:shortMonthName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2795 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2796 |
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
|
2797 |
"/ 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
|
2798 |
aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:dayOfWeek-1 \\ 10 + 1). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2799 |
"/ 0 1 2 3 4 5 6 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2800 |
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
|
2801 |
"/ 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
|
2802 |
! |
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 |
printOn:aStream |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2805 |
"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
|
2806 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2807 |
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
|
2808 |
|
5778 | 2809 |
" |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2810 |
Date today printOn:Transcript. Transcript cr. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2811 |
" |
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 |
"Modified: 27.8.1995 / 01:01:49 / claus" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2814 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2815 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2816 |
printOn:aStream format:aFormatStringOrSqueakFormatArray |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2817 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2818 |
see #addPrintBindingsTo: for a list of valid format strings" |
5778 | 2819 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2820 |
self printOn:aStream format:aFormatStringOrSqueakFormatArray language:nil. |
5778 | 2821 |
|
2822 |
" |
|
2823 |
Date today printOn:Transcript format:'%y%m%d' (iso format) |
|
2824 |
Date today printOn:Transcript format:'%y-%m-%d' (iso format) |
|
2825 |
Date today printOn:Transcript format:'%y-W%w' (iso format - working week) |
|
2826 |
Date today printOn:Transcript format:'%d-%m-%y' (european trivia format) |
|
2827 |
Date today printOn:Transcript format:'%m/%d/%y' (us trivia format) |
|
2828 |
Date today printOn:Transcript format:'%D-%(monthName)-%y' (us trivia format) |
|
2829 |
Date today printOn:Transcript format:'%D-%(MonthName)-%y' (us trivia format) |
|
2830 |
Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
2831 |
Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
2832 |
Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
2833 |
Date today printOn:Transcript format:'%d%m%Y' (millenium bug format - danger) |
|
2834 |
Date today printOn:Transcript format:'Today is the %(weekDay) day of the week' |
|
2835 |
" |
|
7023 | 2836 |
" |
2837 |
String streamContents:[:s | |
|
2838 |
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
|
2839 |
] |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2840 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2841 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2842 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2843 |
printOn:aStream format:aFormatStringOrSqueakFormatArray language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2844 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2845 |
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
|
2846 |
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
|
2847 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2848 |
|dict| |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2849 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2850 |
aFormatStringOrSqueakFormatArray isArray ifTrue:[ |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2851 |
"backward compatibility: a squeak/st80 format array" |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2852 |
self printFormat:aFormatStringOrSqueakFormatArray on:aStream. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2853 |
^ self. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2854 |
]. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2855 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2856 |
dict := IdentityDictionary new. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2857 |
self addPrintBindingsTo:dict language:languageOrNil. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2858 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2859 |
aFormatStringOrSqueakFormatArray expandPlaceholdersWith:dict on:aStream |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2860 |
|
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 |
Date today |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2864 |
printOn:Transcript |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2865 |
format:'%y%m%d' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2866 |
language:#en |
7023 | 2867 |
" |
5778 | 2868 |
! |
2869 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2870 |
printOn:aStream language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2871 |
"append a printed representation of the receiver to aStream. |
8179 | 2872 |
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
|
2873 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2874 |
|format| |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2875 |
|
8118 | 2876 |
(DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[ |
8145 | 2877 |
self class initNames |
8118 | 2878 |
]. |
8179 | 2879 |
format := DefaultFormats at:(languageOrNil ? Language) ifAbsent:[DefaultFormats at:#en]. |
2880 |
self printOn:aStream format:format language:languageOrNil. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2881 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2882 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2883 |
Date today printOn:Transcript language:#en |
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 |
|
8179 | 2886 |
"Modified: / 27-08-1995 / 01:01:49 / claus" |
2887 |
"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
|
2888 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2889 |
|
7023 | 2890 |
printStringFormat:aFormatStringOrArray |
5778 | 2891 |
"print using a format string; |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2892 |
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
|
2893 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2894 |
^ self printStringFormat:aFormatStringOrArray language:nil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2895 |
|
5778 | 2896 |
" |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2897 |
Date today printStringFormat:'%y%m%d' (iso format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2898 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2899 |
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
|
2900 |
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
|
2901 |
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
|
2902 |
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
|
2903 |
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
|
2904 |
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
|
2905 |
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
|
2906 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2907 |
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
|
2908 |
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
|
2909 |
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
|
2910 |
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
|
2911 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2912 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2913 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2914 |
printStringFormat:aFormatStringOrArray language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2915 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2916 |
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
|
2917 |
see #addPrintBindingsTo: for a list of valid format strings" |
5778 | 2918 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2919 |
|s| |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2920 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2921 |
s := WriteStream on:(String new:20). |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2922 |
self printOn:s format:aFormatStringOrArray language:languageOrNil. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2923 |
^ s contents. |
5778 | 2924 |
|
2925 |
" |
|
2926 |
Date today printStringFormat:'%y%m%d' (iso format) |
|
2927 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
|
2928 |
Date today printStringFormat:'%y-W%w' (iso format - working week) |
|
2929 |
Date today printStringFormat:'%d-%m-%y' (european trivia format) |
|
2930 |
Date today printStringFormat:'%m/%d/%y' (us trivia format) |
|
2931 |
Date today printStringFormat:'%D-%(monthName)-%y' (us trivia format) |
|
2932 |
Date today printStringFormat:'%D-%(MonthName)-%y' (us trivia format) |
|
2933 |
Date today printStringFormat:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
2934 |
Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
2935 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
2936 |
Date today printStringFormat:'%d%m%Y' (millenium bug format - danger) |
|
7327 | 2937 |
Date today printStringFormat:'Today is day %(weekDay) of the week' |
2938 |
Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week' |
|
2939 |
Date today printStringFormat:'Today is the %(Day)%(nth) day of the month' |
|
5778 | 2940 |
" |
2941 |
! |
|
2942 |
||
699 | 2943 |
storeOn:aStream |
2944 |
"append a representation to aStream, from which the receiver |
|
2945 |
can be reconstructed" |
|
2946 |
||
2947 |
aStream nextPutAll:'('; nextPutAll:'Date day:'. |
|
2948 |
self day printOn:aStream. |
|
2949 |
aStream nextPutAll:' month:'. |
|
2950 |
self month printOn:aStream. |
|
2951 |
aStream nextPutAll:' year:'. |
|
2952 |
self year printOn:aStream. |
|
2953 |
aStream nextPutAll:')' |
|
2954 |
||
2955 |
" |
|
2956 |
Date today storeOn:Transcript |
|
2957 |
Date today storeString |
|
2958 |
" |
|
1 | 2959 |
! ! |
699 | 2960 |
|
7258 | 2961 |
!Date methodsFor:'private-accessing'! |
699 | 2962 |
|
2963 |
dateEncoding |
|
2964 |
"the internal encoding is stricktly private, |
|
2965 |
and should not be used outside." |
|
2966 |
||
2967 |
^ dateEncoding |
|
2968 |
! |
|
2969 |
||
2970 |
dateEncoding:anInteger |
|
2971 |
"the internal encoding is stricktly private, |
|
2972 |
and should not be used outside." |
|
2973 |
||
2974 |
dateEncoding := anInteger |
|
2975 |
! |
|
2976 |
||
2977 |
fromOSTime:osTime |
|
2978 |
"set my dateEncoding from an OS time. |
|
2979 |
This somewhat clumsy implementation hides the OS's date representation |
|
2980 |
(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
|
2981 |
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
|
2982 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2983 |
|v| |
5858 | 2984 |
|
2985 |
v := OperatingSystem computeTimeAndDateFrom:osTime. |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2986 |
dateEncoding := self class encodeYear:v year month:v month day:v day |
1501 | 2987 |
|
2988 |
"Modified: 1.7.1996 / 15:23:12 / cg" |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2989 |
! |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2990 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2991 |
getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2992 |
"compatibility with Timestamp for comparing" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2993 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2994 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2995 |
((Timestamp epoch addDays:365) asDate asDays - 365) -> 25202 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2996 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2997 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2998 |
^ 1000 * 60*60*24 * (self asDays - 25202) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2999 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3000 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3001 |
Date today asTimestamp getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3002 |
- |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3003 |
Date today getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3004 |
" |
699 | 3005 |
! ! |
3006 |
||
11176 | 3007 |
!Date methodsFor:'visiting'! |
3008 |
||
3009 |
acceptVisitor:aVisitor with:aParameter |
|
3010 |
||
3011 |
^ aVisitor visitDate:self with:aParameter |
|
3012 |
! ! |
|
3013 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
3014 |
!Date class methodsFor:'documentation'! |
699 | 3015 |
|
3016 |
version |
|
17780 | 3017 |
^ '$Id: Date.st 10544 2010-07-12 16:20:36Z vranyj1 $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
3018 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
3019 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
3020 |
version_CVS |
17780 | 3021 |
^ 'Header: /cvs/stx/stx/libbasic/Date.st,v 1.135 2010/03/26 14:26:26 fm Exp ' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
3022 |
! |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
3023 |
|
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
3024 |
version_SVN |
17780 | 3025 |
^ '$Id: Date.st 10544 2010-07-12 16:20:36Z vranyj1 $' |
699 | 3026 |
! ! |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
3027 |
|
699 | 3028 |
Date initialize! |
17767 | 3029 |
|
17772
6e0b3c06c364
Method reverted to r10532
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17767
diff
changeset
|
3030 |
|
17780 | 3031 |