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