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