author | Patrik Svestka <patrik.svestka@gmail.com> |
Thu, 02 Dec 2021 12:27:29 +0100 | |
branch | jv |
changeset 25440 | 039a5cea86c3 |
parent 25425 | 21835502e9d7 |
permissions | -rw-r--r-- |
17194 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
25425
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
5 |
COPYRIGHT (c) 2021 LabWare |
155 | 6 |
All Rights Reserved |
1 | 7 |
|
8 |
This software is furnished under a license and may be used |
|
9 |
only in accordance with the terms of that license and with the |
|
10 |
inclusion of the above copyright notice. This software may not |
|
11 |
be provided or otherwise made available to, or used by, any |
|
12 |
other person. No title to or ownership of the software is |
|
13 |
hereby transferred. |
|
14 |
" |
|
5515 | 15 |
"{ Package: 'stx:libbasic' }" |
16 |
||
17419 | 17 |
"{ NameSpace: Smalltalk }" |
18 |
||
54 | 19 |
Magnitude subclass:#Date |
972 | 20 |
instanceVariableNames:'dateEncoding' |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
21 |
classVariableNames:'DayNames MonthNames DayAbbrevs MonthAbbrevs DefaultFormats |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
22 |
ShortFormats LongFormats EnvironmentChange' |
972 | 23 |
poolDictionaries:'' |
7673 | 24 |
category:'Magnitude-Time' |
1 | 25 |
! |
26 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
27 |
!Date class methodsFor:'documentation'! |
54 | 28 |
|
88 | 29 |
copyright |
30 |
" |
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
25425
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
32 |
COPYRIGHT (c) 2021 LabWare |
155 | 33 |
All Rights Reserved |
88 | 34 |
|
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
54 | 44 |
documentation |
45 |
" |
|
92 | 46 |
Instances of Date represent dates as year, month and day encoded in the |
47 |
(private & hidden) instance dateEncoding. The value found there is |
|
17640 | 48 |
year*100*100 + month*100 + day |
49 |
This makes magnitude-like comparison of dates easy, and the main components |
|
50 |
d,m,y are easily reconstructed (assuming, that this is the stuff most used). |
|
51 |
Do not depend on the internal representation - |
|
52 |
it is private and not guaranteed for future versions. |
|
54 | 53 |
|
92 | 54 |
The old representation used days since 1st Jan. 1901 internally - |
55 |
with the new implementation, it is possible to reasonably represent almost |
|
17640 | 56 |
any Date. |
57 |
(which insurance companies will like, |
|
58 |
since they can now represent even very old people's birthday :-) |
|
59 |
||
16971 | 60 |
Notice: |
61 |
no correction for pre-Gregorian dates (< 1583) is done. |
|
62 |
For dates before 1582 (when calendars were changed from Julian to Grgorian), |
|
17640 | 63 |
the so called 'proleptic gregorian calendar' is used. |
64 |
This assumes leap years to continue in the past as if a gregorian calendar was used. |
|
65 |
Thus, 0000 is considered a leap year. |
|
54 | 66 |
|
92 | 67 |
The printed representation of dates is controlled by resource definitions - |
68 |
thus national variants are already supported (see file 'resources/Date.rs'). |
|
69 |
||
70 |
Compatibility notice: |
|
17640 | 71 |
due to historic reasons, there are some methods found twice |
20776 | 72 |
with different names in this class. The old ST/X methods will vanish |
73 |
over time, but kept for a while to support existing applications |
|
74 |
(the info on how these methods should be named |
|
75 |
came somewhat late from the testers...). |
|
76 |
||
77 |
Please do not use methods marked as obsolete. |
|
92 | 78 |
|
79 |
Most useful methods: |
|
80 |
||
1228 | 81 |
Date today |
82 |
(Date today) addDays: |
|
83 |
(Date today) subtractDays: |
|
1295 | 84 |
|
85 |
[author:] |
|
86 |
Claus Gittinger |
|
87 |
||
88 |
[see also:] |
|
89 |
Time AbstractTime |
|
90 |
Filename |
|
91 |
OperatingSystem |
|
54 | 92 |
" |
93 |
! ! |
|
94 |
||
8145 | 95 |
!Date class methodsFor:'initialization'! |
96 |
||
97 |
initDefaultNames |
|
98 |
"read the language specific names." |
|
99 |
||
19558 | 100 |
|enDayNames enDayAbbrevs enMonthNames enMonthAbbrevs| |
8145 | 101 |
|
102 |
DayNames := Dictionary new. |
|
103 |
DayAbbrevs := Dictionary new. |
|
104 |
MonthNames := Dictionary new. |
|
105 |
MonthAbbrevs := Dictionary new. |
|
106 |
DefaultFormats := Dictionary new. |
|
107 |
LongFormats := Dictionary new. |
|
108 |
ShortFormats := Dictionary new. |
|
109 |
||
110 |
enDayNames := #('monday' |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
111 |
'tuesday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
112 |
'wednesday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
113 |
'thursday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
114 |
'friday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
115 |
'saturday' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
116 |
'sunday'). |
8145 | 117 |
|
118 |
enDayAbbrevs := #('mon' |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
119 |
'tue' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
120 |
'wed' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
121 |
'thu' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
122 |
'fri' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
123 |
'sat' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
124 |
'sun'). |
8145 | 125 |
|
126 |
enMonthNames := #('january' |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
127 |
'february' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
128 |
'march' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
129 |
'april' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
130 |
'may' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
131 |
'june' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
132 |
'july' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
133 |
'august' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
134 |
'september' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
135 |
'october' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
136 |
'november' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
137 |
'december'). |
8145 | 138 |
|
139 |
enMonthAbbrevs := #('jan' |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
140 |
'feb' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
141 |
'mar' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
142 |
'apr' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
143 |
'may' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
144 |
'jun' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
145 |
'jul' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
146 |
'aug' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
147 |
'sep' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
148 |
'oct' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
149 |
'nov' |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
150 |
'dec'). |
8145 | 151 |
|
152 |
DayNames at:#'en' put:enDayNames. |
|
153 |
DayAbbrevs at:#'en' put:enDayAbbrevs. |
|
154 |
MonthNames at:#'en' put:enMonthNames. |
|
155 |
MonthAbbrevs at:#'en' put:enMonthAbbrevs. |
|
156 |
||
19558 | 157 |
DefaultFormats at:#'en' put:('%d-%m-%y'). |
158 |
ShortFormats at:#'en' put:('%d-%m-%y'). |
|
159 |
LongFormats at:#'en' put:('%(dayName), %d-%m-%y'). |
|
12812 | 160 |
|
12105 | 161 |
"/ take the "master" language here, for the caching |
162 |
EnvironmentChange := (Smalltalk language asSymbol ~~ #'en'). |
|
8145 | 163 |
|
164 |
" |
|
12812 | 165 |
Date initDefaultNames |
166 |
" |
|
167 |
! |
|
168 |
||
169 |
initNames |
|
170 |
"read the language specific names." |
|
171 |
||
172 |
|lang| |
|
173 |
||
174 |
DayNames isNil ifTrue:[ |
|
175 |
self initDefaultNames. |
|
176 |
]. |
|
177 |
||
178 |
lang := Smalltalk language asSymbol. |
|
179 |
lang ~~ #'en' ifTrue:[ |
|
180 |
self initNamesForLanguage: lang. |
|
181 |
]. |
|
182 |
||
183 |
EnvironmentChange := false |
|
184 |
||
185 |
" |
|
8145 | 186 |
Date initNames |
187 |
" |
|
188 |
! |
|
189 |
||
12812 | 190 |
initNamesForLanguage:language |
8145 | 191 |
"read the language specific names." |
192 |
||
193 |
|resources lang |
|
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
194 |
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
|
195 |
enDefaultFormat enLongFormat enShortFormat may| |
8145 | 196 |
|
8943 | 197 |
DayNames isNil ifTrue:[ |
198 |
self initDefaultNames. |
|
199 |
]. |
|
200 |
||
12812 | 201 |
lang := language asSymbol. |
8145 | 202 |
lang ~~ #'en' ifTrue:[ |
14624
58ad30334e84
care for libview not being present (tinytalk)
Claus Gittinger <cg@exept.de>
parents:
14498
diff
changeset
|
203 |
ResourcePack notNil ifTrue:[ "/ guard for tinytalk (no libview) |
58ad30334e84
care for libview not being present (tinytalk)
Claus Gittinger <cg@exept.de>
parents:
14498
diff
changeset
|
204 |
resources := ResourcePack forPackage:'stx:libbasic' resourceFileName:(language,'.rs') cached:false. |
58ad30334e84
care for libview not being present (tinytalk)
Claus Gittinger <cg@exept.de>
parents:
14498
diff
changeset
|
205 |
]. |
12812 | 206 |
resources notNil ifTrue:[ |
8196
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
207 |
enDayNames := DayNames at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
208 |
enDayAbbrevs := DayAbbrevs at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
209 |
enMonthNames := MonthNames at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
210 |
enMonthAbbrevs := MonthAbbrevs at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
211 |
monthAbbrevKeys := enMonthAbbrevs copy. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
212 |
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
|
213 |
|
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
214 |
enDefaultFormat := DefaultFormats at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
215 |
enShortFormat := ShortFormats at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
216 |
enLongFormat := LongFormats at:#'en'. |
3b3407d69207
special care for may (same key for long & short name)
Claus Gittinger <cg@exept.de>
parents:
8179
diff
changeset
|
217 |
|
12812 | 218 |
DefaultFormats at:lang put:(resources at:'DATEFORMAT' default:enDefaultFormat). |
219 |
ShortFormats at:lang put:(resources at:'SHORTDATEFORMAT' default:enShortFormat). |
|
220 |
LongFormats at:lang put:(resources at:'LONGDATEFORMAT' default:enLongFormat). |
|
221 |
||
222 |
DayNames at:lang put:(resources array:enDayNames). |
|
223 |
DayAbbrevs at:lang put:(resources array:enDayAbbrevs). |
|
224 |
MonthNames at:lang put:(resources array:enMonthNames). |
|
225 |
MonthAbbrevs at:lang put:(resources array:monthAbbrevKeys). |
|
226 |
"/ may needs special care (same key for long and short name) |
|
227 |
may := resources string:'MAY_ABBREV' default:nil. |
|
228 |
may isNil ifTrue:[ |
|
229 |
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
|
230 |
]. |
12812 | 231 |
(MonthAbbrevs at:lang) at:5 put:may. |
8145 | 232 |
]. |
233 |
]. |
|
234 |
||
235 |
" |
|
12812 | 236 |
Date initNamesForLanguage:#de. |
237 |
Date initNamesForLanguage:#fr. |
|
238 |
Date initNamesForLanguage:#es. |
|
8145 | 239 |
" |
13736
599f4686a493
comment/format in: #initNamesForLanguage:
Claus Gittinger <cg@exept.de>
parents:
13509
diff
changeset
|
240 |
|
599f4686a493
comment/format in: #initNamesForLanguage:
Claus Gittinger <cg@exept.de>
parents:
13509
diff
changeset
|
241 |
"Modified (format): / 28-09-2011 / 15:56:41 / cg" |
8145 | 242 |
! |
243 |
||
244 |
initialize |
|
8943 | 245 |
DayNames isNil ifTrue:[ |
246 |
self initDefaultNames. |
|
247 |
]. |
|
8145 | 248 |
|
249 |
Smalltalk addDependent:self. |
|
18926 | 250 |
Smalltalk language ~= 'en' ifTrue:[ |
8145 | 251 |
EnvironmentChange := true |
252 |
] |
|
253 |
! ! |
|
254 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
255 |
!Date class methodsFor:'instance creation'! |
699 | 256 |
|
257 |
fromDays:dayCount |
|
258 |
"return a new Date, given the day-number starting with 0 at 1.Jan 1901; |
|
259 |
(i.e. 'Date fromDays:0' returns 1st Jan. 1901). |
|
260 |
Date asDays is the reverse operation. |
|
16927 | 261 |
Notice, that this is not able to represent dates before 1901!!. |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
262 |
Added for GNU/ST-80 compatibility" |
699 | 263 |
|
18357 | 264 |
|year rest d yearIncrement yearAsDays| |
699 | 265 |
|
266 |
"approx. year" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
267 |
year := (dayCount // 366) + 1901. |
18357 | 268 |
yearAsDays := (self yearAsDays:year). |
269 |
||
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
270 |
dayCount < 0 ifTrue:[ |
18357 | 271 |
rest := dayCount negated - yearAsDays + 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
|
272 |
yearIncrement := -1. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
273 |
] ifFalse:[ |
18357 | 274 |
rest := dayCount - yearAsDays + 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
|
275 |
yearIncrement := 1. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
276 |
]. |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
277 |
rest > 365 ifTrue:[ |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
278 |
[d := self daysInYear:year. rest > d] whileTrue:[ |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
279 |
"adjust" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
280 |
year := year + yearIncrement. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
281 |
rest := rest - d. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
282 |
]. |
699 | 283 |
]. |
284 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
285 |
^ self newDay:rest year:year |
699 | 286 |
|
287 |
" |
|
288 |
Date fromDays:0 -> 1 jan 1901 |
|
289 |
Date fromDays:365 -> 1 jan 1902 |
|
290 |
Date fromDays:730 -> 1 jan 1903 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
291 |
Date fromDays:1095 -> 1 jan 1904 |
699 | 292 |
Date fromDays:1460 ->31 dec 1904 since 1904 was a leap year |
293 |
" |
|
294 |
||
1501 | 295 |
"Modified: 1.7.1996 / 14:24:25 / cg" |
699 | 296 |
! |
297 |
||
16927 | 298 |
fromDaysFrom0:dayCount |
299 |
"return a new Date, given the day-number starting with 0 at 1.Jan 0; |
|
300 |
(i.e. 'Date fromDaysSince0:0' returns 1st Jan. 0). |
|
301 |
Date asDaysSince0 is the reverse operation. |
|
18444 | 302 |
Notice, that this is a private interface. |
303 |
Also notice: does not care for Gregorian/Julisn calendar change" |
|
16927 | 304 |
|
18357 | 305 |
|year rest d yearIncrement yearAsDaysFrom0| |
16927 | 306 |
|
307 |
"approx. year" |
|
308 |
year := (dayCount // 366). |
|
18357 | 309 |
yearAsDaysFrom0 := (self yearAsDaysFrom0:year). |
310 |
||
16927 | 311 |
dayCount < 0 ifTrue:[ |
18357 | 312 |
rest := dayCount negated - yearAsDaysFrom0 + 1. "+1 for ST-80 compatibility" |
16927 | 313 |
yearIncrement := -1. |
314 |
] ifFalse:[ |
|
18357 | 315 |
rest := dayCount - yearAsDaysFrom0 + 1. "+1 for ST-80 compatibility" |
16927 | 316 |
yearIncrement := 1. |
317 |
]. |
|
318 |
rest > 365 ifTrue:[ |
|
319 |
[d := self daysInYear:year. rest > d] whileTrue:[ |
|
320 |
"adjust" |
|
321 |
year := year + yearIncrement. |
|
322 |
rest := rest - d. |
|
323 |
]. |
|
324 |
]. |
|
325 |
||
326 |
^ self newDay:rest year:year |
|
327 |
||
328 |
" |
|
18357 | 329 |
Date fromDaysFrom0:0 -> 1 jan 0 |
330 |
Date fromDaysFrom0:366 -> 1 jan 1 |
|
16927 | 331 |
" |
332 |
! |
|
333 |
||
699 | 334 |
newDay:dayInYear year:year |
335 |
"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
|
336 |
See also: Date today / Time now / Timestamp now. |
699 | 337 |
ST-80 compatibility" |
338 |
||
339 |
|monthAndDay| |
|
340 |
||
19896 | 341 |
((dayInYear between:1 and:365) |
342 |
or:[dayInYear == 366 and:[self leapYear:year]]) ifFalse:[ |
|
343 |
" |
|
344 |
this error is triggered, when you try to create a |
|
345 |
day from an invalid day-in-year; |
|
346 |
for example, 366 in a non-leap year. |
|
347 |
I don't know, if ST-80 wraps to the next year(s) in this case. |
|
348 |
" |
|
349 |
^ self conversionErrorSignal raiseErrorString:' - Date: invalid day in year'. |
|
699 | 350 |
]. |
351 |
monthAndDay := self monthAndDayFromDayInYear:dayInYear forYear:year. |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
352 |
^ self basicNew year:year month:(monthAndDay at:1) day:(monthAndDay at:2) |
699 | 353 |
|
354 |
" |
|
355 |
Date newDay:150 year:1994 |
|
356 |
Date newDay:1 year:1994 |
|
357 |
Date newDay:1 year:1901 |
|
358 |
Date newDay:1 year:1902 |
|
359 |
Date newDay:365 year:1992 |
|
360 |
Date newDay:366 year:1992 |
|
361 |
Date newDay:365 year:1994 |
|
362 |
Date newDay:366 year:1994 |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
363 |
Date newDay:0 year:1994 |
16913 | 364 |
|
365 |
Date newDay:271 year:2008 |
|
366 |
Date newDay:270 year:2008 |
|
367 |
Date newDay:271 year:2007 |
|
699 | 368 |
" |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
369 |
|
1501 | 370 |
"Modified: 1.7.1996 / 14:22:24 / cg" |
699 | 371 |
! |
372 |
||
16913 | 373 |
newDayInWeek:dayInWeek week:week year:yearArg |
374 |
"return a new Date, given the year, the week (1..) and the day in week (1..7). |
|
375 |
See http://en.wikipedia.org/wiki/ISO_week_date" |
|
376 |
||
377 |
|weekDayOfJan4 dayInYear year| |
|
378 |
||
379 |
year := yearArg. |
|
21217 | 380 |
weekDayOfJan4 := (self year:year month:1 day:4) dayInWeek. |
16913 | 381 |
dayInYear := (week * 7) + dayInWeek - (weekDayOfJan4 + 3). |
382 |
dayInYear < 1 ifTrue:[ |
|
21217 | 383 |
dayInYear := dayInYear + (self daysInYear:year-1). |
16913 | 384 |
year := year - 1. |
385 |
]. |
|
21217 | 386 |
dayInYear > (self daysInYear:year) ifTrue:[ |
387 |
dayInYear := dayInYear - (self daysInYear:year). |
|
16913 | 388 |
year := year + 1. |
389 |
]. |
|
21217 | 390 |
^ self newDay:dayInYear year:year. |
16913 | 391 |
|
392 |
" |
|
393 |
Date newDayInWeek:6 week:39 year:2008 |
|
394 |
Date newDayInWeek:1 week:40 year:2014 |
|
395 |
Date newDayInWeek:1 week:44 year:2014 |
|
396 |
" |
|
397 |
! |
|
398 |
||
18444 | 399 |
readFrom:aStringOrStream format:aSqueakFormatArrayOrFormatString |
4997 | 400 |
"return a new Date, reading a printed representation from aStream. |
7649 | 401 |
aSqueakFormatArrayOrFormatString may either be a squeak formatArray |
402 |
1 day position (1, 2 or 3) |
|
403 |
2 month position (1..3) |
|
404 |
3 year position (1..3) |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
405 |
or a formatString (see printing instance protocol)." |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
406 |
|
7649 | 407 |
^ self |
408 |
readFrom:aStringOrStream |
|
18444 | 409 |
format:aSqueakFormatArrayOrFormatString |
19896 | 410 |
onError:[ self conversionErrorSignal raiseWith:aStringOrStream errorString:' - invalid Date' ] |
4997 | 411 |
|
412 |
" |
|
18444 | 413 |
Date readFrom:'19:11:1999' format:#( 1 2 3 ) |
414 |
Date readFrom:'19-nov-1999' format:#( 1 2 3 ) |
|
415 |
Date readFrom:'19:11:1999' format:#( 2 1 3 ) -> exception: wrong month |
|
416 |
Date readFrom:'5:12:1999' format:#( 2 1 3 ) |
|
417 |
Date readFrom:'may-12-1999' format:#( 2 1 3 ) |
|
418 |
Date readFrom:'1999 may 12' format:#( 3 2 1 ) |
|
419 |
Date readFrom:'12/31/2001' format:#( 2 1 3 ) |
|
420 |
Date readFrom:' 31.08.2001' format:#( 1 2 3 ) |
|
421 |
Date readFrom:' 31.dec.2001' format:#( 1 2 3 ) |
|
422 |
Date readFrom:' 31.Dec.2001' format:#( 1 2 3 ) |
|
423 |
Date readFrom:' 31.dez.2001' format:#( 1 2 3 ) |
|
424 |
||
425 |
Date readFrom:'31/12/01' format:'%d %m %y' onError:'fail' |
|
426 |
Date readFrom:'12/01' format:'%m %y' onError:'fail' |
|
427 |
Date readFrom:'01' format:'%y' onError:'fail' |
|
428 |
Date readFrom:'30.01' format:'%d %m' onError:'fail' |
|
4997 | 429 |
" |
430 |
||
431 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
432 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
433 |
! |
|
434 |
||
18444 | 435 |
readFrom:aStringOrStream format:aFormatStringOrSqueakFormatArray language:languageOrNil onError:exceptionBlock |
4997 | 436 |
"return a new Date, reading a printed representation from aStream. |
16834 | 437 |
aFormatStringOrSqueakFormatArray may either be a squeak formatArray |
7649 | 438 |
1 day position (1, 2 or 3) |
439 |
2 month position (1..3) |
|
440 |
3 year position (1..3) |
|
441 |
or a formatString (see printing instance protocol). |
|
18446 | 442 |
For now %d, %m, %monthName, %shortMonthName, %y, %Y, %y1900, %y2000, %y1950 and %y1980 are supported in the formatString. |
443 |
y1900 converts 2-digit year YY into 19YY, |
|
444 |
y2000 into 20YY. |
|
445 |
y1950, y1980 and Y are special; |
|
446 |
if the year is below 50/80/70, it is converted to 20YY, otherwise to 19YY. |
|
18443 | 447 |
The formatString can have any of these characters '-.:,;/' as separator. |
448 |
The format may be preceeded by a single numeric length (as in %2d) to specify how many |
|
449 |
characters to read. |
|
12812 | 450 |
The formatString can also use a space as separator (for ex. '%d %m %y') and any separator will be allowed. |
451 |
However, when a character separator is defined, only that separator will be expected. |
|
7649 | 452 |
TODO: make this a general feature of all DateAndTime classes. |
4997 | 453 |
" |
454 |
||
16835 | 455 |
|str| |
7649 | 456 |
|
457 |
str := aStringOrStream readStream. |
|
458 |
||
16835 | 459 |
[ |
18448 | 460 |
|day month year dayOfYear monthAndDay| |
16835 | 461 |
|
462 |
aFormatStringOrSqueakFormatArray isArray ifTrue:[ |
|
463 |
|arg| |
|
464 |
||
465 |
arg := Array new:3. |
|
466 |
||
19712 | 467 |
1 to:3 do:[:i| |
468 |
|v| |
|
469 |
||
16835 | 470 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
471 |
||
472 |
v := (str peek isDigit) ifTrue:[Integer readFrom:str] |
|
473 |
ifFalse:[str nextAlphaNumericWord]. |
|
474 |
arg at:i put:v |
|
475 |
]. |
|
476 |
year := arg at:(aFormatStringOrSqueakFormatArray at:3). |
|
477 |
day := arg at:(aFormatStringOrSqueakFormatArray at:1). |
|
478 |
month := arg at:(aFormatStringOrSqueakFormatArray at:2). |
|
7649 | 479 |
] ifFalse:[ |
18443 | 480 |
|formatStream fc c sel somePartAssoc len lStr| |
16835 | 481 |
|
482 |
formatStream := aFormatStringOrSqueakFormatArray readStream. |
|
483 |
||
484 |
[formatStream atEnd] whileFalse:[ |
|
485 |
fc := formatStream next. |
|
486 |
fc == $% ifTrue:[ |
|
487 |
sel := ''. |
|
18443 | 488 |
len := nil. |
489 |
(fc := formatStream peekOrNil) notNil ifTrue:[ |
|
490 |
fc isDigit ifTrue:[ |
|
491 |
len := fc digitValue. |
|
492 |
formatStream next. |
|
493 |
] |
|
494 |
]. |
|
495 |
||
16835 | 496 |
(fc := formatStream peekOrNil) notNil ifTrue:[ |
17466 | 497 |
fc == $( ifTrue:[ |
16835 | 498 |
formatStream next. |
499 |
sel := formatStream upTo:$) |
|
7649 | 500 |
] ifFalse:[ |
16835 | 501 |
sel := sel , (formatStream throughAnyForWhich:[:ch | ch isLetter]) |
7649 | 502 |
] |
16835 | 503 |
]. |
18443 | 504 |
len notNil ifTrue:[ |
505 |
lStr := str next:len. |
|
506 |
somePartAssoc := self readDatePartFrom:lStr readStream format:sel language:languageOrNil. |
|
507 |
] ifFalse:[ |
|
508 |
somePartAssoc := self readDatePartFrom:str format:sel language:languageOrNil. |
|
509 |
]. |
|
16835 | 510 |
somePartAssoc key == #day ifTrue:[ |
511 |
day := somePartAssoc value. |
|
512 |
] ifFalse:[somePartAssoc key == #month ifTrue:[ |
|
513 |
month := somePartAssoc value. |
|
514 |
] ifFalse:[somePartAssoc key == #year ifTrue:[ |
|
515 |
year := somePartAssoc value. |
|
18448 | 516 |
] ifFalse:[somePartAssoc key == #dayOfYear ifTrue:[ |
517 |
dayOfYear := somePartAssoc value. |
|
7649 | 518 |
] ifFalse:[ |
19896 | 519 |
self conversionErrorSignal raiseWith:aStringOrStream errorString:' - unexpected date part' |
18448 | 520 |
]]]]. |
16835 | 521 |
] ifFalse:[ |
522 |
fc == Character space ifTrue:[ |
|
523 |
"/ Skip most possible separator characters |
|
524 |
"/ (if not enough, should check for isNationalAlphaNumeric instead) |
|
525 |
[(c := str peek) isSeparator |
|
526 |
or:[ '-.:,;/\|?<>[]{}()#@!!$&^+=~*_"`' includes:c]] whileTrue:[str next]. |
|
527 |
] ifFalse:[ |
|
528 |
str skipSeparators. |
|
529 |
str next ~= fc ifTrue:[^ exceptionBlock value]. |
|
530 |
str skipSeparators. |
|
7649 | 531 |
] |
16835 | 532 |
] |
533 |
]. |
|
4997 | 534 |
]. |
7649 | 535 |
|
18448 | 536 |
dayOfYear notNil ifTrue:[ |
21217 | 537 |
monthAndDay := self monthAndDayFromDayInYear:dayOfYear forYear:year. |
18448 | 538 |
month := (monthAndDay at:1). |
539 |
day := (monthAndDay at:2). |
|
540 |
]. |
|
541 |
||
16835 | 542 |
day isNil ifTrue:[ day := 1 ]. |
543 |
month isNil ifTrue:[ month := 1 ]. |
|
21217 | 544 |
year isNil ifTrue:[ year := self today year ]. |
16835 | 545 |
|
546 |
(year between:0 and:99) ifTrue:[ |
|
547 |
year := UserPreferences current twoDigitDateHandler value:year. |
|
548 |
]. |
|
19712 | 549 |
^ self year:year month:month day:day. |
8878 | 550 |
] on:Error do:[:ex| ^ exceptionBlock value]. |
4997 | 551 |
|
552 |
" |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
553 |
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
|
554 |
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
|
555 |
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
|
556 |
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
|
557 |
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
|
558 |
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
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
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
|
563 |
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
|
564 |
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
|
565 |
|
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
566 |
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
|
567 |
Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail' |
7649 | 568 |
|
569 |
Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail' |
|
570 |
Date readFrom:'12/01' printFormat:'%m %y' onError:'fail' |
|
571 |
Date readFrom:'01' printFormat:'%y' onError:'fail' |
|
12812 | 572 |
Date readFrom:'30.01' printFormat:'%d %m' onError:'fail' |
18443 | 573 |
Date readFrom:'300180' printFormat:'%2d%2m%2y' onError:'fail' |
574 |
||
575 |
Date readFrom:'300170' printFormat:'%2d%2m%2y' onError:'fail' - gives 2070 as year |
|
18446 | 576 |
Date readFrom:'300170' printFormat:'%2d%2m%2Y' onError:'fail' - gives 1970 as year |
577 |
Date readFrom:'300169' printFormat:'%2d%2m%2y' onError:'fail' - gives 2069 as year |
|
578 |
Date readFrom:'300169' printFormat:'%2d%2m%2Y' onError:'fail' - gives 2069 as year |
|
579 |
||
18443 | 580 |
Date readFrom:'300170' printFormat:'%2d%2m%2(y1950)' onError:'fail' - gives 1970 as year |
581 |
Date readFrom:'300170' printFormat:'%2d%2m%2(y1980)' onError:'fail' - gives 2070 as year |
|
582 |
Date readFrom:'300181' printFormat:'%2d%2m%2(y1980)' onError:'fail' - gives 1981 as year |
|
12812 | 583 |
|
18448 | 584 |
Date readFrom:'2015103' printFormat:'%4y%3(dayOfYear)' onError:'fail' |
585 |
||
12812 | 586 |
Date readFrom:'3-3-1995' printFormat:'%d %m %y' language: #de onError:'fail' |
17194 | 587 |
Date readFrom:'3-März-1995' printFormat:'%d %monthName %y' language: #de onError:'fail' |
588 |
Date readFrom:'3-mär-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail' |
|
589 |
Date readFrom:'3/mär/1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail' |
|
590 |
Date readFrom:'3/mär/1995' printFormat:'%d-%shortMonthName-%y' language: #de onError:'fail' |
|
12812 | 591 |
Date readFrom:'3-dez-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail' |
592 |
Date readFrom:'3-Dez-1995' printFormat:'%d %shortMonthName %y' language: #de onError:'fail' |
|
593 |
Date readFrom:'3-Dezember-1995' printFormat:'%d %monthName %y' language: #de onError:'fail' |
|
594 |
||
4421 | 595 |
" |
596 |
||
597 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
598 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
599 |
! |
|
600 |
||
18444 | 601 |
readFrom:aStringOrStream format:aSqueakFormatArrayOrFormatString onError:exceptionBlock |
11786 | 602 |
"return a new Date, reading a printed representation from aStream. |
603 |
aSqueakFormatArrayOrFormatString may either be a squeak formatArray |
|
604 |
1 day position (1, 2 or 3) |
|
605 |
2 month position (1..3) |
|
606 |
3 year position (1..3) |
|
607 |
or a formatString (see printing instance protocol). |
|
608 |
All of the %-formats as in the printString are supported here. |
|
609 |
(i.e. %d, %m and %y, %shortMonthName and %monthName) |
|
18446 | 610 |
In addition, %Y, %y1900, %y2000, %y1950 and %y1980 are supported: |
18443 | 611 |
y1900 converts 2-digit year YY into 19YY, y2000 into 20YY. |
18446 | 612 |
y1950, y1980 and Y are special; if the year is below 50/80/70, it is converted to 20YY, otherwise to 19YY. |
11786 | 613 |
TODO: make this a general feature of all DateAndTime classes. |
614 |
" |
|
615 |
||
616 |
^ self |
|
617 |
readFrom:aStringOrStream |
|
18444 | 618 |
format:aSqueakFormatArrayOrFormatString |
11786 | 619 |
language:nil |
620 |
onError:exceptionBlock |
|
621 |
||
622 |
" |
|
18444 | 623 |
Date readFrom:'31 December 1992' format:#(1 2 3) onError:'fail' |
624 |
Date readFrom:'19:11:1999' format:#(1 2 3) onError:'fail' |
|
625 |
Date readFrom:'December, 5 1992' format:#(1 2 3) onError:'fail' |
|
626 |
Date readFrom:'3-jan-95' format:#(1 2 3) onError:'fail' |
|
627 |
Date readFrom:'12/31/1992' format:#(1 2 3) onError:'fail' |
|
628 |
Date readFrom:'15.4.1992' format:#(1 2 3) onError:'wrong date' -> german |
|
629 |
Date readFrom:'10.4.1992' format:#(1 2 3) onError:'fail' -> german |
|
630 |
Date readFrom:'10.4.1992' format:#(1 2 3) onError:['wrong date'] |
|
631 |
Date readFrom:'32.4.1992' format:#(1 2 3) onError:['wrong date'] |
|
632 |
Date readFrom:'fooBar' format:#(1 2 3) onError:['wrong date'] |
|
633 |
Date readFrom:'10.4' format:#(1 2 3) onError:['wrong date'] |
|
634 |
Date readFrom:'10041999' format:#(1 2 3) onError:['wrong date'] |
|
635 |
||
636 |
Date readFrom:'31/12/92' format:#(1 2 3) onError:'fail' |
|
637 |
Date readFrom:'31/12/01' format:#(1 2 3) onError:'fail' |
|
638 |
||
639 |
Date readFrom:'31/12/01' format:'%d %m %y' onError:'fail' |
|
640 |
Date readFrom:'12/01' format:'%m %y' onError:'fail' |
|
641 |
Date readFrom:'01' format:'%y' onError:'fail' |
|
642 |
Date readFrom:'30.01' format:'%d %m' onError:'fail' |
|
643 |
Date readFrom:'311201' format:'%2d%2m%2y' onError:'fail' |
|
644 |
" |
|
645 |
||
646 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
647 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
648 |
! |
|
649 |
||
650 |
readFrom:aStringOrStream onError:exceptionBlock |
|
651 |
"return a new Date, reading a printed representation from aStream. |
|
652 |
Notice, that this is not the storeString format and |
|
653 |
is different from the format expected by readFrom:. |
|
654 |
||
655 |
BUG: |
|
656 |
For Smalltalk compatibility, this method handles american format (i.e. month/day/year), |
|
657 |
the common format with letter month in the middle (10 December 2007) |
|
658 |
and ISO format (yyyy-mm-dd) - as long as yyyy is > 12. |
|
659 |
||
660 |
It does NOT handle the german/french and other dd-mm-yyyy formats. |
|
661 |
use readFrom:printFormat:onError: for this." |
|
662 |
||
663 |
^ [ |
|
664 |
|str items first second month day year| |
|
665 |
str := aStringOrStream readStream. |
|
666 |
||
667 |
items := #(1 2 3) collect:[:idx| |
|
668 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
|
669 |
(str peek isDigit) ifTrue:[ |
|
670 |
Integer readFrom:str |
|
671 |
] ifFalse:[ |
|
672 |
str nextAlphaNumericWord |
|
673 |
]. |
|
674 |
]. |
|
675 |
||
676 |
first := items at:1. |
|
677 |
second := items at:2. |
|
678 |
||
679 |
(first isInteger and:[second isInteger and:[first > 12]]) ifTrue:[ |
|
680 |
"ISO Date: yyyy-mm-dd" |
|
681 |
year := first. |
|
682 |
month := second. |
|
683 |
day := items at:3. |
|
684 |
] ifFalse:[ |
|
685 |
second isInteger ifTrue:[ |
|
686 |
"must be an american date mm/dd/yy" |
|
687 |
month := first. |
|
688 |
day := second. |
|
689 |
] ifFalse:[ |
|
690 |
"3 Dec 2007" |
|
691 |
day := first. |
|
692 |
month := second. |
|
693 |
]. |
|
694 |
year := items at:3. |
|
695 |
]. |
|
696 |
(year between:0 and:99) ifTrue:[ |
|
697 |
year := UserPreferences current twoDigitDateHandler value:year. |
|
698 |
]. |
|
19712 | 699 |
self year:year month:month day:day. |
18444 | 700 |
] on:Error do:exceptionBlock. |
701 |
||
702 |
" |
|
703 |
Date readFromString:'31 December 1992' |
|
704 |
Date readFrom:'19:11:1999' |
|
705 |
Date readFrom:'2007-12-31' onError:'wrong date'. |
|
706 |
Date readFromString:'December, 5 1992' |
|
707 |
Date readFromString:'12/31/1992' |
|
708 |
Date readFromString:'3-jan-95' |
|
709 |
Date readFromString:'3-jan-01' |
|
710 |
Date readFromString:'12/31/01' |
|
711 |
Date readFromString:'15.4.1992' -> german; leads to an error |
|
712 |
Date readFromString:'10.4.1992' -> german; leads to a wrong date |
|
713 |
Date readFromString:'10.4.1992' onError:['wrong date'] |
|
714 |
Date readFromString:'32.4.1992' onError:['wrong date'] |
|
715 |
Date readFromString:'fooBar' onError:['wrong date'] |
|
716 |
Date readFromString:'10.4' onError:['wrong date'] |
|
717 |
Date readFromString:'10041999' onError:['wrong date'] |
|
11786 | 718 |
" |
719 |
||
720 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
721 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
722 |
! |
|
723 |
||
699 | 724 |
today |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
725 |
"return a date, representing today. |
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
726 |
See also: Time now / Timestamp now." |
699 | 727 |
|
1501 | 728 |
^ self fromOSTime:(OperatingSystem getOSTime) |
699 | 729 |
|
730 |
" |
|
731 |
Date today |
|
732 |
" |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
733 |
|
1501 | 734 |
"Modified: 1.7.1996 / 15:20:16 / cg" |
5548 | 735 |
! |
736 |
||
737 |
tomorrow |
|
738 |
"return a date, representing tomorrow. |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
739 |
See also: Time now / Timestamp now." |
5548 | 740 |
|
21217 | 741 |
^ self today addDays:1 |
5548 | 742 |
|
743 |
" |
|
744 |
Date tomorrow |
|
745 |
Date tomorrow dayInWeek |
|
746 |
" |
|
747 |
! |
|
748 |
||
13234 | 749 |
utcToday |
17135 | 750 |
"return a date, representing today in UTC. |
751 |
That is, the current date in London without any daylight saving adjustments. |
|
13234 | 752 |
See also: Time now / Timestamp now." |
753 |
||
754 |
^ self new fromUtcOSTime:(OperatingSystem getOSTime) |
|
755 |
||
756 |
" |
|
757 |
Date today |
|
758 |
Date utcToday |
|
759 |
" |
|
760 |
||
761 |
"Modified: 1.7.1996 / 15:20:16 / cg" |
|
762 |
! |
|
763 |
||
19712 | 764 |
year:year month:month day:day |
765 |
"return a new Date, given the day, month and year. |
|
766 |
For your convenience, month may be either an integer |
|
767 |
or the month's name as a string. |
|
768 |
||
769 |
WARNING: semantics changed: 0..99 is no longer treated as 1900..1999, |
|
770 |
but as 0..99 now. |
|
771 |
Any such adjustments must be made by the caller of this method now |
|
772 |
(see those, for example readFrom:onError:)" |
|
773 |
||
774 |
|monthIndex ok| |
|
775 |
||
776 |
(year < 100 and:[year > 0]) ifTrue:[ |
|
777 |
'Date [warning]: year in [0..99] no longer converted to [1900..1999]' infoPrintCR. |
|
778 |
]. |
|
779 |
year class ~= SmallInteger ifTrue:[ |
|
780 |
"we support a lot of future, but LargeInteger years fail in #isLeapYear" |
|
19896 | 781 |
self conversionErrorSignal raiseWith:year errorString:' - invalid year in Date (way too large)'. |
19712 | 782 |
]. |
783 |
month isInteger ifTrue:[ |
|
784 |
monthIndex := month |
|
785 |
] ifFalse:[ |
|
786 |
monthIndex := self indexOfMonth:month |
|
787 |
]. |
|
788 |
(monthIndex == 2 and:[day == 29]) ifTrue:[ |
|
789 |
ok := self leapYear:year |
|
790 |
] ifFalse:[ |
|
791 |
ok := day <= (self daysInMonth:month forYear:year) |
|
792 |
]. |
|
793 |
((day > 0) and:[ok]) ifTrue:[ |
|
794 |
^ self basicNew year:year month:monthIndex day:day. |
|
795 |
]. |
|
796 |
||
797 |
"this error is triggered if you try to create a date from an |
|
798 |
invalid year/month/day combination; |
|
799 |
Such as 29-feb-year, where year is no leap year |
|
800 |
" |
|
801 |
self conversionErrorSignal raiseErrorString:' - invalid date'. |
|
802 |
||
803 |
" |
|
804 |
Date year:1993 month:'may' day:8 |
|
805 |
Date year:1993 month:5 day:8 |
|
806 |
Date year:2004 month:'feb' day:29 |
|
807 |
Date year:2003 month:'feb' day:29 |
|
808 |
Date year:5 month:'feb' day:28 |
|
809 |
Date year:95 month:'feb' day:28 |
|
810 |
" |
|
811 |
! |
|
812 |
||
5548 | 813 |
yesterday |
814 |
"return a date, representing yesterday. |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
815 |
See also: Time now / Timestamp now." |
5548 | 816 |
|
21217 | 817 |
^ self today subtractDays:1 |
5548 | 818 |
|
819 |
" |
|
820 |
Date yesterday |
|
821 |
Date yesterday dayInWeek |
|
822 |
" |
|
699 | 823 |
! ! |
824 |
||
25425
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
825 |
|
7299 | 826 |
!Date class methodsFor:'Compatibility-Dolphin'! |
6872 | 827 |
|
828 |
newDay:day monthIndex:month year:year |
|
17419 | 829 |
"Dolphin compatibility - same as newDay:month:year" |
830 |
||
19712 | 831 |
^ self year:year month:month day:day |
6872 | 832 |
|
833 |
" |
|
834 |
Date newDay:8 monthIndex:5 year:1993 |
|
835 |
" |
|
836 |
||
837 |
"Modified: 19.4.1996 / 15:28:15 / cg" |
|
838 |
! ! |
|
839 |
||
7646 | 840 |
!Date class methodsFor:'Compatibility-ST80'! |
841 |
||
7648 | 842 |
newDay:day monthNumber:monthIndex year:year |
7646 | 843 |
"ST80 compatibility" |
844 |
||
19712 | 845 |
^ self year:year month:monthIndex day:day |
7646 | 846 |
! ! |
847 |
||
7299 | 848 |
!Date class methodsFor:'Compatibility-Squeak'! |
7005 | 849 |
|
11815 | 850 |
current |
851 |
"return the current date" |
|
852 |
||
853 |
^ self today |
|
854 |
||
855 |
" |
|
856 |
Date current |
|
857 |
" |
|
858 |
! |
|
859 |
||
7005 | 860 |
fromSeconds:seconds |
861 |
"Answer an instance of me which is 'seconds' seconds after January 1, 1901." |
|
862 |
||
863 |
| secondsInDay | |
|
864 |
||
865 |
secondsInDay := 24 * 60 * 60. |
|
866 |
^self fromDays: seconds // secondsInDay |
|
867 |
||
868 |
" |
|
869 |
Date fromSeconds:0 |
|
870 |
Date fromSeconds:(24 * 60 * 60 * 365) |
|
871 |
" |
|
11181 | 872 |
! |
873 |
||
874 |
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock |
|
875 |
"return a new Date, reading a printed representation from aStream. |
|
876 |
Notice, that this is not the storeString format and |
|
877 |
is different from the format expected by readFrom:" |
|
878 |
||
879 |
^ [ |
|
11182 | 880 |
|str monthString month dayString day year yearString| |
11181 | 881 |
|
882 |
str := aStringOrStream readStream. |
|
11182 | 883 |
monthString := str next:2. |
884 |
dayString := str next:2. |
|
885 |
yearString := str next:4. |
|
886 |
||
19712 | 887 |
year := Integer readFrom:yearString. |
11182 | 888 |
month := Integer readFrom:monthString. |
19712 | 889 |
day := Integer readFrom:dayString. |
890 |
||
891 |
self year:year month:month day:day. |
|
11181 | 892 |
] on:Error do:exceptionBlock |
893 |
||
894 |
" |
|
895 |
Date readMMDDYYYYFrom:'10041999' onError:['wrong date'] |
|
896 |
Date readMMDDYYYYFrom:'100419' onError:['wrong date'] |
|
897 |
||
898 |
Date readMMDDYYYYFrom:'10040001' onError:['wrong date'] |
|
899 |
" |
|
900 |
||
901 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
902 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
903 |
! |
|
904 |
||
905 |
readYYYYMMDDFrom:aStringOrStream onError:exceptionBlock |
|
906 |
"return a new Date, reading a printed representation from aStream. |
|
907 |
Notice, that this is not the storeString format and |
|
908 |
is different from the format expected by readFrom:" |
|
909 |
||
910 |
^ [ |
|
11182 | 911 |
|str monthString month dayString day yearString year| |
11181 | 912 |
|
913 |
str := aStringOrStream readStream. |
|
11182 | 914 |
yearString := str next:4. |
915 |
monthString := str next:2. |
|
916 |
dayString := str next:2. |
|
917 |
||
918 |
day := Integer readFrom:dayString. |
|
919 |
month := Integer readFrom:monthString. |
|
920 |
year := Integer readFrom:yearString. |
|
11181 | 921 |
|
19712 | 922 |
self year:year month:month day:day |
11181 | 923 |
] on:Error do:exceptionBlock |
924 |
||
925 |
" |
|
926 |
Date readYYYYMMDDFrom:'19991004' onError:['wrong date'] |
|
11182 | 927 |
Date readYYYYMMDDFrom:'911004' onError:['wrong date'] |
11181 | 928 |
" |
7005 | 929 |
! ! |
930 |
||
21217 | 931 |
|
11553 | 932 |
!Date class methodsFor:'change & update'! |
933 |
||
934 |
update:something with:aParameter from:changedObject |
|
935 |
((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[ |
|
936 |
"just remember change for next access" |
|
937 |
EnvironmentChange := true |
|
938 |
] |
|
939 |
||
940 |
"Created: 15.6.1996 / 15:19:25 / cg" |
|
941 |
! ! |
|
942 |
||
11127 | 943 |
!Date class methodsFor:'error handling'! |
944 |
||
945 |
conversionErrorSignal |
|
946 |
"return the signal used for conversion error handling" |
|
947 |
||
948 |
^ DateConversionError |
|
949 |
! ! |
|
950 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
951 |
!Date class methodsFor:'general queries'! |
699 | 952 |
|
16913 | 953 |
abbreviatedDayNamesForLanguage:languageOrNilForDefault |
954 |
"return a collection of short month-names for a given language or the |
|
955 |
current language if nil is given. |
|
956 |
The returned strings depend on the resource translation file to be present for the |
|
957 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
958 |
If not, english names are returned" |
|
959 |
||
960 |
|langDayAbbrevs lang| |
|
961 |
||
962 |
(DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
|
963 |
self initNames |
|
964 |
]. |
|
965 |
lang := languageOrNilForDefault notNil ifTrue:[languageOrNilForDefault] ifFalse:[Smalltalk language]. |
|
966 |
langDayAbbrevs := DayAbbrevs at:lang ifAbsent:nil. |
|
967 |
||
968 |
"/ If language is not found, try to initialize it from the resources and try again |
|
969 |
langDayAbbrevs isNil ifTrue:[ |
|
970 |
self initNamesForLanguage: lang. |
|
971 |
"/ If language initialization failed, take english dayAbbrevs |
|
972 |
langDayAbbrevs := DayAbbrevs at:lang ifAbsent:[DayAbbrevs at:#en.]. |
|
973 |
]. |
|
974 |
^ langDayAbbrevs |
|
975 |
||
976 |
" |
|
977 |
self abbreviatedDayNamesForLanguage:#en |
|
978 |
self abbreviatedDayNamesForLanguage:#de |
|
979 |
self abbreviatedDayNamesForLanguage:#fr |
|
980 |
self abbreviatedDayNamesForLanguage:#es |
|
981 |
self abbreviatedDayNamesForLanguage:#zulu |
|
982 |
||
983 |
self abbreviatedDayNamesForLanguage:nil |
|
984 |
" |
|
985 |
! |
|
986 |
||
987 |
abbreviatedMonthNamesForLanguage:languageOrNilForDefault |
|
988 |
"return a collection of short month-names for a given language or the |
|
989 |
current language if nil is given. |
|
990 |
The returned strings depend on the resource translation file to be present for the |
|
991 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
992 |
If not, english names are returned" |
|
993 |
||
994 |
|langMonthAbbrevs lang| |
|
995 |
||
996 |
(MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
|
997 |
self initNames |
|
998 |
]. |
|
999 |
lang := languageOrNilForDefault notNil ifTrue:[languageOrNilForDefault] ifFalse:[Smalltalk language]. |
|
1000 |
langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:nil. |
|
1001 |
||
1002 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1003 |
langMonthAbbrevs isNil ifTrue:[ |
|
1004 |
self initNamesForLanguage: lang. |
|
1005 |
"/ If language initialization failed, take english monthAbbrevs |
|
1006 |
langMonthAbbrevs := MonthAbbrevs at:lang ifAbsent:[MonthAbbrevs at:#en.]. |
|
1007 |
]. |
|
1008 |
^ langMonthAbbrevs |
|
1009 |
||
1010 |
" |
|
1011 |
self abbreviatedMonthNamesForLanguage:#en |
|
1012 |
self abbreviatedMonthNamesForLanguage:#de |
|
1013 |
self abbreviatedMonthNamesForLanguage:#fr |
|
1014 |
self abbreviatedMonthNamesForLanguage:#es |
|
1015 |
self abbreviatedMonthNamesForLanguage:#zulu |
|
1016 |
||
1017 |
self abbreviatedMonthNamesForLanguage:nil |
|
1018 |
" |
|
1019 |
||
1020 |
"Modified (format): / 18-07-2011 / 09:34:20 / cg" |
|
1021 |
! |
|
1022 |
||
699 | 1023 |
abbreviatedNameOfDay:dayIndex |
16913 | 1024 |
"given a day index (1..7), |
1025 |
return the abbreviated name of the day |
|
1026 |
for the current language setting" |
|
699 | 1027 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1028 |
^ self abbreviatedNameOfDay:dayIndex language:nil |
699 | 1029 |
|
1030 |
" |
|
1031 |
Date abbreviatedNameOfDay:4 |
|
1032 |
" |
|
1033 |
! |
|
1034 |
||
16913 | 1035 |
abbreviatedNameOfDay:dayIndex language:langOrNilForDefault |
1036 |
"given a day index (1..7), |
|
1037 |
return the abbreviated name of the day. |
|
1038 |
For nil, the current default language us used. |
|
1039 |
For unknown languages, english is used." |
|
1040 |
||
1041 |
^ (self abbreviatedDayNamesForLanguage:langOrNilForDefault) at:dayIndex |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1042 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1043 |
" |
16913 | 1044 |
Date abbreviatedNameOfDay:4 language:#en |
1045 |
Date abbreviatedNameOfDay:4 language:#de |
|
1046 |
Date abbreviatedNameOfDay:4 language:#zulu |
|
1047 |
Date abbreviatedNameOfDay:4 language:nil |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1048 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1049 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1050 |
|
699 | 1051 |
abbreviatedNameOfMonth:monthIndex |
16913 | 1052 |
"given a month index (1..12), |
1053 |
return the abbreviated name of the month |
|
1054 |
for the current language setting" |
|
1055 |
||
699 | 1056 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1057 |
^ self abbreviatedNameOfMonth:monthIndex language:nil |
699 | 1058 |
|
1059 |
" |
|
1060 |
Date abbreviatedNameOfMonth:11 |
|
1061 |
Date abbreviatedNameOfMonth:12 |
|
1062 |
" |
|
1063 |
! |
|
1064 |
||
16913 | 1065 |
abbreviatedNameOfMonth:monthIndex language:langOrNilForDefault |
1066 |
"given a month index (1..12), |
|
1067 |
return the abbreviated name of the month. |
|
1068 |
For nil, the current default language us used. |
|
1069 |
For unknown languages, english is used." |
|
1070 |
||
1071 |
^ (self abbreviatedMonthNamesForLanguage:langOrNilForDefault) at: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 |
" |
16913 | 1074 |
Date abbreviatedNameOfMonth:11 language:#en |
1075 |
Date abbreviatedNameOfMonth:12 language:#en |
|
1076 |
Date abbreviatedNameOfMonth:12 language:#de |
|
1077 |
Date abbreviatedNameOfMonth:12 language:#fr |
|
1078 |
Date abbreviatedNameOfMonth:12 language:#zulu |
|
1079 |
Date abbreviatedNameOfMonth:12 language:nil |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1080 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1081 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1082 |
|
699 | 1083 |
dateAndTimeNow |
16983 | 1084 |
"return an array containing the date and time of now. |
1085 |
As these provide no timezone info, this should be only used for user interface purposes." |
|
699 | 1086 |
|
1087 |
^ Time dateAndTimeNow |
|
1088 |
||
1089 |
" |
|
1090 |
Date dateAndTimeNow |
|
1091 |
" |
|
1092 |
! |
|
1093 |
||
16913 | 1094 |
dayNamesForLanguage:languageOrNilForDefault |
1095 |
"return a collection of day-names for a given language or the |
|
1096 |
current language if nil is given. |
|
1097 |
The returned strings depend on the resource translation file to be present for the |
|
1098 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
1099 |
If not, english names are returned" |
|
1100 |
||
1101 |
|langDayNames lang| |
|
1102 |
||
1103 |
(DayNames isNil or:[EnvironmentChange]) ifTrue:[ |
|
1104 |
self initNames |
|
1105 |
]. |
|
1106 |
lang := languageOrNilForDefault notNil ifTrue:[languageOrNilForDefault] ifFalse:[Smalltalk language]. |
|
1107 |
langDayNames := DayNames at:lang ifAbsent:nil. |
|
1108 |
||
1109 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1110 |
langDayNames isNil ifTrue:[ |
|
1111 |
self initNamesForLanguage: lang. |
|
1112 |
"/ If language initialization failed, take english dayNames |
|
1113 |
langDayNames := DayNames at:lang ifAbsent:[DayNames at:#en]. |
|
1114 |
]. |
|
1115 |
^ langDayNames |
|
1116 |
||
1117 |
" |
|
1118 |
self dayNamesForLanguage:#en |
|
1119 |
self dayNamesForLanguage:#de |
|
1120 |
self dayNamesForLanguage:#fr |
|
1121 |
self dayNamesForLanguage:#es |
|
1122 |
||
1123 |
self dayNamesForLanguage:#zulu |
|
1124 |
self dayNamesForLanguage:nil |
|
1125 |
" |
|
1126 |
||
1127 |
"Modified (format): / 18-07-2011 / 09:34:08 / cg" |
|
1128 |
! |
|
1129 |
||
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1130 |
dayOfFirstWeekInYear:aYear |
16913 | 1131 |
"for a given year, return the day corresponding to that year's monday of week-01. |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1132 |
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
|
1133 |
and the 1st day of that week is the preceeding monday |
16983 | 1134 |
(that means: that the returned day might be a day of the previous year!!)" |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1135 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1136 |
|day dayInWeekOf1stJan firstThursday firstDayInWeek| |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1137 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1138 |
"/ find the first thursday ... |
21217 | 1139 |
day := self newDay:1 year:aYear. |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1140 |
dayInWeekOf1stJan := day dayInWeek. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1141 |
dayInWeekOf1stJan > 4 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1142 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1143 |
] ifFalse:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1144 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1145 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1146 |
"/ back to the preceeding monday |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1147 |
firstDayInWeek := firstThursday subtractDays:3. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1148 |
^ firstDayInWeek |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1149 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1150 |
" |
14496 | 1151 |
Date newDay:1 year:1900 |
1152 |
Date dayOfFirstWeekInYear:1900 |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1153 |
Date dayOfFirstWeekInYear:1998 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1154 |
Date dayOfFirstWeekInYear:1999 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1155 |
Date dayOfFirstWeekInYear:2000 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1156 |
Date dayOfFirstWeekInYear:2001 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1157 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1158 |
! |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1159 |
|
699 | 1160 |
dayOfWeek:dayName |
1161 |
"given the name of a day (either string or symbol), |
|
1162 |
return the day-index (1 for monday; 7 for sunday). |
|
1163 |
Return 0 for invalid day name" |
|
1164 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1165 |
|d| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1166 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1167 |
d := self dayOfWeek:dayName language:nil. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1168 |
d == 0 ifTrue:[ |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1169 |
d := self dayOfWeek:dayName language:'en'. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1170 |
]. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1171 |
^ d |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1172 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1173 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1174 |
Date dayOfWeek:'wednesday' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1175 |
Date dayOfWeek:'Wednesday' |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
1176 |
Date dayOfWeek:'Mittwoch' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1177 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1178 |
! |
6976 | 1179 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1180 |
dayOfWeek:dayName language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1181 |
"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
|
1182 |
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
|
1183 |
Return 0 for invalid day name. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1184 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1185 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1186 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1187 |
|idx langDayNames| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1188 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1189 |
langDayNames := self dayNamesForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1190 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1191 |
idx := langDayNames indexOf:dayName. |
6976 | 1192 |
idx == 0 ifTrue:[ |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1193 |
idx := langDayNames indexOf:dayName asLowercase. |
6976 | 1194 |
]. |
1195 |
^ idx |
|
699 | 1196 |
|
1197 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1198 |
Date dayOfWeek:'wednesday' language:'en' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1199 |
Date dayOfWeek:'Wednesday' language:'en' |
699 | 1200 |
" |
1201 |
! |
|
1202 |
||
1203 |
daysInMonth:month forYear:yearInteger |
|
1204 |
"given the name of a month and a year, return the number |
|
1205 |
of days this month has (modified GNU). |
|
1206 |
return 0 if the month name was invalid. |
|
1207 |
For your convenience, month maybe an integer or name-string." |
|
1208 |
||
1209 |
|monthIndex "{ Class: SmallInteger }"| |
|
1210 |
||
1211 |
month isInteger ifTrue:[ |
|
1212 |
monthIndex := month |
|
1213 |
] ifFalse:[ |
|
1214 |
monthIndex := self indexOfMonth:month |
|
1215 |
]. |
|
1216 |
||
1217 |
^ self daysInMonthIndex:monthIndex forYear:yearInteger |
|
1218 |
||
1219 |
" |
|
1220 |
Date daysInMonth:2 forYear:1980 |
|
1221 |
Date daysInMonth:2 forYear:1981 |
|
1222 |
Date daysInMonth:'feb' forYear:1981 |
|
1223 |
" |
|
1224 |
! |
|
1225 |
||
1226 |
daysInYear:yearInteger |
|
1227 |
"return the number of days in a year" |
|
1228 |
||
1229 |
(self leapYear:yearInteger) ifTrue:[^ 366]. |
|
1230 |
^ 365 |
|
1231 |
||
1232 |
" |
|
1233 |
Date daysInYear:1900 |
|
1234 |
Date daysInYear:1901 |
|
1235 |
Date daysInYear:1904 |
|
1236 |
Date daysInYear:1980 |
|
1237 |
Date daysInYear:1981 |
|
1238 |
" |
|
1239 |
! |
|
1240 |
||
1241 |
daysUntilMonth:month forYear:yearInteger |
|
1242 |
"given the name of a month and a year, return the number |
|
1243 |
of days from 1st january to last of prev month of that year. |
|
1244 |
Return 0 if the month name/index is invalid or is january. |
|
1245 |
For your convenience, month maybe an integer or name-string." |
|
1246 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1247 |
|monthIndex| |
699 | 1248 |
|
1249 |
month isInteger ifTrue:[ |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1250 |
monthIndex := month |
699 | 1251 |
] ifFalse:[ |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1252 |
monthIndex := self indexOfMonth:month |
699 | 1253 |
]. |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1254 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1255 |
^ self daysUntilMonthIndex:monthIndex forYear:yearInteger |
699 | 1256 |
|
1257 |
" |
|
1258 |
Date daysUntilMonth:'feb' forYear:1993 |
|
1259 |
Date daysUntilMonth:'jan' forYear:1993 |
|
1260 |
" |
|
1261 |
! |
|
1262 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1263 |
defaultFormatString |
16983 | 1264 |
"a language specific format string to present dates in user interfaces. |
1265 |
Do not use this to store/retrieve dates (use ISO8601 for that)" |
|
1266 |
||
8118 | 1267 |
(DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[ |
16983 | 1268 |
self initNames |
8118 | 1269 |
]. |
18926 | 1270 |
^ DefaultFormats at:Smalltalk language ifAbsent:(DefaultFormats at:#en). |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1271 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1272 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1273 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1274 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1275 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1276 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1277 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1278 |
|
5778 | 1279 |
firstDayOfYear:inYear |
1280 |
"return the weekDay-index of the 1st-january of the given year. |
|
1281 |
1->monday, 2->tuesday, ... 7->sunday" |
|
1282 |
||
1283 |
| t d | |
|
1284 |
||
1285 |
((inYear < 1) or:[ inYear > 9999]) ifTrue:[ |
|
1286 |
^ 0. |
|
1287 |
]. |
|
1288 |
||
1289 |
"/ normal Gregorian calendar: one extra day per four years |
|
1290 |
t := 4 + inYear + ((inYear + 3) // 4). |
|
1291 |
||
1292 |
inYear > 1800 ifTrue:[ |
|
1293 |
"/ Julian calendar: regular Gregorian less 3 days per 400 |
|
1294 |
t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400). |
|
1295 |
]. |
|
1296 |
inYear > 1752 ifTrue:[ |
|
1297 |
"/ calendar changeover |
|
1298 |
t := t + 3. |
|
1299 |
]. |
|
1300 |
d := t \\ 7. |
|
1301 |
"/ convert from 0 (sunday) .. 6 (saturday) |
|
1302 |
"/ to 1 (munday) .. 7 (sunday) |
|
1303 |
d == 0 ifTrue:[^ 7]. |
|
1304 |
^ d |
|
1305 |
||
1306 |
" |
|
1307 |
self firstDayOfYear:2000 |
|
1308 |
(Date newDay:1 year:2000) dayInWeek |
|
1309 |
self firstDayOfYear:1999 |
|
1310 |
(Date newDay:1 year:1999) dayInWeek |
|
1311 |
self firstDayOfYear:1998 |
|
1312 |
(Date newDay:1 year:1998) dayInWeek |
|
1313 |
self firstDayOfYear:2001 |
|
1314 |
(Date newDay:1 year:2001) dayInWeek |
|
1315 |
self firstDayOfYear:2002 |
|
1316 |
(Date newDay:1 year:2002) dayInWeek |
|
1317 |
self firstDayOfYear:2006 |
|
1318 |
(Date newDay:1 year:2006) dayInWeek |
|
1319 |
||
1320 |
self firstDayOfYear:1800 |
|
1321 |
(Date newDay:1 year:1800) dayInWeek |
|
1322 |
" |
|
1323 |
! |
|
1324 |
||
699 | 1325 |
indexOfMonth:aMonthString |
1326 |
"given the name of a month (either string or symbol), |
|
1327 |
return the month-index (1 for jan; 12 for december). |
|
1328 |
The given string may be a full or abbreviated name, |
|
1329 |
case is ignored. |
|
1330 |
Return 0 for invalid month name." |
|
1331 |
||
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1332 |
|monthIndex| |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1333 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1334 |
monthIndex := self indexOfMonth:aMonthString language:nil. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1335 |
"/ if not found, retry in english |
17080 | 1336 |
(monthIndex == 0 and:[ Smalltalk language ~= #en ]) |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1337 |
ifTrue:[ |
17080 | 1338 |
monthIndex := self indexOfMonth:aMonthString language:#en. |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1339 |
]. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1340 |
^ monthIndex |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1341 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1342 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1343 |
Date indexOfMonth:'jan' |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1344 |
Date indexOfMonth:'Jan' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1345 |
Date indexOfMonth:'December' |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1346 |
Date indexOfMonth:'Dezember' |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1347 |
Date indexOfMonth:'december' |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1348 |
Date indexOfMonth:'dezember' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1349 |
" |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1350 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1351 |
"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
|
1352 |
! |
699 | 1353 |
|
14714 | 1354 |
indexOfMonth:aMonthString language:languageOrNil |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1355 |
"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
|
1356 |
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
|
1357 |
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
|
1358 |
case is ignored. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1359 |
Return 0 for invalid month name. |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1360 |
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
|
1361 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1362 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1363 |
|idx name langMonthNames langMonthAbbrevs| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1364 |
|
14714 | 1365 |
langMonthNames := self monthNamesForLanguage:languageOrNil. |
16839 | 1366 |
langMonthAbbrevs := self abbreviatedMonthNamesForLanguage:languageOrNil. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1367 |
|
699 | 1368 |
name := aMonthString asLowercase. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1369 |
idx := langMonthAbbrevs indexOf:name. |
699 | 1370 |
idx ~~ 0 ifTrue:[^ idx]. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1371 |
idx := langMonthNames indexOf:name. |
699 | 1372 |
idx ~~ 0 ifTrue:[^ idx]. |
1373 |
||
1374 |
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
|
1375 |
idx := langMonthAbbrevs indexOf:name. |
699 | 1376 |
idx ~~ 0 ifTrue:[^ idx]. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1377 |
idx := langMonthNames indexOf:name. |
699 | 1378 |
idx ~~ 0 ifTrue:[^ idx]. |
1379 |
||
1380 |
^ idx |
|
1381 |
||
1382 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1383 |
Date indexOfMonth:'jan' language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1384 |
Date indexOfMonth:'Jan' language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1385 |
Date indexOfMonth:'December' language:#en |
699 | 1386 |
" |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1387 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1388 |
"Modified: / 08-10-2006 / 14:20:17 / cg" |
699 | 1389 |
! |
1390 |
||
1391 |
leapYear:yearInteger |
|
16971 | 1392 |
"return true, if yearInteger is a leap year. |
1393 |
For years before 1583, the proleptic calendar is used |
|
1394 |
(i.e. assuming there was a gregorian calendar in effect)" |
|
699 | 1395 |
|
1396 |
|y "{ Class: SmallInteger }"| |
|
1397 |
||
1398 |
y := yearInteger. |
|
1399 |
(y \\ 4 == 0) ifTrue:[ |
|
16971 | 1400 |
(y \\ 100 ~~ 0) ifTrue:[^ true]. |
1401 |
(y \\ 400 == 0) ifTrue:[^ true] |
|
699 | 1402 |
]. |
1403 |
^ false |
|
1404 |
||
1405 |
" |
|
1406 |
Date leapYear:1992 |
|
1407 |
Date leapYear:1994 |
|
1408 |
Date leapYear:1900 |
|
1409 |
Date leapYear:2000 |
|
16971 | 1410 |
|
1411 |
Date leapYear:0 |
|
1412 |
Date leapYear:-1 |
|
1413 |
Date leapYear:-2 |
|
1414 |
Date leapYear:-3 |
|
1415 |
Date leapYear:-4 |
|
699 | 1416 |
" |
1417 |
! |
|
1418 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1419 |
longFormatString |
8118 | 1420 |
(LongFormats isNil or:[EnvironmentChange]) ifTrue:[ |
18926 | 1421 |
self initNames |
8118 | 1422 |
]. |
18926 | 1423 |
^ LongFormats at:Smalltalk language ifAbsent:(LongFormats at:#en). |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1424 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1425 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1426 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1427 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1428 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1429 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1430 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1431 |
|
699 | 1432 |
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger |
1433 |
"given a day-in-year (1..365) return an Array containing the |
|
1434 |
month index and the day-in-month. Return nil if the argument is invalid." |
|
1435 |
||
1436 |
|restDays daysInMonth| |
|
1437 |
||
1438 |
restDays := aDayInYear. |
|
1439 |
restDays < 1 ifTrue:[^ nil]. |
|
1440 |
||
1441 |
1 to:12 do:[:m | |
|
1442 |
daysInMonth := self daysInMonthIndex:m forYear:yearInteger. |
|
1443 |
restDays <= daysInMonth ifTrue:[ |
|
1444 |
^ Array with:m with:restDays |
|
1445 |
]. |
|
1446 |
restDays := restDays - daysInMonth |
|
1447 |
]. |
|
1448 |
restDays > daysInMonth ifTrue:[^ nil]. |
|
1449 |
^ Array with:12 with:restDays |
|
1450 |
||
1451 |
" |
|
1452 |
Date monthAndDayFromDayInYear:66 forYear:1980 |
|
1453 |
Date monthAndDayFromDayInYear:66 forYear:1981 |
|
1454 |
" |
|
1455 |
! |
|
1456 |
||
16913 | 1457 |
monthNamesForLanguage:languageOrNilForDefault |
1458 |
"return a collection of month-names for a given language or the |
|
1459 |
current language if nil is given. |
|
1460 |
The returned strings depend on the resource translation file to be present for the |
|
1461 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
1462 |
If not, english names are returned" |
|
1463 |
||
1464 |
|langMonthNames lang| |
|
1465 |
||
1466 |
(MonthNames isNil or:[EnvironmentChange]) ifTrue:[ |
|
1467 |
self initNames |
|
1468 |
]. |
|
1469 |
lang := languageOrNilForDefault notNil ifTrue:[languageOrNilForDefault] ifFalse:[Smalltalk language]. |
|
1470 |
langMonthNames := MonthNames at:lang ifAbsent:nil. |
|
1471 |
||
1472 |
"/ If language is not found, try to initialize it from the resources and try again |
|
1473 |
langMonthNames isNil ifTrue:[ |
|
1474 |
self initNamesForLanguage: lang. |
|
1475 |
"/ If language initialization failed, take english monthNames |
|
1476 |
langMonthNames := MonthNames at:lang ifAbsent:[MonthNames at:#en.]. |
|
1477 |
]. |
|
1478 |
^ langMonthNames |
|
1479 |
||
1480 |
" |
|
1481 |
self monthNamesForLanguage:#en |
|
1482 |
self monthNamesForLanguage:#de |
|
1483 |
self monthNamesForLanguage:#fr |
|
1484 |
self monthNamesForLanguage:#es |
|
1485 |
||
1486 |
self monthNamesForLanguage:#zulu |
|
1487 |
self monthNamesForLanguage:nil |
|
1488 |
" |
|
1489 |
||
1490 |
"Modified: / 18-07-2011 / 09:34:32 / cg" |
|
1491 |
! |
|
1492 |
||
699 | 1493 |
nameOfDay:dayIndex |
1494 |
"given a day index (1..7), return the name of the day" |
|
1495 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1496 |
^ self nameOfDay:dayIndex language:nil |
699 | 1497 |
|
1498 |
" |
|
8795 | 1499 |
Date nameOfDay:1 |
699 | 1500 |
Date nameOfDay:4 |
1501 |
" |
|
1502 |
! |
|
1503 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1504 |
nameOfDay:dayIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1505 |
"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
|
1506 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1507 |
for unknown languages, english is used." |
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 |
^ (self dayNamesForLanguage:lang) at:dayIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1510 |
|
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 |
Date nameOfDay:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1513 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1514 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1515 |
|
699 | 1516 |
nameOfMonth:monthIndex |
1517 |
"given a month index (1..12), return the name of the month" |
|
1518 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1519 |
^ self nameOfMonth:monthIndex language:nil |
699 | 1520 |
|
1521 |
" |
|
1522 |
Date nameOfMonth:11 |
|
1523 |
Date nameOfMonth:12 |
|
1524 |
Date nameOfMonth:4 |
|
1525 |
" |
|
1526 |
! |
|
1527 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1528 |
nameOfMonth:monthIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1529 |
"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
|
1530 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1531 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1532 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1533 |
^ (self monthNamesForLanguage:lang) at:monthIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1534 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1535 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1536 |
Date nameOfMonth:11 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1537 |
Date nameOfMonth:12 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1538 |
Date nameOfMonth:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1539 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1540 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1541 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1542 |
shortFormatString |
8118 | 1543 |
(ShortFormats isNil or:[EnvironmentChange]) ifTrue:[ |
18926 | 1544 |
self initNames |
8118 | 1545 |
]. |
18926 | 1546 |
^ ShortFormats at:Smalltalk language ifAbsent:(ShortFormats at:#en). |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1547 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1548 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1549 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1550 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1551 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1552 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1553 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1554 |
|
5548 | 1555 |
weekInYearOf:aDateOrTimestamp |
1556 |
"for a given date or timeStamp, return the week-number. |
|
14496 | 1557 |
The returned week number starts with 1 for the first week which has a thursday in it. |
1558 |
(see DIN 1355-1/ISO 8601) |
|
1559 |
The rule is: |
|
1560 |
every monday (and only monday), a new week begins |
|
1561 |
the first week is the one which has at least 4 days of the new year in it |
|
1562 |
||
1563 |
Be prepared: this definition can lead to the 1st week starting in the old year!!" |
|
5548 | 1564 |
|
13234 | 1565 |
|date dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week| |
1566 |
||
1567 |
date := aDateOrTimestamp asDate. |
|
1568 |
||
1569 |
dayInYear := date dayInYear. |
|
1570 |
dayOfFirstWeekInYear := self dayOfFirstWeekInYear:date year. |
|
1571 |
||
1572 |
numDays := date subtractDate:dayOfFirstWeekInYear. |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1573 |
"/ 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
|
1574 |
numDays < 0 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1575 |
"/ not in a week here ... |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1576 |
"/ can be either 52 or 53, depending on the previous year. |
21217 | 1577 |
^ self weekInYearOf:(self year:date year - 1 month:12 day:31) |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1578 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1579 |
|
5548 | 1580 |
"/ compute the week |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1581 |
week := numDays // 7 + 1. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1582 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1583 |
"/ 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
|
1584 |
week == 53 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1585 |
dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1. |
13234 | 1586 |
date >= dayOfFirstWeekInNextYear ifTrue:[ |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1587 |
^ 1 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1588 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1589 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1590 |
^ week |
5548 | 1591 |
|
1592 |
" |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1593 |
Timestamp now weekInYear |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1594 |
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
|
1595 |
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
|
1596 |
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
|
1597 |
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
|
1598 |
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
|
1599 |
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
|
1600 |
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
|
1601 |
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
|
1602 |
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
|
1603 |
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
|
1604 |
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
|
1605 |
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
|
1606 |
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
|
1607 |
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
|
1608 |
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
|
1609 |
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
|
1610 |
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
|
1611 |
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
|
1612 |
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
|
1613 |
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
|
1614 |
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
|
1615 |
Date weekInYearOf:(Date newDay:7 month:1 year:2002) |
16913 | 1616 |
Date weekInYearOf:(Date newDay:26 month:9 year:2008) |
1617 |
Date weekInYearOf:(Date newDay:27 month:9 year:2008) |
|
1618 |
Date weekInYearOf:(Date newDay:4 month:1 year:2008) |
|
1619 |
||
1620 |
Date weekInYearOf:(Date newDay:1 month:1 year:2010) |
|
1621 |
Date weekInYearOf:(Date newDay:2 month:1 year:2010) |
|
1622 |
Date weekInYearOf:(Date newDay:3 month:1 year:2010) |
|
1623 |
Date weekInYearOf:(Date newDay:4 month:1 year:2010) |
|
5548 | 1624 |
" |
1625 |
! |
|
1626 |
||
699 | 1627 |
yearAsDays: yearInteger |
1628 |
"Returns the number of days since Jan 1, 1901. (GNU) |
|
1629 |
to the first Jan of the year, yearInteger. |
|
16927 | 1630 |
For 1901 this is zero, for 1902 it's 365. |
699 | 1631 |
Defined for years >= 1901" |
1632 |
||
1633 |
|y "{ Class: SmallInteger }"| |
|
1634 |
||
1635 |
y := yearInteger - 1900. |
|
1636 |
y := y - 1. |
|
1637 |
^ (y * 365) |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1638 |
+ (y // 4) |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1639 |
- (y // 100) |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1640 |
+ ((y + 300) // 400) |
699 | 1641 |
|
1642 |
" |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1643 |
Date yearAsDays:5 |
14496 | 1644 |
Date yearAsDays:1900 |
699 | 1645 |
Date yearAsDays:1901 |
1646 |
Date yearAsDays:1902 |
|
1647 |
Date yearAsDays:1903 |
|
1648 |
Date yearAsDays:1904 |
|
1649 |
Date yearAsDays:1905 |
|
1650 |
Date yearAsDays:1994 |
|
1651 |
(Date yearAsDays:2001) - (Date yearAsDays:2000) |
|
1652 |
" |
|
16927 | 1653 |
! |
1654 |
||
1655 |
yearAsDaysFrom0: yearInteger |
|
1656 |
"Returns the number of days since Jan 1, 0 to Jan 1, yearInteger |
|
16983 | 1657 |
without caring for gregorian calendar change |
16927 | 1658 |
(i.e. as if there was a gregorian for all time). |
1659 |
Also assuming that the leapYear rules were present in pre-gregorian times also. |
|
16983 | 1660 |
Used internally to compute date differences. |
1661 |
||
1662 |
In previous versions, dates were counted relative to 1.1.1901. |
|
1663 |
This is no longer done; however, for backward compatibility, the old yearAsDays |
|
1664 |
and Date fromDays is still supported. |
|
1665 |
||
1666 |
For years >= 1901 it must hold that: |
|
1667 |
yearAsDaysFrom0(d1) - yearAsDaysFrom0(d2) |
|
1668 |
is the same as |
|
1669 |
yearAsDays(d1) - yearAsDays(d2) |
|
1670 |
" |
|
16927 | 1671 |
|
1672 |
|y "{ Class: SmallInteger }"| |
|
1673 |
||
1674 |
yearInteger == 0 ifTrue:[^ 0]. |
|
1675 |
y := yearInteger - 1. |
|
1676 |
^ 366 "/ 0 would have been a leap year |
|
1677 |
+ (y * 365) |
|
1678 |
+ (y // 4) "/ every 4th year is a leap year |
|
1679 |
- (y // 100) "/ but not evey 100th |
|
1680 |
+ (y // 400) "/ but evey 400th is |
|
1681 |
||
1682 |
" |
|
16983 | 1683 |
Date yearAsDaysFrom0:1900 |
1684 |
Date yearAsDaysFrom0:1901 |
|
1685 |
Date yearAsDaysFrom0:1902 |
|
1686 |
Date yearAsDaysFrom0:1903 |
|
1687 |
Date yearAsDaysFrom0:1904 |
|
1688 |
Date yearAsDaysFrom0:1905 |
|
1689 |
Date yearAsDaysFrom0:1994 |
|
16927 | 1690 |
|
1691 |
(Date yearAsDays:2001) - (Date yearAsDays:2000) |
|
16983 | 1692 |
(Date yearAsDaysFrom0:2001) - (Date yearAsDaysFrom0:2000) |
16927 | 1693 |
|
1694 |
(Date yearAsDays:2002) - (Date yearAsDays:2001) |
|
16983 | 1695 |
(Date yearAsDaysFrom0:2002) - (Date yearAsDaysFrom0:2001) |
1696 |
||
1697 |
Date yearAsDaysFrom0:-4 -1461 -- -4 was a leap year |
|
1698 |
Date yearAsDaysFrom0:-3 -1095 |
|
1699 |
Date yearAsDaysFrom0:-2 -730 |
|
1700 |
Date yearAsDaysFrom0:-1 -365 |
|
1701 |
Date yearAsDaysFrom0:0 0 |
|
1702 |
Date yearAsDaysFrom0:1 366 -- 0 was a leap year |
|
1703 |
Date yearAsDaysFrom0:2 731 |
|
1704 |
Date yearAsDaysFrom0:3 1096 |
|
1705 |
Date yearAsDaysFrom0:4 1461 |
|
1706 |
Date yearAsDaysFrom0:5 1827 -- 0 and 4 are leap years |
|
16927 | 1707 |
" |
699 | 1708 |
! ! |
1709 |
||
17690 | 1710 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1711 |
!Date class methodsFor:'obsolete'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1712 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1713 |
day:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1714 |
"return a new Date, given the day, month and year. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1715 |
Obsolete: |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1716 |
use newDay:month:year: for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1717 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1718 |
<resource: #obsolete> |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1719 |
|
18585 | 1720 |
"sr: #storeString has this format, |
1721 |
you really want to remove this method somewhen??? |
|
1722 |
if yes, please change #storeString also to #newDay:" |
|
1723 |
||
19712 | 1724 |
self obsoleteMethodWarning:'use #year:month:day: (2014-09)'. |
1725 |
^ self year:year month:month day:day |
|
18585 | 1726 |
|
1727 |
"Modified (comment): / 16-07-2015 / 15:32:14 / sr" |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1728 |
! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1729 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1730 |
day:dayInYear year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1731 |
"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
|
1732 |
Obsolete: |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1733 |
use newDay:year: for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1734 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1735 |
<resource: #obsolete> |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1736 |
|
16838 | 1737 |
self obsoleteMethodWarning:'use #newDay:year: (2014-09)'. |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1738 |
^ self newDay:dayInYear year:year |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1739 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1740 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1741 |
isLeapYear:yearInteger |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1742 |
"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
|
1743 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1744 |
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
|
1745 |
since this method will vanish." |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1746 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1747 |
|
16838 | 1748 |
self obsoleteMethodWarning:'use #leapYear: (2014-09)'. |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1749 |
^ self leapYear:yearInteger |
18444 | 1750 |
! |
1751 |
||
19712 | 1752 |
newDay:day month:month year:year |
1753 |
"backward compatibility" |
|
1754 |
||
1755 |
^ self year:year month:month day:day |
|
1756 |
! |
|
1757 |
||
18444 | 1758 |
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString |
1759 |
"OBSOLETE: kept for backward compatibility. |
|
1760 |
return a new Date, reading a printed representation from aStream. |
|
1761 |
aSqueakFormatArrayOrFormatString may either be a squeak formatArray |
|
1762 |
1 day position (1, 2 or 3) |
|
1763 |
2 month position (1..3) |
|
1764 |
3 year position (1..3) |
|
1765 |
or a formatString (see printing instance protocol)." |
|
1766 |
||
1767 |
^ self |
|
1768 |
readFrom:aStringOrStream |
|
1769 |
format:aSqueakFormatArrayOrFormatString |
|
1770 |
||
1771 |
" |
|
1772 |
Date readFrom:'19:11:1999' printFormat:#( 1 2 3 ) |
|
1773 |
Date readFrom:'19-nov-1999' printFormat:#( 1 2 3 ) |
|
1774 |
Date readFrom:'19:11:1999' printFormat:#( 2 1 3 ) -> exception: wrong month |
|
1775 |
Date readFrom:'5:12:1999' printFormat:#( 2 1 3 ) |
|
1776 |
Date readFrom:'may-12-1999' printFormat:#( 2 1 3 ) |
|
1777 |
Date readFrom:'1999 may 12' printFormat:#( 3 2 1 ) |
|
1778 |
Date readFrom:'12/31/2001' printFormat:#( 2 1 3 ) |
|
1779 |
Date readFrom:' 31.08.2001' printFormat:#( 1 2 3 ) |
|
1780 |
Date readFrom:' 31.dec.2001' printFormat:#( 1 2 3 ) |
|
1781 |
Date readFrom:' 31.Dec.2001' printFormat:#( 1 2 3 ) |
|
1782 |
Date readFrom:' 31.dez.2001' printFormat:#( 1 2 3 ) |
|
1783 |
||
1784 |
Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail' |
|
1785 |
Date readFrom:'12/01' printFormat:'%m %y' onError:'fail' |
|
1786 |
Date readFrom:'01' printFormat:'%y' onError:'fail' |
|
1787 |
Date readFrom:'30.01' printFormat:'%d %m' onError:'fail' |
|
1788 |
" |
|
1789 |
||
1790 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
1791 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
1792 |
! |
|
1793 |
||
1794 |
readFrom:aStringOrStream printFormat:aFormatStringOrSqueakFormatArray language:languageOrNil onError:exceptionBlock |
|
1795 |
"OBSOLETE: kept for backward compatibility |
|
1796 |
return a new Date, reading a printed representation from aStream. |
|
1797 |
aFormatStringOrSqueakFormatArray may either be a squeak formatArray |
|
1798 |
1 day position (1, 2 or 3) |
|
1799 |
2 month position (1..3) |
|
1800 |
3 year position (1..3) |
|
1801 |
or a formatString (see printing instance protocol). |
|
1802 |
For now %d, %m, %monthName, %shortMonthName, %y, %y1900, %y2000, %y1950 and %y1980 are supported in the formatString. |
|
1803 |
y1900 converts 2-digit year YY into 19YY, y2000 into 20YY. |
|
1804 |
y1950 and y1980 are special; if the year is below 50/80, it is converted to 20YY, otherwise to 19YY. |
|
1805 |
The formatString can have any of these characters '-.:,;/' as separator. |
|
1806 |
The format may be preceeded by a single numeric length (as in %2d) to specify how many |
|
1807 |
characters to read. |
|
1808 |
The formatString can also use a space as separator (for ex. '%d %m %y') and any separator will be allowed. |
|
1809 |
However, when a character separator is defined, only that separator will be expected. |
|
1810 |
TODO: make this a general feature of all DateAndTime classes. |
|
1811 |
" |
|
1812 |
||
1813 |
^ self readFrom:aStringOrStream format:aFormatStringOrSqueakFormatArray language:languageOrNil onError:exceptionBlock |
|
1814 |
||
1815 |
||
1816 |
" |
|
1817 |
Date readFrom:'31 December 1992' format:#(1 2 3) onError:'fail' |
|
1818 |
Date readFrom:'19:11:1999' format:#(1 2 3) onError:'fail' |
|
1819 |
Date readFrom:'December, 5 1992' format:#(1 2 3) onError:'fail' |
|
1820 |
Date readFrom:'3-jan-95' format:#(1 2 3) onError:'fail' |
|
1821 |
Date readFrom:'12/31/1992' format:#(1 2 3) onError:'fail' |
|
1822 |
Date readFrom:'15.4.1992' format:#(1 2 3) onError:'wrong date' -> german |
|
1823 |
Date readFrom:'10.4.1992' format:#(1 2 3) onError:'fail' -> german |
|
1824 |
Date readFrom:'10.4.1992' format:#(1 2 3) onError:['wrong date'] |
|
1825 |
Date readFrom:'32.4.1992' format:#(1 2 3) onError:['wrong date'] |
|
1826 |
Date readFrom:'fooBar' format:#(1 2 3) onError:['wrong date'] |
|
1827 |
Date readFrom:'10.4' format:#(1 2 3) onError:['wrong date'] |
|
1828 |
Date readFrom:'10041999' format:#(1 2 3) onError:['wrong date'] |
|
1829 |
||
1830 |
Date readFrom:'31/12/92' format:#(1 2 3) onError:'fail' |
|
1831 |
Date readFrom:'31/12/01' format:#(1 2 3) onError:'fail' |
|
1832 |
||
1833 |
Date readFrom:'31/12/01' format:'%d %m %y' onError:'fail' |
|
1834 |
Date readFrom:'12/01' format:'%m %y' onError:'fail' |
|
1835 |
Date readFrom:'01' format:'%y' onError:'fail' |
|
1836 |
Date readFrom:'30.01' format:'%d %m' onError:'fail' |
|
1837 |
Date readFrom:'300180' format:'%2d%2m%2y' onError:'fail' |
|
1838 |
||
1839 |
Date readFrom:'300170' format:'%2d%2m%2y' onError:'fail' - gives 2070 as year |
|
1840 |
Date readFrom:'300170' format:'%2d%2m%2(y1950)' onError:'fail' - gives 1970 as year |
|
1841 |
Date readFrom:'300170' format:'%2d%2m%2(y1980)' onError:'fail' - gives 2070 as year |
|
1842 |
Date readFrom:'300181' format:'%2d%2m%2(y1980)' onError:'fail' - gives 1981 as year |
|
1843 |
||
1844 |
Date readFrom:'3-3-1995' format:'%d %m %y' language: #de onError:'fail' |
|
1845 |
Date readFrom:'3-März-1995' format:'%d %monthName %y' language: #de onError:'fail' |
|
1846 |
Date readFrom:'3-mär-1995' format:'%d %shortMonthName %y' language: #de onError:'fail' |
|
1847 |
Date readFrom:'3/mär/1995' format:'%d %shortMonthName %y' language: #de onError:'fail' |
|
1848 |
Date readFrom:'3/mär/1995' format:'%d-%shortMonthName-%y' language: #de onError:'fail' |
|
1849 |
Date readFrom:'3-dez-1995' format:'%d %shortMonthName %y' language: #de onError:'fail' |
|
1850 |
Date readFrom:'3-Dez-1995' format:'%d %shortMonthName %y' language: #de onError:'fail' |
|
1851 |
Date readFrom:'3-Dezember-1995' format:'%d %monthName %y' language: #de onError:'fail' |
|
1852 |
" |
|
1853 |
||
1854 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
1855 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
1856 |
! |
|
1857 |
||
1858 |
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString onError:exceptionBlock |
|
1859 |
"return a new Date, reading a printed representation from aStream. |
|
1860 |
aSqueakFormatArrayOrFormatString may either be a squeak formatArray |
|
1861 |
1 day position (1, 2 or 3) |
|
1862 |
2 month position (1..3) |
|
1863 |
3 year position (1..3) |
|
1864 |
or a formatString (see printing instance protocol). |
|
1865 |
All of the %-formats as in the printString are supported here. |
|
1866 |
(i.e. %d, %m and %y, %shortMonthName and %monthName) |
|
1867 |
In addition, %y1900, %y2000, %y1950 and %y1980 are supported: |
|
1868 |
y1900 converts 2-digit year YY into 19YY, y2000 into 20YY. |
|
1869 |
y1950 and y1980 are special; if the year is below 50/80, it is converted to 20YY, otherwise to 19YY. |
|
1870 |
TODO: make this a general feature of all DateAndTime classes. |
|
1871 |
" |
|
1872 |
||
1873 |
^ self readFrom:aStringOrStream format:aSqueakFormatArrayOrFormatString onError:exceptionBlock |
|
1874 |
||
1875 |
" |
|
1876 |
Date readFrom:'31 December 1992' format:#(1 2 3) onError:'fail' |
|
1877 |
Date readFrom:'19:11:1999' format:#(1 2 3) onError:'fail' |
|
1878 |
Date readFrom:'December, 5 1992' format:#(1 2 3) onError:'fail' |
|
1879 |
Date readFrom:'3-jan-95' format:#(1 2 3) onError:'fail' |
|
1880 |
Date readFrom:'12/31/1992' format:#(1 2 3) onError:'fail' |
|
1881 |
Date readFrom:'15.4.1992' format:#(1 2 3) onError:'wrong date' -> german |
|
1882 |
Date readFrom:'10.4.1992' format:#(1 2 3) onError:'fail' -> german |
|
1883 |
Date readFrom:'10.4.1992' format:#(1 2 3) onError:['wrong date'] |
|
1884 |
Date readFrom:'32.4.1992' format:#(1 2 3) onError:['wrong date'] |
|
1885 |
Date readFrom:'fooBar' format:#(1 2 3) onError:['wrong date'] |
|
1886 |
Date readFrom:'10.4' format:#(1 2 3) onError:['wrong date'] |
|
1887 |
Date readFrom:'10041999' format:#(1 2 3) onError:['wrong date'] |
|
1888 |
||
1889 |
Date readFrom:'31/12/92' format:#(1 2 3) onError:'fail' |
|
1890 |
Date readFrom:'31/12/01' format:#(1 2 3) onError:'fail' |
|
1891 |
||
1892 |
Date readFrom:'31/12/01' format:'%d %m %y' onError:'fail' |
|
1893 |
Date readFrom:'12/01' format:'%m %y' onError:'fail' |
|
1894 |
Date readFrom:'01' format:'%y' onError:'fail' |
|
1895 |
Date readFrom:'30.01' format:'%d %m' onError:'fail' |
|
1896 |
Date readFrom:'311201' format:'%2d%2m%2y' onError:'fail' |
|
1897 |
" |
|
1898 |
||
1899 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
1900 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1901 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1902 |
|
21217 | 1903 |
|
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
1904 |
!Date class methodsFor:'private'! |
1 | 1905 |
|
13509 | 1906 |
dayAbbrevsForLanguage:languageOrNilForDefault |
16913 | 1907 |
<resource: #obsolete> |
1908 |
"return a collection of short day-names for a given language or the |
|
1909 |
current language if nil is given. |
|
1910 |
The returned strings depend on the resource translation file to be present for the |
|
1911 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
1912 |
If not, english names are returned" |
|
1913 |
||
1914 |
^ self abbreviatedDayNamesForLanguage:languageOrNilForDefault |
|
12812 | 1915 |
|
1916 |
" |
|
1917 |
self dayAbbrevsForLanguage:#en |
|
1918 |
self dayAbbrevsForLanguage:#de |
|
1919 |
self dayAbbrevsForLanguage:#fr |
|
1920 |
self dayAbbrevsForLanguage:#es |
|
16913 | 1921 |
self dayAbbrevsForLanguage:nil |
1922 |
self dayAbbrevsForLanguage:#zulu |
|
12812 | 1923 |
" |
13509 | 1924 |
|
1925 |
"Modified (format): / 18-07-2011 / 09:34:14 / cg" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1926 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1927 |
|
699 | 1928 |
daysInMonthIndex: monthIndex forYear: yearInteger |
1929 |
"return the number of days in month monthIndex of |
|
1930 |
year yearInteger (modified GNU). |
|
1931 |
Return 0 for invalid month index. |
|
1932 |
This is the internal version of daysInMonth:forYear:" |
|
1933 |
||
1934 |
|days| |
|
1935 |
||
1936 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
|
1937 |
||
1938 |
days := #(31 28 31 "Jan Feb Mar" |
|
1939 |
30 31 30 "Apr May Jun" |
|
1940 |
31 31 30 "Jul Aug Sep" |
|
1941 |
31 30 31 "Oct Nov Dec" |
|
1942 |
) at: monthIndex. |
|
1943 |
||
1944 |
(monthIndex == 2) ifTrue:[ |
|
1945 |
(self leapYear:yearInteger) ifTrue:[ |
|
1946 |
^ days + 1 |
|
1947 |
] |
|
1948 |
]. |
|
1949 |
^ days |
|
1950 |
||
1951 |
" |
|
1952 |
Date daysInMonthIndex:2 forYear:1994 |
|
1953 |
Date daysInMonthIndex:2 forYear:1980 |
|
1954 |
Date daysInMonthIndex:2 forYear:1981 |
|
1955 |
" |
|
1956 |
! |
|
1957 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1958 |
daysUntilMonthIndex: monthIndex forYear: yearInteger |
16913 | 1959 |
"return the number of days from 1st January up to month monthIndex of |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1960 |
year yearInteger (modified GNU). |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1961 |
Return 0 for invalid month index. |
16913 | 1962 |
This is the internal version of dayInMonth:forYear:" |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1963 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1964 |
|days| |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1965 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1966 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1967 |
|sum| |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1968 |
sum := 0. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1969 |
#(31 28 31 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1970 |
30 31 30 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1971 |
31 31 30 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1972 |
31 30 31 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1973 |
) collect:[:each | |first| first:= sum. sum := sum + each. first] |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1974 |
#(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
|
1975 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1976 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1977 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1978 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1979 |
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
|
1980 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1981 |
(monthIndex > 2) ifTrue:[ |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1982 |
(self leapYear:yearInteger) ifTrue:[ |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1983 |
^ days + 1 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1984 |
] |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1985 |
]. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1986 |
^ days |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1987 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1988 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1989 |
Date daysUntilMonthIndex:3 forYear:1994 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1990 |
Date daysUntilMonthIndex:3 forYear:1980 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1991 |
Date daysUntilMonthIndex:3 forYear:1981 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1992 |
" |
54 | 1993 |
! ! |
1994 |
||
11786 | 1995 |
!Date class methodsFor:'private-encoding/decoding'! |
54 | 1996 |
|
1997 |
encodeYear:y month:m day:d |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1998 |
"the internal encoding is strictly private, |
92 | 1999 |
and should not be used outside." |
2000 |
||
16927 | 2001 |
"this encoding was chosen to be easily readable... |
2002 |
and also sortable" |
|
54 | 2003 |
^ (((y * 100) + m) * 100) + d |
11786 | 2004 |
! |
2005 |
||
2006 |
readDatePartFrom:str format:fmt language:languageOrNil |
|
2007 |
"read a single component (such as %shortName) from str" |
|
2008 |
||
18448 | 2009 |
|dayName monthName day month year format string dayOfYear| |
12812 | 2010 |
|
25425
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2011 |
format := fmt asLowercase. |
12812 | 2012 |
string := str throughAnyForWhich:[:ch | ch isNationalAlphaNumeric]. |
2013 |
||
2014 |
((format sameAs:'dayName') or:[format sameAs:'shortDayName']) ifTrue:[ |
|
11786 | 2015 |
"/ skipped, in case the format is 'monday, 23rd of may...' - not used for decoding |
12812 | 2016 |
dayName := string. |
11786 | 2017 |
^ nil. |
2018 |
]. |
|
18446 | 2019 |
((format sameAs:'d') or:[format sameAs:'day']) ifTrue:[ |
12812 | 2020 |
day := Integer readFrom:string. |
11786 | 2021 |
^ #day -> day |
2022 |
]. |
|
12812 | 2023 |
|
18446 | 2024 |
((format sameAs:'m') or:[format sameAs:'month']) ifTrue:[ |
12812 | 2025 |
month := Integer readFrom:string. |
11786 | 2026 |
^ #month -> month |
2027 |
]. |
|
12812 | 2028 |
(format sameAs:'monthName') ifTrue:[ |
2029 |
monthName := string. |
|
21217 | 2030 |
month := (self monthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m]. |
12812 | 2031 |
"/ month == 0 ifTrue:[self error:'invalid month name']. |
2032 |
^ #month -> month |
|
2033 |
]. |
|
2034 |
(format sameAs:'shortMonthName') ifTrue:[ |
|
2035 |
monthName := string. |
|
21217 | 2036 |
month := (self abbreviatedMonthNamesForLanguage:languageOrNil) findFirst:[:m | monthName sameAs:m]. |
12812 | 2037 |
"/ month == 0 ifTrue:[self error:'invalid month name']. |
2038 |
^ #month -> month |
|
2039 |
]. |
|
2040 |
||
18443 | 2041 |
format = 'y1900' ifTrue:[ |
2042 |
year := Integer readFrom:string. |
|
2043 |
year < 100 ifTrue:[ |
|
2044 |
^ #year -> (year + 1900) |
|
2045 |
]. |
|
2046 |
^ #year -> year |
|
2047 |
]. |
|
2048 |
||
2049 |
format = 'y1950' ifTrue:[ |
|
2050 |
"shift YY into 1950..2049; for 2k support of old date strings" |
|
2051 |
year := Integer readFrom:string. |
|
2052 |
year < 100 ifTrue:[ |
|
2053 |
year < 50 ifTrue:[ |
|
2054 |
^ #year -> (year + 2000) |
|
2055 |
]. |
|
2056 |
^ #year -> (year + 1900) |
|
2057 |
]. |
|
2058 |
^ #year -> year |
|
2059 |
]. |
|
2060 |
||
25425
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2061 |
format = 'y1970' ifTrue:[ |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2062 |
"shift YY into 1970..2069; for 2k support of old date strings" |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2063 |
year := Integer readFrom:string. |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2064 |
year < 100 ifTrue:[ |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2065 |
year < 70 ifTrue:[ |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2066 |
^ #year -> (year + 2000) |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2067 |
]. |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2068 |
^ #year -> (year + 1900) |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2069 |
]. |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2070 |
^ #year -> year |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2071 |
]. |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2072 |
|
18443 | 2073 |
format = 'y1980' ifTrue:[ |
2074 |
"shift YY into 1980..2079; for 2k support of old date strings" |
|
2075 |
year := Integer readFrom:string. |
|
2076 |
year < 100 ifTrue:[ |
|
2077 |
year < 80 ifTrue:[ |
|
2078 |
^ #year -> (year + 2000) |
|
2079 |
]. |
|
2080 |
^ #year -> (year + 1900) |
|
2081 |
]. |
|
2082 |
^ #year -> year |
|
2083 |
]. |
|
2084 |
||
25425
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2085 |
format = 'y2000' ifTrue:[ |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2086 |
"shift YY into 2000..2099; for 2k support of old date strings" |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2087 |
year := Integer readFrom:string. |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2088 |
year < 100 ifTrue:[ |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2089 |
^ #year -> (year + 2000) |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2090 |
]. |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2091 |
^ #year -> year |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2092 |
]. |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2093 |
|
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2094 |
|
18446 | 2095 |
(format = 'Y') ifTrue:[ |
2096 |
"shift YY into 1970..2069; for 2k support of old date strings" |
|
2097 |
year := Integer readFrom:string. |
|
2098 |
year < 100 ifTrue:[ |
|
2099 |
year < 70 ifTrue:[ |
|
2100 |
^ #year -> (year + 2000) |
|
2101 |
]. |
|
2102 |
^ #year -> (year + 1900) |
|
2103 |
]. |
|
2104 |
^ #year -> year |
|
2105 |
]. |
|
2106 |
||
2107 |
((format = 'y') or:[format sameAs:'year']) ifTrue:[ |
|
12812 | 2108 |
year := Integer readFrom:string. |
11786 | 2109 |
year < 100 ifTrue:[ |
11787 | 2110 |
^ #year -> (year + 2000) |
11786 | 2111 |
]. |
2112 |
^ #year -> year |
|
2113 |
]. |
|
18448 | 2114 |
|
2115 |
(format sameAs:'dayOfYear') ifTrue:[ |
|
2116 |
dayOfYear := Integer readFrom:string. |
|
2117 |
^ #dayOfYear -> dayOfYear |
|
2118 |
]. |
|
2119 |
||
18443 | 2120 |
self error:'unknown format specifier: ',format |
25425
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2121 |
|
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
2122 |
"Modified: / 08-06-2021 / 22:19:29 / Jan Vrany <jan.vrany@labware.com>" |
54 | 2123 |
! ! |
2124 |
||
7258 | 2125 |
!Date class methodsFor:'private-instance creation'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2126 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2127 |
fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2128 |
"return a date, representing the date given by the operatingSystem time. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2129 |
This somewhat clumsy implementation hides the OS's date representation |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2130 |
(i.e. makes this class independent of what the OS starts its time values with). |
20794 | 2131 |
Don't use this method, the osTime representation is totally unportable." |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2132 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2133 |
^ self basicNew fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2134 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2135 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2136 |
Date fromOSTime:0 -> on UNIX: this should return 1st Jan 1970 |
20409 | 2137 |
that's where Unix time starts |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2138 |
On other systems, it may be something different. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2139 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2140 |
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
|
2141 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2142 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2143 |
|
21217 | 2144 |
|
7261 | 2145 |
!Date methodsFor:'Compatibility-ANSI'! |
6419 | 2146 |
|
2147 |
dayOfWeek |
|
2148 |
"return the week-day of the receiver - 1 is sunday, 7 for saturday. |
|
2149 |
WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday). |
|
2150 |
" |
|
2151 |
||
2152 |
|d| |
|
2153 |
||
2154 |
d := self dayInWeek. |
|
2155 |
d == 7 ifTrue:[ |
|
2156 |
^ 1 |
|
2157 |
]. |
|
2158 |
^ d + 1 |
|
2159 |
||
2160 |
" |
|
2161 |
Date today dayOfWeek |
|
2162 |
Date today dayInWeek |
|
2163 |
" |
|
2164 |
! |
|
2165 |
||
2166 |
dayOfWeekAbbreviation |
|
2167 |
"return the short week-day of the receiver as a string. |
|
2168 |
The returned string depends on the language setting. |
|
2169 |
Expect things like 'mon', 'tue' ..." |
|
2170 |
||
2171 |
^ self abbreviatedDayName |
|
2172 |
||
2173 |
" |
|
2174 |
Date today dayOfWeekAbbreviation |
|
2175 |
" |
|
2176 |
! |
|
2177 |
||
2178 |
dayOfWeekName |
|
2179 |
"return the week-day of the receiver as a string. |
|
2180 |
The returned string depends on the language setting. |
|
2181 |
Expect things like 'monday', 'tuesday' ..." |
|
2182 |
||
2183 |
^ self weekday |
|
2184 |
||
2185 |
" |
|
2186 |
Date today dayOfWeekName |
|
2187 |
Date today dayOfWeekAbbreviation |
|
2188 |
" |
|
2189 |
! |
|
2190 |
||
2191 |
dayOfYear |
|
2192 |
"return the day-nr within the year of the receiver - 1..365/366" |
|
2193 |
||
2194 |
^ self dayInYear |
|
2195 |
||
2196 |
" |
|
2197 |
Date today dayOfYear |
|
2198 |
" |
|
2199 |
! |
|
2200 |
||
2201 |
monthAbbreviation |
|
2202 |
"return the month of the receiver as a string. |
|
2203 |
The returned string depends on the language setting. |
|
2204 |
Expect things like 'jan', 'feb' ..." |
|
2205 |
||
2206 |
^ self abbreviatedMonthName |
|
2207 |
||
2208 |
" |
|
2209 |
Date today monthAbbreviation |
|
2210 |
" |
|
2211 |
! ! |
|
2212 |
||
7261 | 2213 |
!Date methodsFor:'Compatibility-ST80'! |
5515 | 2214 |
|
11740 | 2215 |
firstDayInMonth |
2216 |
"Return the first day in the month of the receiver" |
|
2217 |
||
2218 |
^ self subtractDays:(self dayOfMonth - 1) |
|
2219 |
||
2220 |
" |
|
2221 |
Date today |
|
11895 | 2222 |
Date today firstDayInMonth |
2223 |
Date today firstDayInMonth subtractDays:1 |
|
11740 | 2224 |
(Date today subtractDays:30) firstDayInMonth |
2225 |
(Date today subtractDays:122) firstDayInMonth |
|
2226 |
(Date today subtractDays:154) firstDayInMonth |
|
2227 |
" |
|
2228 |
! |
|
2229 |
||
11895 | 2230 |
lastDayInMonth |
2231 |
"Return the last day in the month in which the receiver is." |
|
2232 |
||
2233 |
^ self addDays:(self daysInMonth - self day). |
|
2234 |
||
2235 |
" |
|
2236 |
Date today |
|
2237 |
Date today lastDayInMonth |
|
2238 |
Date today lastDayInMonth addDays:1 |
|
2239 |
" |
|
2240 |
! |
|
2241 |
||
11664 | 2242 |
next:dayName |
2243 |
"Return the next date whose weekday name is dayName. |
|
2244 |
Caveat; dayName is expected to be in the current language" |
|
2245 |
||
2246 |
|ti ni| |
|
2247 |
||
2248 |
ti := self weekdayIndex. |
|
2249 |
ni := (self class dayOfWeek:dayName). |
|
2250 |
^ self addDays:(ni > ti ifTrue:[ ni-ti ] ifFalse:[ 7+ni-ti ]) |
|
2251 |
||
2252 |
" |
|
2253 |
Date today |
|
2254 |
Date today next:#Friday |
|
2255 |
Date today next:#Sunday |
|
2256 |
Date today next:#Monday |
|
2257 |
Date today next:#Thursday |
|
2258 |
Date today next:#WednesDay |
|
2259 |
" |
|
2260 |
! |
|
2261 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2262 |
nextDayWithIndex:dayIndex |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2263 |
"Return the next date whose weekday name is dayName. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2264 |
dayIndex is Monday=1, ... , Sunday=7" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2265 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2266 |
|ti| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2267 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2268 |
self assert:(dayIndex between:1 and:7). |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2269 |
ti := self weekdayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2270 |
^ self addDays:(dayIndex > ti ifTrue:[ dayIndex-ti ] ifFalse:[ 7+dayIndex-ti ]) |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2271 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2272 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2273 |
Date today |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2274 |
Date today nextDayWithIndex:5 - next Friday |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2275 |
Date today nextDayWithIndex:7 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2276 |
Date today nextDayWithIndex:1 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2277 |
Date today nextDayWithIndex:4 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2278 |
Date today nextDayWithIndex:3 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2279 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2280 |
! |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2281 |
|
6976 | 2282 |
previous:dayName |
2283 |
"Return the previous date whose weekday name is dayName. |
|
2284 |
Caveat; dayName is expected to be in the current language" |
|
2285 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2286 |
^ self previousDayWithIndex:(self class dayOfWeek:dayName). |
6976 | 2287 |
|
2288 |
" |
|
11664 | 2289 |
Date today |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2290 |
Date today previous:#Montag |
6976 | 2291 |
Date today previous:#Monday |
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2292 |
|
11664 | 2293 |
Date today previous:#Friday |
2294 |
Date today previous:#Sunday |
|
2295 |
Date today previous:#Monday |
|
2296 |
Date today previous:#Thursday |
|
2297 |
Date today previous:#WednesDay |
|
2298 |
Date today previous:#TuesDay |
|
6976 | 2299 |
" |
2300 |
! |
|
2301 |
||
11665
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2302 |
previousDayWithIndex:dayIndex |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2303 |
"Return the previous date whose weekday name is dayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2304 |
dayIndex is Monday=1, ... , Sunday=7" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2305 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2306 |
|ti| |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2307 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2308 |
self assert:(dayIndex between:1 and:7). |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2309 |
ti := self weekdayIndex. |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2310 |
^ self subtractDays:(((ti - dayIndex - 1) \\ 7) + 1) |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2311 |
|
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2312 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2313 |
Date today |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2314 |
Date today previousDayWithIndex:1 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2315 |
Date today previousDayWithIndex:5 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2316 |
Date today previousDayWithIndex:7 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2317 |
Date today previousDayWithIndex:4 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2318 |
Date today previousDayWithIndex:3 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2319 |
Date today previousDayWithIndex:2 |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2320 |
" |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2321 |
! |
352825372305
+nextDayWithIndex and previousDayWithIndex:
Claus Gittinger <cg@exept.de>
parents:
11664
diff
changeset
|
2322 |
|
7023 | 2323 |
printFormat:aFormatArray |
2324 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
2325 |
Return a string containing a printed representation of the receiver. |
|
2326 |
The formatArray argument consists of 6 or 7 integers which control |
|
2327 |
the resulting string. The entries are: |
|
2328 |
1 day position (1, 2 or 3) |
|
2329 |
2 month position (1..3) |
|
2330 |
3 year position (1..3) |
|
2331 |
4 asciiValue of separator character or separator character |
|
2332 |
or collection of 2 separator characters |
|
2333 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
2334 |
4: abbreviated uppercase 5: full uppercase) |
|
2335 |
6 year format (1 include century; 2 exclude century) |
|
2336 |
7 (optional) true/false. |
|
2337 |
if true, print numbers in 2-digit format |
|
2338 |
(i.e. with leading zeros); |
|
2339 |
Taken as false, if ommited |
|
2340 |
||
2341 |
Day and monthnames are in the currently active language. |
|
2342 |
||
2343 |
This method supports more options than the ST-80 version; month formats |
|
2344 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
2345 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
2346 |
||
2347 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
2348 |
This is an ST-80 compatibility method - I would have choosen another |
|
2349 |
(less cryptic) formatString ... |
|
2350 |
" |
|
2351 |
||
7961 | 2352 |
^ self printFormat:aFormatArray forLanguage:nil |
2353 |
||
2354 |
" |
|
2355 |
Date today printFormat:#(1 2 3 '' 1 2) |
|
2356 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
2357 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
|
2358 |
Date today printFormat:#(2 1 3 32 3 1) |
|
2359 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
2360 |
Date today printFormat:#(1 2 3 $- 2 1) |
|
2361 |
Date today printFormat:#(1 2 3 $- 4 1) |
|
2362 |
" |
|
2363 |
! |
|
2364 |
||
2365 |
printFormat:aFormatArray forLanguage:languageOrNil |
|
2366 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
2367 |
Return a string containing a printed representation of the receiver. |
|
2368 |
The formatArray argument consists of 6 or 7 integers which control |
|
2369 |
the resulting string. The entries are: |
|
2370 |
1 day position (1, 2 or 3) |
|
2371 |
2 month position (1..3) |
|
2372 |
3 year position (1..3) |
|
2373 |
4 asciiValue of separator character or separator character |
|
2374 |
or collection of 2 separator characters |
|
2375 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
2376 |
4: abbreviated uppercase 5: full uppercase) |
|
2377 |
6 year format (1 include century; 2 exclude century) |
|
2378 |
7 (optional) true/false. |
|
2379 |
if true, print numbers in 2-digit format |
|
2380 |
(i.e. with leading zeros); |
|
2381 |
Taken as false, if ommited |
|
2382 |
||
2383 |
Day and monthnames are in the currently active language. |
|
2384 |
||
2385 |
This method supports more options than the ST-80 version; month formats |
|
2386 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
2387 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
2388 |
||
2389 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
2390 |
This is an ST-80 compatibility method - I would have choosen another |
|
2391 |
(less cryptic) formatString ... |
|
2392 |
" |
|
2393 |
||
7023 | 2394 |
|mf upperCase day month year components sep1 sep2 leadingZeros| |
2395 |
||
2396 |
aFormatArray size > 6 ifTrue:[ |
|
2397 |
leadingZeros := aFormatArray at:7 |
|
2398 |
] ifFalse:[ |
|
2399 |
leadingZeros := false. |
|
2400 |
]. |
|
2401 |
||
2402 |
components := Array new:3. |
|
2403 |
day := self day. |
|
2404 |
leadingZeros ifTrue:[ |
|
2405 |
day := day printStringLeftPaddedTo:2 with:$0 |
|
2406 |
] ifFalse:[ |
|
2407 |
day := day printString |
|
2408 |
]. |
|
2409 |
components at:(aFormatArray at:1) put:day. |
|
2410 |
||
2411 |
upperCase := false. |
|
2412 |
mf := aFormatArray at:5. |
|
2413 |
(mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true]. |
|
2414 |
||
2415 |
mf == 1 ifTrue:[ |
|
2416 |
month := self month. |
|
2417 |
leadingZeros ifTrue:[ |
|
2418 |
month := month printStringLeftPaddedTo:2 with:$0 |
|
2419 |
] ifFalse:[ |
|
2420 |
month := month printString |
|
2421 |
] |
|
2422 |
] ifFalse:[ |
|
2423 |
mf == 2 ifTrue:[ |
|
7961 | 2424 |
month := self abbreviatedMonthNameForLanguage:languageOrNil |
7023 | 2425 |
] ifFalse:[ |
7961 | 2426 |
month := self monthNameForLanguage:languageOrNil |
7023 | 2427 |
] |
2428 |
]. |
|
2429 |
upperCase ifTrue:[month := month asUppercase]. |
|
2430 |
components at:(aFormatArray at:2) put:month. |
|
2431 |
||
2432 |
year := self year. |
|
2433 |
(aFormatArray at:6) == 2 ifTrue:[ |
|
2434 |
year := year \\ 100. |
|
2435 |
year := year printStringLeftPaddedTo:2 with:$0 |
|
2436 |
]. |
|
2437 |
year := year printString. |
|
2438 |
components at:(aFormatArray at:3) put:year. |
|
2439 |
||
2440 |
sep1 := sep2 := (aFormatArray at:4). |
|
2441 |
sep1 isString ifFalse:[ |
|
2442 |
sep1 isCollection ifTrue:[ |
|
2443 |
sep2 := (sep1 at:2). |
|
2444 |
sep1 := (sep1 at:1). |
|
2445 |
] ifFalse:[ |
|
2446 |
sep1 := sep2 := sep1 asCharacter |
|
2447 |
] |
|
2448 |
]. |
|
2449 |
||
2450 |
^ (components at:1) |
|
2451 |
, sep1 asString |
|
2452 |
, (components at:2) |
|
2453 |
, sep2 asString |
|
2454 |
, (components at:3) |
|
2455 |
||
2456 |
" |
|
7961 | 2457 |
Date today printFormat:#(1 2 3 '' 1 2) |
2458 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
7023 | 2459 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
2460 |
Date today printFormat:#(2 1 3 32 3 1) |
|
2461 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
7961 | 2462 |
Date today printFormat:#(1 2 3 $- 2 1) forLanguage:#en |
2463 |
Date today printFormat:#(1 2 3 $- 4 1) forLanguage:#en |
|
2464 |
" |
|
2465 |
! |
|
2466 |
||
2467 |
printFormat:aFormatArray forLanguage:languageOrNil on:aStream |
|
2468 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
2469 |
in printFormat:. |
|
2470 |
Append a printed representation of the receiver to aStream. |
|
2471 |
The argument, aFormatString controls the format, as described |
|
2472 |
in the #printFormat: method. |
|
2473 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
2474 |
||
2475 |
aStream nextPutAll:(self printFormat:aFormatArray forLanguage:languageOrNil) |
|
2476 |
||
2477 |
||
2478 |
"european formats: |
|
2479 |
||
2480 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
2481 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
2482 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
2483 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
2484 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
2485 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
2486 |
||
2487 |
US formats: |
|
2488 |
||
2489 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
2490 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
2491 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
2492 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
2493 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
2494 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
2495 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
7023 | 2496 |
" |
2497 |
! |
|
2498 |
||
2499 |
printFormat:aFormatArray on:aStream |
|
2500 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
2501 |
in printFormat:. |
|
2502 |
Append a printed representation of the receiver to aStream. |
|
2503 |
The argument, aFormatString controls the format, as described |
|
2504 |
in the #printFormat: method. |
|
2505 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
2506 |
||
2507 |
aStream nextPutAll:(self printFormat:aFormatArray) |
|
2508 |
||
2509 |
||
2510 |
"european formats: |
|
2511 |
||
2512 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
2513 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
2514 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
2515 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
2516 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
2517 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
2518 |
||
2519 |
US formats: |
|
2520 |
||
2521 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
2522 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
2523 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
2524 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
2525 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
2526 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
2527 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
2528 |
" |
|
2529 |
! |
|
2530 |
||
5515 | 2531 |
shortPrintString |
2532 |
"dummy - for now" |
|
2533 |
||
2534 |
^ self printString |
|
2535 |
||
2536 |
"Created: 20.6.1997 / 17:16:48 / cg" |
|
6976 | 2537 |
! |
2538 |
||
2539 |
weekdayIndex |
|
2540 |
"Return the day index; Monday=1, ... , Sunday=7" |
|
2541 |
||
2542 |
^ (self asDays + 1) \\ 7 + 1 "1 January 1901 was a Tuesday" |
|
2543 |
||
2544 |
" |
|
2545 |
Date today dayName |
|
2546 |
Date today weekdayIndex |
|
2547 |
" |
|
5515 | 2548 |
! ! |
2549 |
||
7261 | 2550 |
!Date methodsFor:'Compatibility-Squeak'! |
4407 | 2551 |
|
2552 |
mmddyyyy |
|
4462 | 2553 |
"return a printed representation of the receiver in the |
2554 |
form mmddyyyy. |
|
2555 |
The receiver can be reconstructed with: |
|
2556 |
Date readMMDDYYYYFrom:aStringOrStream onError:[...]" |
|
2557 |
||
11182 | 2558 |
^ self printStringFormat:'%m%d%y' |
2559 |
||
2560 |
"/ ^ (self month printStringLeftPaddedTo:2 with:$0) |
|
2561 |
"/ , (self day printStringLeftPaddedTo:2 with:$0) |
|
2562 |
"/ , (self year printStringLeftPaddedTo:4 with:$0) |
|
4407 | 2563 |
|
2564 |
" |
|
2565 |
Date today mmddyyyy |
|
2566 |
" |
|
2567 |
! ! |
|
2568 |
||
699 | 2569 |
!Date methodsFor:'accessing'! |
241 | 2570 |
|
699 | 2571 |
abbreviatedDayName |
16913 | 2572 |
"return the short week-day-name of the receiver as a string. |
699 | 2573 |
The returned string depends on the language setting. |
2574 |
Expect things like 'mon', 'tue' ..." |
|
54 | 2575 |
|
699 | 2576 |
^ self class abbreviatedNameOfDay:(self dayInWeek) |
92 | 2577 |
|
2578 |
" |
|
699 | 2579 |
Date today abbreviatedDayName |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2580 |
(Date newDay:15 month:4 year:1959) abbreviatedDayName |
92 | 2581 |
" |
2582 |
! |
|
2583 |
||
16913 | 2584 |
abbreviatedDayNameForLanguage:lang |
2585 |
"return the short week-day-name of the receiver as a string. |
|
2586 |
The returned string depends on the resource translation file to be present for the |
|
2587 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
2588 |
If not, the english name is returned. |
|
2589 |
Expect things like 'mon', 'tue' ..." |
|
2590 |
||
2591 |
^ self class abbreviatedNameOfDay:(self dayInWeek) language:lang |
|
2592 |
||
2593 |
" |
|
2594 |
Date today abbreviatedDayNameForLanguage:#en |
|
2595 |
Date today abbreviatedDayNameForLanguage:#de |
|
2596 |
Date today abbreviatedDayNameForLanguage:#zulu |
|
2597 |
||
2598 |
(Date newDay:15 month:4 year:1959) abbreviatedDayName |
|
2599 |
" |
|
2600 |
! |
|
2601 |
||
699 | 2602 |
abbreviatedMonthName |
16913 | 2603 |
"return the short month name of the receiver as a string. |
699 | 2604 |
The returned string depends on the language setting. |
2605 |
Expect things like 'jan', 'feb' ..." |
|
54 | 2606 |
|
699 | 2607 |
^ self class abbreviatedNameOfMonth:(self month) |
68 | 2608 |
|
92 | 2609 |
" |
699 | 2610 |
Date today abbreviatedMonthName |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2611 |
(Date newDay:15 month:4 year:1959) abbreviatedMonthName |
92 | 2612 |
" |
2613 |
! |
|
2614 |
||
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2615 |
abbreviatedMonthNameForLanguage:lang |
16913 | 2616 |
"return the short month-name of the receiver as a string in a given language. |
2617 |
The returned string depends on the resource translation file to be present for the |
|
2618 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
2619 |
If not, the english name is returned. |
|
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2620 |
Expect things like 'jan', 'feb' ..." |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2621 |
|
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2622 |
^ self class abbreviatedNameOfMonth:(self month) language:lang |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2623 |
|
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2624 |
" |
7961 | 2625 |
Date today abbreviatedMonthNameForLanguage:#en |
2626 |
Date today abbreviatedMonthNameForLanguage:#de |
|
16913 | 2627 |
Date today abbreviatedMonthNameForLanguage:#zulu |
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2628 |
" |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2629 |
! |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
2630 |
|
92 | 2631 |
asDays |
2632 |
"return the number of days elapsed since 01-Jan-1901 |
|
2633 |
and the receiver's day; starts with 0 for 1-1-1901. |
|
2634 |
Date>>fromDays: is the reverse operation. |
|
16927 | 2635 |
Notice, that this is not able to represent dates before 1901!!. |
2636 |
For GNU/ST-80 compatibility." |
|
68 | 2637 |
|
2638 |
|yr| |
|
2639 |
||
2640 |
yr := self year. |
|
2641 |
^ (self class yearAsDays:yr) |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2642 |
+ (self class daysUntilMonthIndex:self month forYear:yr) |
68 | 2643 |
+ self day |
85 | 2644 |
- 1 |
68 | 2645 |
|
92 | 2646 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2647 |
(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
|
2648 |
(Date newDay: 1 month: 1 year: 1901) asDays -> 0 |
16913 | 2649 |
(Date newDay: 31 month: 12 year: 1900) asDays -> -1 |
2650 |
(Date newDay: 1 month: 1 year: 1800) asDays -> -36889 |
|
2651 |
Date today asDays |
|
2652 |
Date fromDays:(Date today asDays + 7) |
|
92 | 2653 |
" |
77 | 2654 |
! |
2655 |
||
16927 | 2656 |
asDaysFrom0 |
2657 |
"return the number of days elapsed since 01-Jan-0 |
|
2658 |
and the receiver's day; starts with 0 for 1-1-0. |
|
2659 |
Date>>fromDaysFrom0: is the reverse operation. |
|
2660 |
Notice, that this is not able to represent dates before 0!!." |
|
2661 |
||
2662 |
|yr| |
|
2663 |
||
2664 |
yr := self year. |
|
2665 |
^ (self class yearAsDaysFrom0:yr) |
|
2666 |
+ (self class daysUntilMonthIndex:self month forYear:yr) |
|
2667 |
+ self day |
|
2668 |
- 1 |
|
2669 |
||
2670 |
" |
|
2671 |
(Date newDay: 1 month: 1 year: 0) asDaysFrom0 -> should be 0 |
|
2672 |
(Date newDay: 1 month: 1 year: 1) asDaysFrom0 -> should be 366 |
|
2673 |
Date fromDaysFrom0:(Date today asDaysFrom0 + 7) |
|
2674 |
" |
|
2675 |
! |
|
2676 |
||
77 | 2677 |
asSeconds |
19453 | 2678 |
"return the seconds between 1.jan.1901 and the same time in the receiver's |
17690 | 2679 |
day. (i.e. midnight to midnight). The returned number may be negative for dates before 1901. |
1501 | 2680 |
This does not include any leapSeconds ... strictly speaking, this is incorrect. |
77 | 2681 |
ST-80 compatibility." |
2682 |
||
92 | 2683 |
^ 60*60*24 * self asDays |
77 | 2684 |
|
92 | 2685 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2686 |
(Date newDay: 5 month: 8 year: 1962) asSeconds |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2687 |
(Date newDay: 1 month: 1 year: 1901) asSeconds |
17690 | 2688 |
(Date newDay: 1 month: 1 year: 1700) asSeconds |
92 | 2689 |
(Date today addDays:7) asSeconds - Date today asSeconds |
1501 | 2690 |
" |
2691 |
||
2692 |
"Modified: 1.7.1996 / 14:19:17 / cg" |
|
699 | 2693 |
! |
2694 |
||
2695 |
day |
|
2696 |
"return the day (1..31) of the receiver" |
|
2697 |
||
2698 |
^ dateEncoding \\ 100 |
|
2699 |
||
8626 | 2700 |
"example: |
699 | 2701 |
Date today day |
2702 |
" |
|
2703 |
! |
|
2704 |
||
2705 |
dayInWeek |
|
5778 | 2706 |
"return the week-day of the receiver - 1 for monday, 7 for sunday. |
6419 | 2707 |
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
|
2708 |
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
|
2709 |
(i.e. do not use this for dates before 1583) |
5778 | 2710 |
" |
699 | 2711 |
|
3256
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2712 |
|wday| |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2713 |
|
16927 | 2714 |
wday := self asDaysFrom0 \\ 7 - 1. |
2715 |
"/ wday := (1 "knowing, that 1st Jan 1901 was a tuesday" |
|
2716 |
"/ + self asDays) \\ 7 + 1. |
|
3256
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2717 |
wday < 1 ifTrue:[ |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2718 |
wday := wday + 7 |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2719 |
]. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
2720 |
^ wday |
699 | 2721 |
|
2722 |
" |
|
16927 | 2723 |
Date today dayInWeek |
2724 |
Date tomorrow dayInWeek |
|
5548 | 2725 |
Date yesterday dayInWeek |
16927 | 2726 |
(Date today subtractDays:2) dayInWeek |
2727 |
Date today weekday |
|
2728 |
Date tomorrow weekday |
|
2729 |
Date yesterday weekday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2730 |
(Date newDay:15 month:4 year:1959) dayInWeek |
16927 | 2731 |
(Date newDay:1 month:1 year:1901) dayInWeek |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2732 |
(Date newDay:31 month:12 year:1900) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2733 |
(Date newDay:31 month:12 year:1899) dayInWeek |
699 | 2734 |
" |
1501 | 2735 |
|
3257 | 2736 |
"Modified: / 1.2.1998 / 14:10:27 / cg" |
699 | 2737 |
! |
2738 |
||
5548 | 2739 |
dayInYear |
2740 |
"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
|
2741 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2742 |
" |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2743 |
|daysSoFar| |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2744 |
daysSoFar := 0. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2745 |
#(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
|
2746 |
" |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2747 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2748 |
|days month| |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2749 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2750 |
month := self month. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2751 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2752 |
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
|
2753 |
days := days + self day. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2754 |
(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
|
2755 |
days := days + 1. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2756 |
]. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2757 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2758 |
^ days |
5548 | 2759 |
|
2760 |
" |
|
2761 |
Date today dayInYear |
|
2762 |
(Date newDay:1 year:1999) dayInYear |
|
2763 |
(Date newDay:1 year:2000) dayInYear |
|
2764 |
(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
|
2765 |
(Date newDay:59 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2766 |
(Date newDay:60 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2767 |
(Date newDay:61 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2768 |
(Date newDay:366 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2769 |
(Date newDay:59 year:2005) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2770 |
(Date newDay:60 year:2005) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
2771 |
(Date newDay:365 year:2005) dayInYear |
5548 | 2772 |
" |
2773 |
! |
|
2774 |
||
77 | 2775 |
dayOfMonth |
2776 |
"Answer the day of the month represented by me. |
|
2777 |
Same as day; for ST-80 compatibility." |
|
2778 |
||
2779 |
^ self day |
|
92 | 2780 |
|
2781 |
" |
|
2782 |
Date today dayOfMonth |
|
2783 |
" |
|
2784 |
! |
|
2785 |
||
2786 |
daysInMonth |
|
2787 |
"return the number of days in the month of the receiver" |
|
2788 |
||
21217 | 2789 |
^ self class daysInMonth:(self month) forYear:(self year) |
92 | 2790 |
|
2791 |
" |
|
2792 |
Date today daysInMonth |
|
2793 |
" |
|
2794 |
! |
|
2795 |
||
2796 |
daysInYear |
|
2797 |
"return the number of days in the year of the receiver" |
|
2798 |
||
21217 | 2799 |
^ self class daysInYear:(self year) |
92 | 2800 |
|
2801 |
" |
|
2802 |
Date today daysInYear |
|
2803 |
" |
|
2804 |
! |
|
2805 |
||
5778 | 2806 |
daysLeftInMonth |
2807 |
"return the number of days left in the month of the receiver" |
|
2808 |
||
2809 |
^ self daysInMonth - self day |
|
2810 |
||
2811 |
" |
|
2812 |
Date today daysLeftInMonth |
|
2813 |
" |
|
2814 |
! |
|
2815 |
||
92 | 2816 |
daysLeftInYear |
11079
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2817 |
"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
|
2818 |
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
|
2819 |
the first january will return 364)" |
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
2820 |
|
21217 | 2821 |
^ (self class daysInYear:(self year)) - self dayOfYear |
92 | 2822 |
|
2823 |
" |
|
5282 | 2824 |
Date today daysLeftInYear |
92 | 2825 |
" |
77 | 2826 |
! |
2827 |
||
13234 | 2828 |
isLeapYear |
17053 | 2829 |
"return true, if the receiver's year is a leap year" |
68 | 2830 |
|
21217 | 2831 |
^ self class leapYear:self year |
68 | 2832 |
|
92 | 2833 |
" |
13234 | 2834 |
Date today isLeapYear |
2835 |
(Date newDay:1 month:1 year:1992) isLeapYear |
|
92 | 2836 |
" |
68 | 2837 |
! |
2838 |
||
699 | 2839 |
month |
2840 |
"return the month (1..12) of the receiver" |
|
92 | 2841 |
|
699 | 2842 |
^ (dateEncoding // 100) \\ 100 |
68 | 2843 |
|
92 | 2844 |
" |
699 | 2845 |
Date today month |
92 | 2846 |
" |
68 | 2847 |
! |
2848 |
||
77 | 2849 |
monthIndex |
2850 |
"return the index of the month (e.g. Feb.=2). |
|
2851 |
Same as month; for ST-80 compatibility." |
|
2852 |
||
2853 |
^ self month |
|
2854 |
! |
|
2855 |
||
68 | 2856 |
monthName |
2857 |
"return the month of the receiver as a string. |
|
2858 |
The returned string depends on the language setting. |
|
2859 |
Expect things like 'january', 'february' ..." |
|
2860 |
||
2861 |
^ self class nameOfMonth:(self month) |
|
2862 |
||
92 | 2863 |
" |
2864 |
Date today monthName |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2865 |
(Date newDay:15 month:4 year:1959) monthName |
92 | 2866 |
" |
68 | 2867 |
! |
2868 |
||
7961 | 2869 |
monthNameForLanguage:languageOrNil |
16913 | 2870 |
"return the month-name of the receiver as a string in a given language. |
2871 |
The returned string depends on the resource translation file to be present for the |
|
2872 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
2873 |
If not, the english name is returned. |
|
7961 | 2874 |
Expect things like 'january', 'february' ..." |
2875 |
||
2876 |
^ self class nameOfMonth:(self month) language:languageOrNil |
|
2877 |
||
2878 |
" |
|
16913 | 2879 |
Date today monthName |
2880 |
||
2881 |
Date today monthNameForLanguage:#en |
|
2882 |
Date today monthNameForLanguage:#de |
|
2883 |
Date today monthNameForLanguage:#zulu |
|
7961 | 2884 |
" |
2885 |
! |
|
2886 |
||
5548 | 2887 |
weekInYear |
2888 |
"return the week number of the receiver - 1 for Jan, 1st. |
|
2889 |
each week is Mon .. Sun (i.e. Sunday belongs to the previous week)" |
|
2890 |
||
2891 |
^ self class weekInYearOf:self |
|
2892 |
||
2893 |
" |
|
2894 |
Date today weekInYear |
|
2895 |
(Date newDay:1 year:2000) weekInYear was a saturday |
|
2896 |
(Date newDay:2 year:2000) weekInYear was a sunday |
|
2897 |
(Date newDay:3 year:2000) weekInYear was a monday |
|
2898 |
(Date newDay:4 year:2000) weekInYear was a tuesday |
|
2899 |
(Date newDay:5 year:2000) weekInYear was a wed |
|
2900 |
(Date newDay:6 year:2000) weekInYear was a thursday |
|
2901 |
(Date newDay:7 year:2000) weekInYear was a fri |
|
2902 |
(Date newDay:8 year:2000) weekInYear was a sat |
|
2903 |
(Date newDay:9 year:2000) weekInYear was a sun |
|
2904 |
(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
|
2905 |
(Date newDay:3 month:1 year:2001) weekInYear |
5548 | 2906 |
" |
2907 |
! |
|
2908 |
||
699 | 2909 |
weekday |
2910 |
"return the week-day of the receiver as a string. |
|
16913 | 2911 |
The returned string depends on the current language setting. |
699 | 2912 |
Expect things like 'monday', 'tuesday' ... |
2913 |
For ST-80 compatibility" |
|
2914 |
||
2915 |
^ self class nameOfDay:(self dayInWeek) |
|
2916 |
||
2917 |
" |
|
2918 |
Date today weekday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2919 |
(Date newDay:15 month:4 year:1959) weekday |
699 | 2920 |
" |
2921 |
! |
|
2922 |
||
16913 | 2923 |
weekdayForLanguage:lang |
2924 |
"return the week-day-name of the receiver as a string in a given language. |
|
2925 |
The returned string depends on the resource translation file to be present for the |
|
2926 |
given language (i.e. libbasic/resources(<lang>.rs). |
|
2927 |
If not, the english name is returned. |
|
2928 |
Expect things like 'monday', 'tuesday'..." |
|
2929 |
||
2930 |
^ self class nameOfDay:(self dayInWeek) language:lang |
|
2931 |
||
2932 |
" |
|
2933 |
Date today weekdayForLanguage:#de -> Mittwoch |
|
2934 |
Date today weekdayForLanguage:#en -> wednesday |
|
2935 |
Date today weekdayForLanguage:#zulu -> wednesday |
|
2936 |
||
2937 |
(Date newDay:15 month:4 year:1959) weekdayForLanguage:#de |
|
2938 |
(Date newDay:15 month:4 year:1959) weekdayForLanguage:#en |
|
2939 |
(Date newDay:15 month:4 year:1959) weekdayForLanguage:#zulu |
|
2940 |
" |
|
2941 |
! |
|
2942 |
||
699 | 2943 |
year |
16927 | 2944 |
"return the year of the receiver" |
699 | 2945 |
|
2946 |
^ dateEncoding // (100*100) |
|
68 | 2947 |
|
699 | 2948 |
" |
2949 |
Date today year |
|
16927 | 2950 |
Date today subtractDays:(1000 * 365) |
2951 |
Date today addDays:(1000 * 365) |
|
699 | 2952 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2953 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2954 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2955 |
year:year month:month day:day |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2956 |
dateEncoding := self class encodeYear:year month:month day:day |
699 | 2957 |
! ! |
2958 |
||
2959 |
!Date methodsFor:'arithmetic'! |
|
2960 |
||
8201 | 2961 |
+ days |
2962 |
"return a new date representing 'days' after the receiver. |
|
2963 |
The argument should be some kind of integer. |
|
2964 |
This is the same as #addDays." |
|
2965 |
||
16927 | 2966 |
^ self class fromDaysFrom0:(self asDaysFrom0 + days) |
8201 | 2967 |
|
2968 |
" |
|
2969 |
Date today + 7. |
|
2970 |
||
2971 |
Date today to:(Date today + 28) by:7 do:[:date| |
|
2972 |
Transcript show:date weekday; show:', '; showCr:date |
|
2973 |
]. |
|
2974 |
" |
|
2975 |
! |
|
2976 |
||
2977 |
- aDateOrNumberOfDays |
|
2978 |
"return the delta in days (anInteger) between 2 dates or |
|
2979 |
subtract a number of days from a date returning a Date" |
|
2980 |
||
2981 |
aDateOrNumberOfDays class == self class ifTrue:[ |
|
16927 | 2982 |
^ self asDaysFrom0 - aDateOrNumberOfDays asDaysFrom0 |
8201 | 2983 |
]. |
2984 |
||
16927 | 2985 |
^ self class fromDaysFrom0:(self asDaysFrom0 - aDateOrNumberOfDays asInteger) |
8201 | 2986 |
|
2987 |
" |
|
16927 | 2988 |
Date today - Date yesterday |
2989 |
Date today - 3 |
|
2990 |
Date today + 3 |
|
8201 | 2991 |
" |
2992 |
! |
|
2993 |
||
699 | 2994 |
addDays:days |
2995 |
"return a new date representing 'days' after the receiver. |
|
2996 |
The argument should be some kind of integer. |
|
2997 |
For ST-80 compatibility." |
|
2998 |
||
16927 | 2999 |
^ self class fromDaysFrom0:(self asDaysFrom0 + days) |
699 | 3000 |
|
3001 |
" |
|
3002 |
Date today addDays:7 |
|
3003 |
" |
|
3004 |
! |
|
3005 |
||
14331 | 3006 |
addMonths:numberOfMonths |
16927 | 3007 |
"Return a new instance which added numberOfMonths to self months. |
3008 |
Keep the day of month if possible. |
|
14331 | 3009 |
If the month of the new instance has fewer days than self dayOfMonth set the day to the last |
3010 |
day of the new instance's month. |
|
19712 | 3011 |
Does (probably) not work correct for resulting dates before calendar reform." |
3012 |
||
14331 | 3013 |
|yearToAdd years monthsInYear tempDate newMonth newMonthAsDate| |
3014 |
||
3015 |
yearToAdd := 0. |
|
3016 |
years := numberOfMonths // 12. |
|
3017 |
monthsInYear := numberOfMonths \\ 12. |
|
3018 |
tempDate := self addYears:years. |
|
3019 |
||
3020 |
newMonth := tempDate month + monthsInYear. |
|
3021 |
(newMonth between:1 and:12) ifFalse:[ |
|
3022 |
newMonth := newMonth \\ 12. |
|
3023 |
yearToAdd := 1. |
|
3024 |
]. |
|
3025 |
||
3026 |
newMonthAsDate := self class |
|
19712 | 3027 |
year:(tempDate year + yearToAdd) |
3028 |
month:newMonth |
|
3029 |
day:1. |
|
14331 | 3030 |
|
3031 |
^ self class |
|
19712 | 3032 |
year:(tempDate year + yearToAdd) |
14331 | 3033 |
month:newMonth |
19712 | 3034 |
day:(newMonthAsDate daysInMonth min:tempDate day) |
14331 | 3035 |
|
3036 |
"Created: / 23-08-2012 / 11:04:17 / sr" |
|
3037 |
"Created: / 24-08-2012 / 12:14:52 / anwild" |
|
3038 |
! |
|
3039 |
||
3040 |
addMonthsUsingEncoding:numberOfMonths |
|
16927 | 3041 |
"Return a new instance which added numberOfMonths to self months. |
3042 |
Keep the day of month if possible. |
|
3043 |
If the month of the new instance has fewer days than self dayOfMonth, |
|
3044 |
set the day to the last day of the new instance's month. |
|
3045 |
Does (probably) not work correct for resulting dates before calendar reform." |
|
3046 |
||
14331 | 3047 |
| newEncoding | |
16927 | 3048 |
|
14331 | 3049 |
newEncoding := dateEncoding |
3050 |
+ ((numberOfMonths + self month) // 12 * 10000) "the new year" |
|
3051 |
+ ((((numberOfMonths \\ 12) + self month) \\ 12) * 100) "the new month" |
|
3052 |
- (self month * 100) "in the line above the new month is already completely calculated. So subtract the current month" |
|
3053 |
- self day "in the line below the new day is already completely calculated. So subtract the current day" |
|
3054 |
+ (self day min: self daysInMonth). "the new day considering the maximum number of days in the new month." |
|
21217 | 3055 |
^ self class |
19712 | 3056 |
year: newEncoding // 10000 |
16927 | 3057 |
month: (newEncoding // 100 \\ 100) |
19712 | 3058 |
day: newEncoding \\ 100. |
14331 | 3059 |
|
3060 |
"Created: / 24-08-2012 / 15:18:44 / anwild" |
|
3061 |
! |
|
3062 |
||
3063 |
addYears:numberOfYears |
|
16927 | 3064 |
"Return a new instance which is the same date, but numberOfYears ahead of self. |
3065 |
Cares about leap years. |
|
3066 |
I.e. goes from a leap year's 29.feb to a non-leap year's 28.feb." |
|
3067 |
||
3068 |
|newYear newDay newMonth| |
|
14331 | 3069 |
|
3070 |
newYear := self year + numberOfYears. |
|
16927 | 3071 |
newDay := self day. |
3072 |
newMonth := self month. |
|
3073 |
||
3074 |
"/ special care for the 29th of February in a leapYear |
|
3075 |
(newDay = 29 and:[newMonth == 2]) ifTrue:[ |
|
3076 |
(self class leapYear:newYear) ifFalse: [ |
|
14331 | 3077 |
newDay := 28. |
3078 |
]. |
|
3079 |
]. |
|
3080 |
||
3081 |
^ self class |
|
19712 | 3082 |
year:newYear |
16927 | 3083 |
month:newMonth |
19712 | 3084 |
day:newDay |
14331 | 3085 |
|
3086 |
"Created: / 23-08-2012 / 11:05:04 / sr" |
|
3087 |
"Created: / 24-08-2012 / 12:14:09 / anwild" |
|
3088 |
! |
|
3089 |
||
9262 | 3090 |
daysSince:aDate |
3091 |
"return the number of days between the receiver and the argument, |
|
3092 |
aDate, which should be some kind of date" |
|
3093 |
||
16927 | 3094 |
^ self asDaysFrom0 - aDate asDaysFrom0 |
9262 | 3095 |
|
3096 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3097 |
Date today daysSince:(Date newDay:1 month:1 year:1901) |
9262 | 3098 |
" |
3099 |
! |
|
3100 |
||
699 | 3101 |
daysUntil:aDate |
3102 |
"return the number of days between the receiver and the argument, |
|
8201 | 3103 |
aDate, which should be some kind of date" |
699 | 3104 |
|
16927 | 3105 |
^ aDate asDaysFrom0 - self asDaysFrom0 |
68 | 3106 |
|
92 | 3107 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3108 |
(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
|
3109 |
(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
|
3110 |
(Date newDay:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994) |
699 | 3111 |
|
3112 |
|delta| |
|
3113 |
delta := Date today |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3114 |
daysUntil:(Date newDay:25 month:12 year:Date today year). |
699 | 3115 |
Transcript show:'still '; |
8201 | 3116 |
show:delta ; |
3117 |
showCR:' days till xmas' |
|
699 | 3118 |
" |
3119 |
! |
|
3120 |
||
11741 | 3121 |
firstDayInPreviousMonth:nMonths |
16927 | 3122 |
"Return the first day of a previous month (0=this month, 1=prev. month, etc.). |
3123 |
CG: there are two such methods - which one is obsolete?" |
|
3124 |
||
3125 |
^ self firstDayOfPreviousMonth:nMonths |
|
11741 | 3126 |
|
3127 |
" |
|
3128 |
(Date newDay:3 month:6 year:2009) firstDayInMonth |
|
3129 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:0 |
|
3130 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:5 |
|
3131 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:6 |
|
3132 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:7 |
|
3133 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:17 |
|
3134 |
(Date newDay:3 month:6 year:2009) firstDayInPreviousMonth:18 |
|
3135 |
" |
|
3136 |
! |
|
3137 |
||
3138 |
firstDayOfPreviousMonth:nMonths |
|
16927 | 3139 |
"Return the first day of a previous month (0=this month). |
3140 |
CG: there are two such methods - which one is obsolete? (see firstDayInPreviousMonth:)" |
|
11741 | 3141 |
|
18357 | 3142 |
|month year monthNegated| |
11741 | 3143 |
|
3144 |
month := self month. |
|
3145 |
year := self year. |
|
3146 |
month := month - nMonths. |
|
3147 |
month < 1 ifTrue:[ |
|
18357 | 3148 |
monthNegated := month negated. |
3149 |
year := year - 1 - (monthNegated // 12). |
|
3150 |
month := (12 - (monthNegated \\ 12)). |
|
11741 | 3151 |
]. |
3152 |
||
21217 | 3153 |
^ self class year:year month:month day:1. |
11741 | 3154 |
|
3155 |
" |
|
3156 |
(Date newDay:3 month:6 year:2009) firstDayInMonth |
|
18357 | 3157 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:0 |
11741 | 3158 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:5 |
3159 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:6 |
|
3160 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:7 |
|
3161 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:17 |
|
18357 | 3162 |
(Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:18 |
11741 | 3163 |
" |
3164 |
! |
|
3165 |
||
699 | 3166 |
subtractDate:aDate |
3167 |
"return the number of days between the receiver and aDate" |
|
3168 |
||
16927 | 3169 |
^ self asDaysFrom0 - aDate asDaysFrom0 |
699 | 3170 |
|
3171 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3172 |
(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
|
3173 |
(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
|
3174 |
(Date newDay:1 month:3 year:1994) subtractDate:(Date newDay:1 month:2 year:1994) |
699 | 3175 |
" |
3176 |
! |
|
3177 |
||
3178 |
subtractDays:days |
|
3179 |
"return a new date representing 'days' before the receiver. |
|
3180 |
The argument should be some kind of integer. |
|
3181 |
For ST-80 compatibility" |
|
3182 |
||
16927 | 3183 |
^ self class fromDaysFrom0:(self asDaysFrom0 - days) |
699 | 3184 |
|
3185 |
" |
|
3186 |
Date today subtractDays:7 |
|
92 | 3187 |
" |
1 | 3188 |
! ! |
3189 |
||
3190 |
!Date methodsFor:'comparing'! |
|
3191 |
||
29 | 3192 |
< aDate |
3193 |
"return true, if the date represented by the receiver |
|
3194 |
is before the argument, aDate" |
|
3195 |
||
19789 | 3196 |
"/ quick check, if it is another Date; then we can tune this operation, |
3197 |
"/ by not having to compute the osTime |
|
54 | 3198 |
(aDate isMemberOf:Date) ifTrue:[ |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3199 |
^ dateEncoding < aDate dateEncoding |
54 | 3200 |
]. |
29 | 3201 |
|
19789 | 3202 |
"/ the argument must understand year, month and day to be |
3203 |
"/ comparable, whatever it is |
|
21217 | 3204 |
^ dateEncoding < (self class 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
|
3205 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3206 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3207 |
Date today < (Date day:24 month:12 year:2000) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3208 |
Date today < (Date day:24 month:12 year:1900) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3209 |
Date today < Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3210 |
Date today-1 < Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3211 |
" |
29 | 3212 |
! |
1 | 3213 |
|
3214 |
= aDate |
|
3215 |
"return true, if the date represented by the receiver |
|
3216 |
is the same as the one represented by argument, aDate" |
|
3217 |
||
19789 | 3218 |
"/ must have same class and same osTime |
155 | 3219 |
(aDate isMemberOf:Date) ifFalse:[^ false]. |
3220 |
^ dateEncoding = aDate dateEncoding |
|
54 | 3221 |
|
3222 |
"the argument must understand year, month and day to be |
|
3223 |
comparable, whatever it is" |
|
3224 |
||
155 | 3225 |
" |
54 | 3226 |
^ dateEncoding = (Date encodeYear:aDate year |
19789 | 3227 |
month:aDate month |
3228 |
day:aDate day) |
|
155 | 3229 |
" |
68 | 3230 |
"Date today = ((Date today plusDays:7) minusDays:7)" |
92 | 3231 |
! |
3232 |
||
699 | 3233 |
> aDate |
3234 |
"return true, if the date represented by the receiver |
|
3235 |
is after the argument, aDate" |
|
3236 |
||
19789 | 3237 |
"/ quick check, if it is another Date; then we can tune this operation, |
3238 |
"/ by not having to compute the osTime |
|
699 | 3239 |
(aDate isMemberOf:Date) ifTrue:[ |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3240 |
^ dateEncoding > aDate dateEncoding |
699 | 3241 |
]. |
3242 |
||
19789 | 3243 |
"/ the argument must understand year, month and day, |
3244 |
"/ to be comparable, whatever it is |
|
21217 | 3245 |
^ dateEncoding > (self class 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
|
3246 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3247 |
" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3248 |
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
|
3249 |
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
|
3250 |
Date today > Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3251 |
Date today+1 > Timestamp now |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3252 |
" |
699 | 3253 |
! |
3254 |
||
92 | 3255 |
hash |
3256 |
"return an integer useful for hashing on dates" |
|
3257 |
||
3258 |
^ dateEncoding |
|
1 | 3259 |
! ! |
3260 |
||
1501 | 3261 |
!Date methodsFor:'converting'! |
3262 |
||
4408 | 3263 |
asDate |
3264 |
"return the receiver" |
|
3265 |
||
3266 |
^ self |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
3267 |
! |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
3268 |
|
13234 | 3269 |
asLocalTimestamp |
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
3270 |
"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
|
3271 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3272 |
^ Timestamp |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3273 |
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
|
3274 |
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
|
3275 |
|
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
3276 |
" |
13234 | 3277 |
Date today asLocalTimestamp |
3278 |
" |
|
3279 |
! |
|
3280 |
||
3281 |
asTimestamp |
|
3282 |
"return an TimeStamp instance, representing midnight of last night" |
|
3283 |
||
3284 |
^ self asLocalTimestamp |
|
3285 |
||
3286 |
" |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
3287 |
Date today asTimestamp |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
3288 |
" |
13234 | 3289 |
! |
3290 |
||
3291 |
asUtcTimestamp |
|
16927 | 3292 |
"return an UtcTimestamp instance, representing midnight of last night" |
13234 | 3293 |
|
3294 |
^ UtcTimestamp |
|
3295 |
year:(self year) month:(self month) day:(self day) |
|
3296 |
hour:0 minute:0 second:0 millisecond:0 |
|
3297 |
||
3298 |
" |
|
3299 |
Date today asUtcTimestamp |
|
3300 |
" |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
3301 |
! ! |
1501 | 3302 |
|
14496 | 3303 |
|
8201 | 3304 |
!Date methodsFor:'obsolete'! |
3305 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3306 |
asAbsoluteTime |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3307 |
"deprecated, use #asTimestamp" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3308 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3309 |
|
12001 | 3310 |
self obsoleteMethodWarning:'use #asTimestamp'. |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3311 |
^ self asTimestamp |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3312 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3313 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3314 |
dayCount |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3315 |
"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
|
3316 |
starting with 0 for this date. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3317 |
Date>>fromDays: is the reverse operation. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3318 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3319 |
please use asDays for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3320 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3321 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3322 |
^ self asDays. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3323 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3324 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3325 |
dayName |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3326 |
"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
|
3327 |
The returned string depends on the language setting. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3328 |
Expect things like 'monday', 'tuesday' ... |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3329 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3330 |
use #weekday for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3331 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3332 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3333 |
^ self weekday |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3334 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3335 |
|
13234 | 3336 |
leap |
19453 | 3337 |
"return true, if the receiver's year is a leap year" |
13234 | 3338 |
<resource: #obsolete> |
3339 |
||
3340 |
^ self isLeapYear |
|
3341 |
||
3342 |
" |
|
3343 |
Date today leap |
|
3344 |
(Date newDay:1 month:1 year:1992) leap |
|
3345 |
" |
|
3346 |
! |
|
3347 |
||
8201 | 3348 |
minusDays:days |
3349 |
"return a new date representing 'days' before the receiver. |
|
3350 |
The argument should be some kind of integer. |
|
3351 |
Obsolete: |
|
20794 | 3352 |
Please don't use this method since it will vanish. |
8201 | 3353 |
Use #subtractDays: instead for ST-80 compatibility." |
3354 |
||
3355 |
<resource: #obsolete> |
|
3356 |
||
3357 |
self obsoleteMethodWarning:'use #substractDays:'. |
|
3358 |
^ self subtractDays:days |
|
3359 |
! |
|
3360 |
||
3361 |
plusDays:days |
|
3362 |
"return a new date representing 'days' after the receiver. |
|
3363 |
The argument should be some kind of integer. |
|
3364 |
Obsolete: |
|
20794 | 3365 |
Please don't use this method since it will vanish. |
8201 | 3366 |
Use #addDays: instead for ST-80 compatibility." |
3367 |
||
3368 |
<resource: #obsolete> |
|
3369 |
||
3370 |
self obsoleteMethodWarning:'use #addDays:'. |
|
3371 |
^ self addDays:days |
|
3372 |
! ! |
|
3373 |
||
54 | 3374 |
!Date methodsFor:'printing & storing'! |
1 | 3375 |
|
5778 | 3376 |
addPrintBindingsTo:aDictionary |
18443 | 3377 |
"see comment in addPrintBindingsTo:language:" |
3378 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3379 |
self addPrintBindingsTo:aDictionary language:nil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3380 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3381 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3382 |
addPrintBindingsTo:aDictionary language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3383 |
"private print support: add bindings for printing to aDictionary. |
18443 | 3384 |
languageOrNil can only be #en or nil for the current language setting (Smalltalk language). |
3385 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3386 |
valid format items are: |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3387 |
%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
|
3388 |
%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
|
3389 |
%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
|
3390 |
%y - year, full i.e. 1999, 2004 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3391 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3392 |
special: |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3393 |
%D - day - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3394 |
%M - month - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3395 |
%W - week in year - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3396 |
%Y - year, last 2 digits only i.e. 99, 04 (danger: year 2k bug) |
5778 | 3397 |
|
18443 | 3398 |
%Y1900 - year, last 2 digits of 19YY only i.e. 99, 04 (danger: year 2k bug) |
3399 |
raises an error, if the year is not in 1900..1999 |
|
3400 |
%Y2000 - year, last 2 digits of 20YY only i.e. 01, 04 or 15 |
|
3401 |
raises an error, if the year is not in 2000..2099 |
|
3402 |
%Y1950 - year, last 2 digits of 19YY or 20YY only i.e. 01, 04 or 80 |
|
3403 |
raises an error, if the year is not in 1950..2049 |
|
3404 |
%Y1980 - year, last 2 digits of 19YY or 20YY only i.e. 01, 04 or 80 |
|
3405 |
raises an error, if the year is not in 1980..2079 |
|
3406 |
||
13174
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3407 |
%(weekDay) - day in week (1->monday, 2->tuesday, ... ,7->sunday) |
18448 | 3408 |
%(dayOfYear) - day in year (1..365/366) |
13174
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3409 |
|
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3410 |
%(dayName) - full day name |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3411 |
%(DayName) - full day name, first character uppercase |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3412 |
%(DAYNAME) - full day name, all uppercase |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3413 |
|
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3414 |
%(monthName) - full month name |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3415 |
%(MonthName) - full month name, first character uppercase |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3416 |
%(MONTHNAME) - full month name, all uppercase |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3417 |
|
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3418 |
%(shortDayName) - short (abbreviated) day name |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3419 |
%(ShortDayName) - short (abbreviated) day name, first character uppercase |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3420 |
%(SHORTDAYNAME) - short (abbreviated) day name, all uppercase |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3421 |
|
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3422 |
%(shortMonthName) - short (abbreviated) month name |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3423 |
%(ShortMonthName) - short (abbreviated) month name, first character uppercase |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3424 |
%(SHORTMONTHNAME) - short (abbreviated) month name, all uppercase |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3425 |
|
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3426 |
%(nth) - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3427 |
%(weekDayNth) - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
17193 | 3428 |
%(weekNth) - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') |
3429 |
||
3430 |
%(yearRoman) - year, in roman letters |
|
3431 |
%(monthRoman) - month, in roman letters" |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3432 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3433 |
|day ds dsPadded0 dsPaddedB month ms msPadded0 msPaddedB |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3434 |
year weekInYear monthName shortMonthName |
18448 | 3435 |
dayInWeek dayOfWeek dayName dayOfYear shortDayName ws wsPadded0| |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3436 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3437 |
day := self day. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3438 |
ds := day printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3439 |
dsPaddedB := day printStringLeftPaddedTo:2. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3440 |
dsPadded0 := day printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3441 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3442 |
month := self month. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3443 |
ms := month printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3444 |
msPaddedB := month printStringLeftPaddedTo:2. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3445 |
msPadded0 := month printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3446 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3447 |
year := self year. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3448 |
weekInYear := self weekInYear. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3449 |
ws := weekInYear printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3450 |
wsPadded0 := weekInYear printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3451 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3452 |
dayInWeek := self dayInWeek. "/ 1 .. 7 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3453 |
dayOfWeek := self dayOfWeek. "/ 0 .. 6 |
18448 | 3454 |
dayOfYear := self dayOfYear. "/ 0 .. 6 |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3455 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3456 |
monthName := self class nameOfMonth:(self month) language:languageOrNil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3457 |
dayName := self class nameOfDay:dayInWeek language:languageOrNil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3458 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3459 |
aDictionary at:#day put:dsPadded0. "/ 0-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3460 |
aDictionary at:#daypadded put:dsPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3461 |
aDictionary at:#dayPadded put:dsPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3462 |
aDictionary at:#Day put:ds. "/ unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3463 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3464 |
aDictionary at:#month put:msPadded0. "/ 0-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3465 |
aDictionary at:#monthPadded put:msPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3466 |
aDictionary at:#monthpadded put:msPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3467 |
aDictionary at:#Month put:ms. "/ unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3468 |
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
|
3469 |
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
|
3470 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3471 |
aDictionary at:#year put:year. "/ padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3472 |
aDictionary at:#week put:wsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3473 |
aDictionary at:#Week put:ws. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3474 |
|
21217 | 3475 |
year ~~ self class today year ifTrue:[ |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3476 |
aDictionary at:#yearOrTime put:(' ' , year printString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3477 |
]. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3478 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3479 |
aDictionary at:$d put:dsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3480 |
aDictionary at:$D put:ds. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3481 |
aDictionary at:$m put:msPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3482 |
aDictionary at:$M put:ms. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3483 |
aDictionary at:$y put:year. |
12663 | 3484 |
aDictionary at:$Y put:((year \\ 100) printStringLeftPaddedTo:2 with:$0). |
18443 | 3485 |
aDictionary at:#Y1950 put:[ |
3486 |
(year between:1950 and:2049) ifFalse:[ |
|
3487 |
self error:'year cannot be represented' |
|
3488 |
]. |
|
3489 |
(year between:1950 and:1999) ifTrue:[ |
|
3490 |
(year - 1900) printStringLeftPaddedTo:2 with:$0 |
|
3491 |
] ifFalse:[ |
|
3492 |
(year - 2000) printStringLeftPaddedTo:2 with:$0 |
|
3493 |
] |
|
3494 |
]. |
|
3495 |
aDictionary at:#Y1980 put:[ |
|
3496 |
(year between:1980 and:2079) ifFalse:[ |
|
3497 |
self error:'year cannot be represented' |
|
3498 |
]. |
|
3499 |
(year between:1980 and:1999) ifTrue:[ |
|
3500 |
(year - 1900) printStringLeftPaddedTo:2 with:$0 |
|
3501 |
] ifFalse:[ |
|
3502 |
(year - 2000) printStringLeftPaddedTo:2 with:$0 |
|
3503 |
] |
|
3504 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3505 |
aDictionary at:$w put:wsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3506 |
aDictionary at:$W put:ws. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3507 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3508 |
aDictionary at:#monthName put:monthName. |
14496 | 3509 |
aDictionary at:#monthname put:monthName asLowercase. |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3510 |
aDictionary at:#MonthName put:monthName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3511 |
aDictionary at:#MONTHNAME put:monthName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3512 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3513 |
aDictionary at:#dayName put:dayName. |
14496 | 3514 |
aDictionary at:#dayname put:dayName asLowercase. |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3515 |
aDictionary at:#DayName put:dayName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3516 |
aDictionary at:#DAYNAME put:dayName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3517 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3518 |
aDictionary at:#weekDay put:dayInWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3519 |
aDictionary at:#weekday put:dayInWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3520 |
aDictionary at:#weekDayUS put:dayOfWeek. |
18448 | 3521 |
aDictionary at:#dayOfYear put:dayOfYear. |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3522 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3523 |
aDictionary at:#shortDayName put:(shortDayName := self class abbreviatedNameOfDay:(self dayInWeek) language:languageOrNil). |
14496 | 3524 |
aDictionary at:#shortdayname put:shortDayName asLowercase. |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3525 |
aDictionary at:#ShortDayName put:shortDayName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3526 |
aDictionary at:#SHORTDAYNAME put:shortDayName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3527 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3528 |
aDictionary at:#shortMonthName put:(shortMonthName := self class abbreviatedNameOfMonth:(self month) language:languageOrNil). |
14496 | 3529 |
aDictionary at:#shortmonthname put:shortMonthName asLowercase. |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3530 |
aDictionary at:#ShortMonthName put:shortMonthName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3531 |
aDictionary at:#SHORTMONTHNAME put:shortMonthName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3532 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3533 |
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
|
3534 |
"/ 0 1 2 3 4 5 6 7 8 9 |
13174
2fe9eccdb8e4
comment/format in: #addPrintBindingsTo:language:
Stefan Vogel <sv@exept.de>
parents:
12814
diff
changeset
|
3535 |
aDictionary at:#weekDayNth put:(#('th' 'st' 'nd' 'rd' 'th' 'th' 'th') at:(dayOfWeek-1) \\ 10 + 1). |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3536 |
"/ 0 1 2 3 4 5 6 |
14496 | 3537 |
aDictionary at:#weekDayUSNth put:(#('st' 'nd' 'rd' 'th' 'th' 'th' 'th') at:(dayOfWeek-1) \\ 10 + 1). |
3538 |
"/ 0 1 2 3 4 5 6 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3539 |
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
|
3540 |
"/ 0 1 2 3 4 5 6 7 8 9 |
17193 | 3541 |
aDictionary at:#yearRoman put:[ year romanPrintString ]. |
3542 |
aDictionary at:#monthRoman put:[ month romanPrintString ]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3543 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3544 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3545 |
printOn:aStream |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3546 |
"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
|
3547 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3548 |
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
|
3549 |
|
5778 | 3550 |
" |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3551 |
Date today printOn:Transcript. Transcript cr. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3552 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3553 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3554 |
"Modified: 27.8.1995 / 01:01:49 / claus" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3555 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3556 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3557 |
printOn:aStream format:aFormatStringOrSqueakFormatArray |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3558 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3559 |
see #addPrintBindingsTo: for a list of valid format strings" |
5778 | 3560 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3561 |
self printOn:aStream format:aFormatStringOrSqueakFormatArray language:nil. |
5778 | 3562 |
|
3563 |
" |
|
3564 |
Date today printOn:Transcript format:'%y%m%d' (iso format) |
|
3565 |
Date today printOn:Transcript format:'%y-%m-%d' (iso format) |
|
3566 |
Date today printOn:Transcript format:'%y-W%w' (iso format - working week) |
|
3567 |
Date today printOn:Transcript format:'%d-%m-%y' (european trivia format) |
|
3568 |
Date today printOn:Transcript format:'%m/%d/%y' (us trivia format) |
|
3569 |
Date today printOn:Transcript format:'%D-%(monthName)-%y' (us trivia format) |
|
3570 |
Date today printOn:Transcript format:'%D-%(MonthName)-%y' (us trivia format) |
|
3571 |
Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
3572 |
Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
3573 |
Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
3574 |
Date today printOn:Transcript format:'%d%m%Y' (millenium bug format - danger) |
|
18443 | 3575 |
Date today printOn:Transcript format:'%d%m%(Y1950)' (millenium bug partial workaround format - danger) |
3576 |
Date today printOn:Transcript format:'%d%m%(Y1980)' (millenium bug partial workaround format - danger) |
|
5778 | 3577 |
Date today printOn:Transcript format:'Today is the %(weekDay) day of the week' |
17196 | 3578 |
Date today printOn:Transcript format:'Today is %(year).%(monthRoman).%D' (hungarian format) |
3579 |
Date today printOn:Transcript format:'Today is %(D) %(monthRoman) %y' (poland) |
|
3580 |
Date today printOn:Transcript format:'Today is %(D)-%(monthRoman)-%y' (romania) |
|
3581 |
Date today printOn:Transcript format:'Today is %(D)/%(mon)-%Y' (sweden) |
|
17194 | 3582 |
Date today printOn:Transcript format:'Anno domini %(yearRoman)' |
3583 |
Date today printOn:Transcript format:'%y年%(mon)月%d日' (select a font, which can display those chars) |
|
18448 | 3584 |
Date today printOn:Transcript format:'%(dayOfYear)' |
5778 | 3585 |
" |
18443 | 3586 |
|
15200 | 3587 |
"short form (as in blogs like www.stackoverflow, www.superuser etc.) |
3588 |
Date today printOn:Transcript format:'%(MonthName) %D ''%Y' |
|
3589 |
Timestamp now printOn:Transcript format:'%(MonthName) %D ''%Y at %h:%m' |
|
3590 |
" |
|
18443 | 3591 |
|
3592 |
"Squeak format spec: |
|
7023 | 3593 |
String streamContents:[:s | |
3594 |
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
|
3595 |
] |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3596 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3597 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3598 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3599 |
printOn:aStream format:aFormatStringOrSqueakFormatArray language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3600 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3601 |
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
|
3602 |
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
|
3603 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3604 |
|dict| |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3605 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3606 |
aFormatStringOrSqueakFormatArray isArray ifTrue:[ |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3607 |
"backward compatibility: a squeak/st80 format array" |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3608 |
self printFormat:aFormatStringOrSqueakFormatArray on:aStream. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3609 |
^ self. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3610 |
]. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3611 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3612 |
dict := IdentityDictionary new. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3613 |
self addPrintBindingsTo:dict language:languageOrNil. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3614 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3615 |
aFormatStringOrSqueakFormatArray expandPlaceholdersWith:dict on:aStream |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3616 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3617 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3618 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3619 |
Date today |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3620 |
printOn:Transcript |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3621 |
format:'%y%m%d' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3622 |
language:#en |
7023 | 3623 |
" |
5778 | 3624 |
! |
3625 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3626 |
printOn:aStream language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3627 |
"append a printed representation of the receiver to aStream. |
8179 | 3628 |
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
|
3629 |
|
18926 | 3630 |
|format langUsed| |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3631 |
|
8118 | 3632 |
(DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[ |
8145 | 3633 |
self class initNames |
8118 | 3634 |
]. |
18926 | 3635 |
langUsed := languageOrNil notNil ifTrue:[languageOrNil] ifFalse:[Smalltalk language]. |
3636 |
format := DefaultFormats at:langUsed ifAbsent:[DefaultFormats at:#en]. |
|
8179 | 3637 |
self printOn:aStream format:format language:languageOrNil. |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3638 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3639 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3640 |
Date today printOn:Transcript language:#en |
13195
d3a5d03a1c1c
comment/format in: #printOn:language:
Claus Gittinger <cg@exept.de>
parents:
13174
diff
changeset
|
3641 |
Date today printOn:Transcript language:#de |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3642 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3643 |
|
8179 | 3644 |
"Modified: / 27-08-1995 / 01:01:49 / claus" |
3645 |
"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
|
3646 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3647 |
|
7023 | 3648 |
printStringFormat:aFormatStringOrArray |
5778 | 3649 |
"print using a format string; |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3650 |
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
|
3651 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3652 |
^ self printStringFormat:aFormatStringOrArray language:nil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3653 |
|
5778 | 3654 |
" |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3655 |
Date today printStringFormat:'%y%m%d' (iso format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3656 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3657 |
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
|
3658 |
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
|
3659 |
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
|
3660 |
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
|
3661 |
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
|
3662 |
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
|
3663 |
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
|
3664 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3665 |
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
|
3666 |
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
|
3667 |
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
|
3668 |
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
|
3669 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3670 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3671 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3672 |
printStringFormat:aFormatStringOrArray language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3673 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
3674 |
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
|
3675 |
see #addPrintBindingsTo: for a list of valid format strings" |
5778 | 3676 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3677 |
|s| |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3678 |
|
18271 | 3679 |
s := CharacterWriteStream new:20. |
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3680 |
self printOn:s format:aFormatStringOrArray language:languageOrNil. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
3681 |
^ s contents. |
5778 | 3682 |
|
3683 |
" |
|
3684 |
Date today printStringFormat:'%y%m%d' (iso format) |
|
3685 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
|
3686 |
Date today printStringFormat:'%y-W%w' (iso format - working week) |
|
3687 |
Date today printStringFormat:'%d-%m-%y' (european trivia format) |
|
3688 |
Date today printStringFormat:'%m/%d/%y' (us trivia format) |
|
3689 |
Date today printStringFormat:'%D-%(monthName)-%y' (us trivia format) |
|
3690 |
Date today printStringFormat:'%D-%(MonthName)-%y' (us trivia format) |
|
3691 |
Date today printStringFormat:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
3692 |
Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
3693 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
3694 |
Date today printStringFormat:'%d%m%Y' (millenium bug format - danger) |
|
7327 | 3695 |
Date today printStringFormat:'Today is day %(weekDay) of the week' |
3696 |
Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week' |
|
3697 |
Date today printStringFormat:'Today is the %(Day)%(nth) day of the month' |
|
5778 | 3698 |
" |
3699 |
! |
|
3700 |
||
699 | 3701 |
storeOn:aStream |
3702 |
"append a representation to aStream, from which the receiver |
|
3703 |
can be reconstructed" |
|
3704 |
||
18731 | 3705 |
aStream nextPutAll:'('; nextPutAll:'Date newDay:'. |
699 | 3706 |
self day printOn:aStream. |
3707 |
aStream nextPutAll:' month:'. |
|
3708 |
self month printOn:aStream. |
|
3709 |
aStream nextPutAll:' year:'. |
|
3710 |
self year printOn:aStream. |
|
3711 |
aStream nextPutAll:')' |
|
3712 |
||
3713 |
" |
|
3714 |
Date today storeOn:Transcript |
|
3715 |
Date today storeString |
|
3716 |
" |
|
1 | 3717 |
! ! |
699 | 3718 |
|
7258 | 3719 |
!Date methodsFor:'private-accessing'! |
699 | 3720 |
|
3721 |
dateEncoding |
|
3722 |
"the internal encoding is stricktly private, |
|
3723 |
and should not be used outside." |
|
3724 |
||
3725 |
^ dateEncoding |
|
3726 |
! |
|
3727 |
||
3728 |
dateEncoding:anInteger |
|
3729 |
"the internal encoding is stricktly private, |
|
3730 |
and should not be used outside." |
|
3731 |
||
3732 |
dateEncoding := anInteger |
|
3733 |
! |
|
3734 |
||
3735 |
fromOSTime:osTime |
|
13234 | 3736 |
"set my dateEncoding as date in the local timezone from an OS time. |
699 | 3737 |
This somewhat clumsy implementation hides the OS's date representation |
3738 |
(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
|
3739 |
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
|
3740 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3741 |
|v| |
5858 | 3742 |
|
3743 |
v := OperatingSystem computeTimeAndDateFrom:osTime. |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
3744 |
dateEncoding := self class encodeYear:v year month:v month day:v day |
1501 | 3745 |
|
3746 |
"Modified: 1.7.1996 / 15:23:12 / cg" |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3747 |
! |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3748 |
|
13234 | 3749 |
fromUtcOSTime:osTime |
3750 |
"set my dateEncoding as UTC date from an OS time. |
|
3751 |
This somewhat clumsy implementation hides the OS's date representation |
|
3752 |
(i.e. makes this class independent of what the OS starts its time values with). |
|
3753 |
Don't use this method, the osTime representation is totally unportable." |
|
3754 |
||
3755 |
|v| |
|
3756 |
||
3757 |
v := OperatingSystem computeUTCTimeAndDateFrom:osTime. |
|
3758 |
dateEncoding := self class encodeYear:v year month:v month day:v day |
|
3759 |
||
3760 |
"Modified: 1.7.1996 / 15:23:12 / cg" |
|
3761 |
! |
|
3762 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3763 |
getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3764 |
"compatibility with Timestamp for comparing" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3765 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3766 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3767 |
((Timestamp epoch addDays:365) asDate asDays - 365) -> 25202 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3768 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3769 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3770 |
^ 1000 * 60*60*24 * (self asDays - 25202) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3771 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3772 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3773 |
Date today asTimestamp getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3774 |
- |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3775 |
Date today getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
3776 |
" |
699 | 3777 |
! ! |
3778 |
||
11176 | 3779 |
!Date methodsFor:'visiting'! |
3780 |
||
3781 |
acceptVisitor:aVisitor with:aParameter |
|
16725 | 3782 |
"dispatch for visitor pattern; send #visitDate:with: to aVisitor" |
11176 | 3783 |
|
3784 |
^ aVisitor visitDate:self with:aParameter |
|
3785 |
! ! |
|
3786 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
3787 |
!Date class methodsFor:'documentation'! |
699 | 3788 |
|
3789 |
version |
|
18568 | 3790 |
^ '$Header$' |
12097 | 3791 |
! |
3792 |
||
3793 |
version_CVS |
|
18568 | 3794 |
^ '$Header$' |
25425
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
3795 |
! |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
3796 |
|
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
3797 |
version_HG |
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
3798 |
|
21835502e9d7
Fix parsing year when using Y2K compatibility formats
Jan Vrany <jan.vrany@labware.com>
parents:
21249
diff
changeset
|
3799 |
^ '$Changeset: <not expanded> $' |
699 | 3800 |
! ! |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
3801 |
|
14714 | 3802 |
|
699 | 3803 |
Date initialize! |