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