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