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