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