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