author | Stefan Vogel <sv@exept.de> |
Thu, 26 Feb 2009 22:00:23 +0100 | |
changeset 11593 | 4d5d359f2008 |
parent 11553 | 5f6a4bccb7e7 |
child 11652 | 0799a4f46825 |
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'). |
|
160 |
||
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), |
70bdfdb519e3
#readFrom: handles ISO date too: yyyy-mm-dd
Stefan Vogel <sv@exept.de>
parents:
10056
diff
changeset
|
360 |
commo format with letter month in the middle (10 December 2007) |
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 ) |
|
447 |
" |
|
448 |
||
449 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
450 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
451 |
! |
|
452 |
||
7649 | 453 |
readFrom:aStringOrStream printFormat:aSqueakFormatArrayOrFormatString onError:exceptionBlock |
4997 | 454 |
"return a new Date, reading a printed representation from aStream. |
7649 | 455 |
aSqueakFormatArrayOrFormatString may either be a squeak formatArray |
456 |
1 day position (1, 2 or 3) |
|
457 |
2 month position (1..3) |
|
458 |
3 year position (1..3) |
|
459 |
or a formatString (see printing instance protocol). |
|
7651 | 460 |
For now, only %d, %m and %y are supported in the formatString. |
7649 | 461 |
TODO: make this a general feature of all DateAndTime classes. |
4997 | 462 |
" |
463 |
||
7649 | 464 |
|str day month year| |
465 |
||
466 |
str := aStringOrStream readStream. |
|
467 |
||
468 |
aSqueakFormatArrayOrFormatString isArray |
|
469 |
ifTrue:[ |
|
470 |
[ |
|
471 |
|arg| |
|
472 |
||
473 |
arg := Array new:3. |
|
4997 | 474 |
|
7649 | 475 |
1 to:3 do:[:i||v| |
476 |
[str peek isLetterOrDigit] whileFalse:[str next]. |
|
4997 | 477 |
|
7649 | 478 |
v := (str peek isDigit) ifTrue:[Integer readFrom:str] |
479 |
ifFalse:[str nextAlphaNumericWord]. |
|
480 |
arg at:i put:v |
|
481 |
]. |
|
482 |
year := (arg at:(aSqueakFormatArrayOrFormatString at:3)). |
|
483 |
day := arg at:(aSqueakFormatArrayOrFormatString at:1). |
|
484 |
month := arg at:(aSqueakFormatArrayOrFormatString at:2). |
|
7673 | 485 |
] on:Error do:[:ex| ^ exceptionBlock value]. |
7649 | 486 |
] ifFalse:[ |
487 |
[ |
|
488 |
|formatStream fc c sel| |
|
4997 | 489 |
|
7649 | 490 |
formatStream := aSqueakFormatArrayOrFormatString readStream. |
491 |
[formatStream atEnd] whileFalse:[ |
|
492 |
fc := formatStream next. |
|
493 |
fc == $% ifTrue:[ |
|
494 |
sel := ''. |
|
495 |
[(fc := formatStream peek) notNil and:[ fc isLetter]] whileTrue:[ sel := sel , (formatStream next) ]. |
|
7650 | 496 |
(sel asLowercase = 'd') ifTrue:[ |
7649 | 497 |
day := Integer readFrom:str |
498 |
] ifFalse:[ |
|
7650 | 499 |
(sel asLowercase = 'm') ifTrue:[ |
7649 | 500 |
month := Integer readFrom:str |
501 |
] ifFalse:[ |
|
7650 | 502 |
(sel asLowercase = 'y') ifTrue:[ |
7649 | 503 |
year := Integer readFrom:str |
504 |
] |
|
505 |
] |
|
506 |
] |
|
507 |
] ifFalse:[ |
|
508 |
fc == Character space ifTrue:[ |
|
8480
e7635256139d
reading: skip over '-'-characters
Claus Gittinger <cg@exept.de>
parents:
8446
diff
changeset
|
509 |
[(c := str peek) isSeparator or:[ '-.:,;/' includes:c ] ] whileTrue:[ str next ]. |
7649 | 510 |
] ifFalse:[ |
511 |
str skipSeparators. |
|
7673 | 512 |
str next == fc ifFalse:[^ exceptionBlock value]. |
7649 | 513 |
str skipSeparators. |
514 |
] |
|
515 |
] |
|
516 |
]. |
|
7673 | 517 |
] on:Error do:[:ex| ^ exceptionBlock value]. |
4997 | 518 |
]. |
7649 | 519 |
|
520 |
day isNil ifTrue:[ day := 1 ]. |
|
521 |
month isNil ifTrue:[ month := 1 ]. |
|
522 |
year isNil ifTrue:[ year := Date today year ]. |
|
523 |
||
524 |
(year between:0 and:99) ifTrue:[ |
|
525 |
year := UserPreferences current twoDigitDateHandler value:year. |
|
526 |
]. |
|
8878 | 527 |
[ |
528 |
^ self newDay:day month:month year:year. |
|
529 |
] on:Error do:[:ex| ^ exceptionBlock value]. |
|
4997 | 530 |
|
531 |
" |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6419
diff
changeset
|
532 |
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
|
533 |
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
|
534 |
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
|
535 |
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
|
536 |
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
|
537 |
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
|
538 |
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
|
539 |
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
|
540 |
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
|
541 |
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
|
542 |
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
|
543 |
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
|
544 |
|
a6704f70a3cf
conversion of year in [00..99] to 1900.. no longer done
Claus Gittinger <cg@exept.de>
parents:
6872
diff
changeset
|
545 |
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
|
546 |
Date readFrom:'31/12/01' printFormat:#(1 2 3) onError:'fail' |
7649 | 547 |
|
548 |
Date readFrom:'31/12/01' printFormat:'%d %m %y' onError:'fail' |
|
549 |
Date readFrom:'12/01' printFormat:'%m %y' onError:'fail' |
|
550 |
Date readFrom:'01' printFormat:'%y' onError:'fail' |
|
551 |
Date readFrom:'30.01' printFormat:'%d %m' onError:'fail' |
|
4421 | 552 |
" |
553 |
||
554 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
555 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
556 |
! |
|
557 |
||
699 | 558 |
today |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
559 |
"return a date, representing today. |
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
560 |
See also: Time now / Timestamp now." |
699 | 561 |
|
1501 | 562 |
^ self fromOSTime:(OperatingSystem getOSTime) |
699 | 563 |
|
564 |
" |
|
565 |
Date today |
|
566 |
" |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
567 |
|
1501 | 568 |
"Modified: 1.7.1996 / 15:20:16 / cg" |
5548 | 569 |
! |
570 |
||
571 |
tomorrow |
|
572 |
"return a date, representing tomorrow. |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
573 |
See also: Time now / Timestamp now." |
5548 | 574 |
|
575 |
^ Date today addDays:1 |
|
576 |
||
577 |
" |
|
578 |
Date tomorrow |
|
579 |
Date tomorrow dayInWeek |
|
580 |
" |
|
581 |
! |
|
582 |
||
583 |
yesterday |
|
584 |
"return a date, representing yesterday. |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
585 |
See also: Time now / Timestamp now." |
5548 | 586 |
|
587 |
^ Date today subtractDays:1 |
|
588 |
||
589 |
" |
|
590 |
Date yesterday |
|
591 |
Date yesterday dayInWeek |
|
592 |
" |
|
699 | 593 |
! ! |
594 |
||
7299 | 595 |
!Date class methodsFor:'Compatibility-Dolphin'! |
6872 | 596 |
|
597 |
newDay:day monthIndex:month year:year |
|
598 |
^ self newDay:day month:month year:year |
|
599 |
||
600 |
" |
|
601 |
Date newDay:8 monthIndex:5 year:1993 |
|
602 |
" |
|
603 |
||
604 |
"Modified: 19.4.1996 / 15:28:15 / cg" |
|
605 |
! ! |
|
606 |
||
7646 | 607 |
!Date class methodsFor:'Compatibility-ST80'! |
608 |
||
7648 | 609 |
newDay:day monthNumber:monthIndex year:year |
7646 | 610 |
"ST80 compatibility" |
611 |
||
612 |
^ self newDay:day month:monthIndex year:year |
|
613 |
! ! |
|
614 |
||
7299 | 615 |
!Date class methodsFor:'Compatibility-Squeak'! |
7005 | 616 |
|
617 |
fromSeconds:seconds |
|
618 |
"Answer an instance of me which is 'seconds' seconds after January 1, 1901." |
|
619 |
||
620 |
| secondsInDay | |
|
621 |
||
622 |
secondsInDay := 24 * 60 * 60. |
|
623 |
^self fromDays: seconds // secondsInDay |
|
624 |
||
625 |
" |
|
626 |
Date fromSeconds:0 |
|
627 |
Date fromSeconds:(24 * 60 * 60 * 365) |
|
628 |
" |
|
11181 | 629 |
! |
630 |
||
631 |
readMMDDYYYYFrom:aStringOrStream onError:exceptionBlock |
|
632 |
"return a new Date, reading a printed representation from aStream. |
|
633 |
Notice, that this is not the storeString format and |
|
634 |
is different from the format expected by readFrom:" |
|
635 |
||
636 |
^ [ |
|
11182 | 637 |
|str monthString month dayString day year yearString| |
11181 | 638 |
|
639 |
str := aStringOrStream readStream. |
|
11182 | 640 |
monthString := str next:2. |
641 |
dayString := str next:2. |
|
642 |
yearString := str next:4. |
|
643 |
||
644 |
day := Integer readFrom:dayString. |
|
645 |
month := Integer readFrom:monthString. |
|
646 |
year := Integer readFrom:yearString. |
|
11181 | 647 |
|
648 |
self newDay:day month:month year:year |
|
649 |
] on:Error do:exceptionBlock |
|
650 |
||
651 |
" |
|
652 |
Date readMMDDYYYYFrom:'10041999' onError:['wrong date'] |
|
653 |
Date readMMDDYYYYFrom:'100419' onError:['wrong date'] |
|
654 |
||
655 |
Date readMMDDYYYYFrom:'10040001' onError:['wrong date'] |
|
656 |
" |
|
657 |
||
658 |
"Created: 16.11.1995 / 22:50:17 / cg" |
|
659 |
"Modified: 8.10.1996 / 19:25:39 / cg" |
|
660 |
! |
|
661 |
||
662 |
readYYYYMMDDFrom:aStringOrStream onError:exceptionBlock |
|
663 |
"return a new Date, reading a printed representation from aStream. |
|
664 |
Notice, that this is not the storeString format and |
|
665 |
is different from the format expected by readFrom:" |
|
666 |
||
667 |
^ [ |
|
11182 | 668 |
|str monthString month dayString day yearString year| |
11181 | 669 |
|
670 |
str := aStringOrStream readStream. |
|
11182 | 671 |
yearString := str next:4. |
672 |
monthString := str next:2. |
|
673 |
dayString := str next:2. |
|
674 |
||
675 |
day := Integer readFrom:dayString. |
|
676 |
month := Integer readFrom:monthString. |
|
677 |
year := Integer readFrom:yearString. |
|
11181 | 678 |
|
679 |
self newDay:day month:month year:year |
|
680 |
] on:Error do:exceptionBlock |
|
681 |
||
682 |
" |
|
683 |
Date readYYYYMMDDFrom:'19991004' onError:['wrong date'] |
|
11182 | 684 |
Date readYYYYMMDDFrom:'911004' onError:['wrong date'] |
11181 | 685 |
" |
7005 | 686 |
! ! |
687 |
||
11553 | 688 |
!Date class methodsFor:'change & update'! |
689 |
||
690 |
update:something with:aParameter from:changedObject |
|
691 |
((something == #Language) or:[something == #LanguageTerritory]) ifTrue:[ |
|
692 |
"just remember change for next access" |
|
693 |
EnvironmentChange := true |
|
694 |
] |
|
695 |
||
696 |
"Created: 15.6.1996 / 15:19:25 / cg" |
|
697 |
! ! |
|
698 |
||
11127 | 699 |
!Date class methodsFor:'error handling'! |
700 |
||
701 |
conversionErrorSignal |
|
702 |
"return the signal used for conversion error handling" |
|
703 |
||
704 |
^ DateConversionError |
|
705 |
! ! |
|
706 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
707 |
!Date class methodsFor:'general queries'! |
699 | 708 |
|
709 |
abbreviatedNameOfDay:dayIndex |
|
710 |
"given a day index (1..7), return the abbreviated name |
|
711 |
of the day" |
|
712 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
713 |
^ self abbreviatedNameOfDay:dayIndex language:nil |
699 | 714 |
|
715 |
" |
|
716 |
Date abbreviatedNameOfDay:4 |
|
717 |
" |
|
718 |
! |
|
719 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
720 |
abbreviatedNameOfDay:dayIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
721 |
"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
|
722 |
of the day. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
723 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
724 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
725 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
726 |
^ (self dayAbbrevsForLanguage:lang) at:dayIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
727 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
728 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
729 |
Date abbreviatedNameOfDay:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
730 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
731 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
732 |
|
699 | 733 |
abbreviatedNameOfMonth:monthIndex |
734 |
"given a month index (1..12), return the abbreviated name |
|
735 |
of the month" |
|
736 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
737 |
^ self abbreviatedNameOfMonth:monthIndex language:nil |
699 | 738 |
|
739 |
" |
|
740 |
Date abbreviatedNameOfMonth:11 |
|
741 |
Date abbreviatedNameOfMonth:12 |
|
742 |
" |
|
743 |
! |
|
744 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
745 |
abbreviatedNameOfMonth:monthIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
746 |
"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
|
747 |
of the month. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
748 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
749 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
750 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
751 |
^ (self monthAbbrevsForLanguage:lang) at:monthIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
752 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
753 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
754 |
Date abbreviatedNameOfMonth:11 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
755 |
Date abbreviatedNameOfMonth:12 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
756 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
757 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
758 |
|
699 | 759 |
dateAndTimeNow |
760 |
"return an array containing the date and time of now" |
|
761 |
||
762 |
^ Time dateAndTimeNow |
|
763 |
||
764 |
" |
|
765 |
Date dateAndTimeNow |
|
766 |
" |
|
767 |
! |
|
768 |
||
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
769 |
dayOfFirstWeekInYear:aYear |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
770 |
"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
|
771 |
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
|
772 |
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
|
773 |
(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
|
774 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
775 |
|day dayInWeekOf1stJan firstThursday firstDayInWeek| |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
776 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
777 |
"/ find the first thursday ... |
11127 | 778 |
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
|
779 |
dayInWeekOf1stJan := day dayInWeek. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
780 |
dayInWeekOf1stJan > 4 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
781 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan + 7). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
782 |
] ifFalse:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
783 |
firstThursday := day addDays:(4 - dayInWeekOf1stJan). |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
784 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
785 |
"/ back to the preceeding monday |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
786 |
firstDayInWeek := firstThursday subtractDays:3. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
787 |
^ firstDayInWeek |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
788 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
789 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
790 |
Date dayOfFirstWeekInYear:1998 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
791 |
Date dayOfFirstWeekInYear:1999 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
792 |
Date dayOfFirstWeekInYear:2000 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
793 |
Date dayOfFirstWeekInYear:2001 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
794 |
" |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
795 |
! |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
796 |
|
699 | 797 |
dayOfWeek:dayName |
798 |
"given the name of a day (either string or symbol), |
|
799 |
return the day-index (1 for monday; 7 for sunday). |
|
800 |
Return 0 for invalid day name" |
|
801 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
802 |
^ self dayOfWeek:dayName language:nil |
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 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
805 |
Date dayOfWeek:'wednesday' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
806 |
Date dayOfWeek:'Wednesday' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
807 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
808 |
! |
6976 | 809 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
810 |
dayOfWeek:dayName language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
811 |
"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
|
812 |
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
|
813 |
Return 0 for invalid day name. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
814 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
815 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
816 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
817 |
|idx langDayNames| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
818 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
819 |
langDayNames := self dayNamesForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
820 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
821 |
idx := langDayNames indexOf:dayName. |
6976 | 822 |
idx == 0 ifTrue:[ |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
823 |
idx := langDayNames indexOf:dayName asLowercase. |
6976 | 824 |
]. |
825 |
^ idx |
|
699 | 826 |
|
827 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
828 |
Date dayOfWeek:'wednesday' language:'en' |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
829 |
Date dayOfWeek:'Wednesday' language:'en' |
699 | 830 |
" |
831 |
! |
|
832 |
||
833 |
daysInMonth:month forYear:yearInteger |
|
834 |
"given the name of a month and a year, return the number |
|
835 |
of days this month has (modified GNU). |
|
836 |
return 0 if the month name was invalid. |
|
837 |
For your convenience, month maybe an integer or name-string." |
|
838 |
||
839 |
|monthIndex "{ Class: SmallInteger }"| |
|
840 |
||
841 |
month isInteger ifTrue:[ |
|
842 |
monthIndex := month |
|
843 |
] ifFalse:[ |
|
844 |
monthIndex := self indexOfMonth:month |
|
845 |
]. |
|
846 |
||
847 |
^ self daysInMonthIndex:monthIndex forYear:yearInteger |
|
848 |
||
849 |
" |
|
850 |
Date daysInMonth:2 forYear:1980 |
|
851 |
Date daysInMonth:2 forYear:1981 |
|
852 |
Date daysInMonth:'feb' forYear:1981 |
|
853 |
" |
|
854 |
! |
|
855 |
||
856 |
daysInYear:yearInteger |
|
857 |
"return the number of days in a year" |
|
858 |
||
859 |
(self leapYear:yearInteger) ifTrue:[^ 366]. |
|
860 |
^ 365 |
|
861 |
||
862 |
" |
|
863 |
Date daysInYear:1900 |
|
864 |
Date daysInYear:1901 |
|
865 |
Date daysInYear:1904 |
|
866 |
Date daysInYear:1980 |
|
867 |
Date daysInYear:1981 |
|
868 |
" |
|
869 |
! |
|
870 |
||
871 |
daysUntilMonth:month forYear:yearInteger |
|
872 |
"given the name of a month and a year, return the number |
|
873 |
of days from 1st january to last of prev month of that year. |
|
874 |
Return 0 if the month name/index is invalid or is january. |
|
875 |
For your convenience, month maybe an integer or name-string." |
|
876 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
877 |
|monthIndex| |
699 | 878 |
|
879 |
month isInteger ifTrue:[ |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
880 |
monthIndex := month |
699 | 881 |
] ifFalse:[ |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
882 |
monthIndex := self indexOfMonth:month |
699 | 883 |
]. |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
884 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
885 |
^ self daysUntilMonthIndex:monthIndex forYear:yearInteger |
699 | 886 |
|
887 |
" |
|
888 |
Date daysUntilMonth:'feb' forYear:1993 |
|
889 |
Date daysUntilMonth:'jan' forYear:1993 |
|
890 |
" |
|
891 |
! |
|
892 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
893 |
defaultFormatString |
8118 | 894 |
(DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[ |
895 |
self initNames |
|
896 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
897 |
^ DefaultFormats at:Language ifAbsent:(DefaultFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
898 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
899 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
900 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
901 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
902 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
903 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
904 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
905 |
|
5778 | 906 |
firstDayOfYear:inYear |
907 |
"return the weekDay-index of the 1st-january of the given year. |
|
908 |
1->monday, 2->tuesday, ... 7->sunday" |
|
909 |
||
910 |
| t d | |
|
911 |
||
912 |
((inYear < 1) or:[ inYear > 9999]) ifTrue:[ |
|
913 |
^ 0. |
|
914 |
]. |
|
915 |
||
916 |
"/ normal Gregorian calendar: one extra day per four years |
|
917 |
t := 4 + inYear + ((inYear + 3) // 4). |
|
918 |
||
919 |
inYear > 1800 ifTrue:[ |
|
920 |
"/ Julian calendar: regular Gregorian less 3 days per 400 |
|
921 |
t := t - ((inYear - 1701) // 100) + ((inYear - 1601) // 400). |
|
922 |
]. |
|
923 |
inYear > 1752 ifTrue:[ |
|
924 |
"/ calendar changeover |
|
925 |
t := t + 3. |
|
926 |
]. |
|
927 |
d := t \\ 7. |
|
928 |
"/ convert from 0 (sunday) .. 6 (saturday) |
|
929 |
"/ to 1 (munday) .. 7 (sunday) |
|
930 |
d == 0 ifTrue:[^ 7]. |
|
931 |
^ d |
|
932 |
||
933 |
" |
|
934 |
self firstDayOfYear:2000 |
|
935 |
(Date newDay:1 year:2000) dayInWeek |
|
936 |
self firstDayOfYear:1999 |
|
937 |
(Date newDay:1 year:1999) dayInWeek |
|
938 |
self firstDayOfYear:1998 |
|
939 |
(Date newDay:1 year:1998) dayInWeek |
|
940 |
self firstDayOfYear:2001 |
|
941 |
(Date newDay:1 year:2001) dayInWeek |
|
942 |
self firstDayOfYear:2002 |
|
943 |
(Date newDay:1 year:2002) dayInWeek |
|
944 |
self firstDayOfYear:2006 |
|
945 |
(Date newDay:1 year:2006) dayInWeek |
|
946 |
||
947 |
self firstDayOfYear:1800 |
|
948 |
(Date newDay:1 year:1800) dayInWeek |
|
949 |
" |
|
950 |
! |
|
951 |
||
699 | 952 |
indexOfMonth:aMonthString |
953 |
"given the name of a month (either string or symbol), |
|
954 |
return the month-index (1 for jan; 12 for december). |
|
955 |
The given string may be a full or abbreviated name, |
|
956 |
case is ignored. |
|
957 |
Return 0 for invalid month name." |
|
958 |
||
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
959 |
|monthIndex| |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
960 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
961 |
monthIndex := self indexOfMonth:aMonthString language:nil. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
962 |
"/ if not found, retry in english |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
963 |
(monthIndex == 0 and:[ Smalltalk language ~= 'en' ]) |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
964 |
ifTrue:[ |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
965 |
monthIndex := self indexOfMonth:aMonthString language:'en'. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
966 |
]. |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
967 |
^ monthIndex |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
968 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
969 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
970 |
Date indexOfMonth:'jan' |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
971 |
Date indexOfMonth:'Jan' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
972 |
Date indexOfMonth:'December' |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
973 |
Date indexOfMonth:'Dezember' |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
974 |
Date indexOfMonth:'december' |
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
975 |
Date indexOfMonth:'dezember' |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
976 |
" |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
977 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
978 |
"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
|
979 |
! |
699 | 980 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
981 |
indexOfMonth:aMonthString language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
982 |
"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
|
983 |
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
|
984 |
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
|
985 |
case is ignored. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
986 |
Return 0 for invalid month name. |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
987 |
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
|
988 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
989 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
990 |
|idx name langMonthNames langMonthAbbrevs| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
991 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
992 |
langMonthNames := self monthNamesForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
993 |
langMonthAbbrevs := self monthAbbrevsForLanguage:lang. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
994 |
|
699 | 995 |
name := aMonthString asLowercase. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
996 |
idx := langMonthAbbrevs indexOf:name. |
699 | 997 |
idx ~~ 0 ifTrue:[^ idx]. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
998 |
idx := langMonthNames indexOf:name. |
699 | 999 |
idx ~~ 0 ifTrue:[^ idx]. |
1000 |
||
1001 |
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
|
1002 |
idx := langMonthAbbrevs indexOf:name. |
699 | 1003 |
idx ~~ 0 ifTrue:[^ idx]. |
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1004 |
idx := langMonthNames indexOf:name. |
699 | 1005 |
idx ~~ 0 ifTrue:[^ idx]. |
1006 |
||
1007 |
^ idx |
|
1008 |
||
1009 |
" |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1010 |
Date indexOfMonth:'jan' language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1011 |
Date indexOfMonth:'Jan' language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1012 |
Date indexOfMonth:'December' language:#en |
699 | 1013 |
" |
10056
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1014 |
|
3c8e8c867a13
indexofmonth: try english as second chance
Claus Gittinger <cg@exept.de>
parents:
9262
diff
changeset
|
1015 |
"Modified: / 08-10-2006 / 14:20:17 / cg" |
699 | 1016 |
! |
1017 |
||
1018 |
leapYear:yearInteger |
|
1019 |
"return true, if yearInteger is a leap year." |
|
1020 |
||
1021 |
|y "{ Class: SmallInteger }"| |
|
1022 |
||
1023 |
y := yearInteger. |
|
1024 |
(y \\ 4 == 0) ifTrue:[ |
|
1025 |
(y \\ 100 ~~ 0) ifTrue:[^ true]. |
|
1026 |
(y \\ 400 == 0) ifTrue:[^ true] |
|
1027 |
]. |
|
1028 |
^ false |
|
1029 |
||
1030 |
" |
|
1031 |
Date leapYear:1992 |
|
1032 |
Date leapYear:1994 |
|
1033 |
Date leapYear:1900 |
|
1034 |
Date leapYear:2000 |
|
1035 |
" |
|
1036 |
! |
|
1037 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1038 |
longFormatString |
8118 | 1039 |
(LongFormats isNil or:[EnvironmentChange]) ifTrue:[ |
1040 |
self initNames |
|
1041 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1042 |
^ LongFormats at:Language ifAbsent:(LongFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1043 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1044 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1045 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1046 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1047 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1048 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1049 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1050 |
|
699 | 1051 |
monthAndDayFromDayInYear:aDayInYear forYear:yearInteger |
1052 |
"given a day-in-year (1..365) return an Array containing the |
|
1053 |
month index and the day-in-month. Return nil if the argument is invalid." |
|
1054 |
||
1055 |
|restDays daysInMonth| |
|
1056 |
||
1057 |
restDays := aDayInYear. |
|
1058 |
restDays < 1 ifTrue:[^ nil]. |
|
1059 |
||
1060 |
1 to:12 do:[:m | |
|
1061 |
daysInMonth := self daysInMonthIndex:m forYear:yearInteger. |
|
1062 |
restDays <= daysInMonth ifTrue:[ |
|
1063 |
^ Array with:m with:restDays |
|
1064 |
]. |
|
1065 |
restDays := restDays - daysInMonth |
|
1066 |
]. |
|
1067 |
restDays > daysInMonth ifTrue:[^ nil]. |
|
1068 |
^ Array with:12 with:restDays |
|
1069 |
||
1070 |
" |
|
1071 |
Date monthAndDayFromDayInYear:66 forYear:1980 |
|
1072 |
Date monthAndDayFromDayInYear:66 forYear:1981 |
|
1073 |
" |
|
1074 |
! |
|
1075 |
||
1076 |
nameOfDay:dayIndex |
|
1077 |
"given a day index (1..7), return the name of the day" |
|
1078 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1079 |
^ self nameOfDay:dayIndex language:nil |
699 | 1080 |
|
1081 |
" |
|
8795 | 1082 |
Date nameOfDay:1 |
699 | 1083 |
Date nameOfDay:4 |
1084 |
" |
|
1085 |
! |
|
1086 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1087 |
nameOfDay:dayIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1088 |
"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
|
1089 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1090 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1091 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1092 |
^ (self dayNamesForLanguage:lang) at:dayIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1093 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1094 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1095 |
Date nameOfDay:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1096 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1097 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1098 |
|
699 | 1099 |
nameOfMonth:monthIndex |
1100 |
"given a month index (1..12), return the name of the month" |
|
1101 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1102 |
^ self nameOfMonth:monthIndex language:nil |
699 | 1103 |
|
1104 |
" |
|
1105 |
Date nameOfMonth:11 |
|
1106 |
Date nameOfMonth:12 |
|
1107 |
Date nameOfMonth:4 |
|
1108 |
" |
|
1109 |
! |
|
1110 |
||
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1111 |
nameOfMonth:monthIndex language:lang |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1112 |
"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
|
1113 |
For nil, Smalltalk language is used, |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1114 |
for unknown languages, english is used." |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1115 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1116 |
^ (self monthNamesForLanguage:lang) at:monthIndex |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1117 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1118 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1119 |
Date nameOfMonth:11 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1120 |
Date nameOfMonth:12 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1121 |
Date nameOfMonth:4 language:#en |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1122 |
" |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1123 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1124 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1125 |
shortFormatString |
8118 | 1126 |
(ShortFormats isNil or:[EnvironmentChange]) ifTrue:[ |
1127 |
self initNames |
|
1128 |
]. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1129 |
^ ShortFormats at:Language ifAbsent:(ShortFormats at:#en). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1130 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1131 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1132 |
Date today printStringFormat:(Date defaultFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1133 |
Date today printStringFormat:(Date longFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1134 |
Date today printStringFormat:(Date shortFormatString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1135 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1136 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
1137 |
|
5548 | 1138 |
weekInYearOf:aDateOrTimestamp |
1139 |
"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
|
1140 |
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
|
1141 |
The above definition can lead to the 1st week starting in the old year!!" |
5548 | 1142 |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1143 |
|dayInYear numDays dayOfFirstWeekInYear dayOfFirstWeekInNextYear week| |
5548 | 1144 |
|
1145 |
dayInYear := aDateOrTimestamp dayInYear. |
|
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1146 |
dayOfFirstWeekInYear := self dayOfFirstWeekInYear:aDateOrTimestamp year. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1147 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1148 |
numDays := aDateOrTimestamp asDate subtractDate:dayOfFirstWeekInYear asDate. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1149 |
"/ 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
|
1150 |
numDays < 0 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1151 |
"/ not in a week here ... |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1152 |
"/ 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
|
1153 |
^ 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
|
1154 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1155 |
|
5548 | 1156 |
"/ compute the week |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1157 |
week := numDays // 7 + 1. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1158 |
|
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1159 |
"/ 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
|
1160 |
week == 53 ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1161 |
dayOfFirstWeekInNextYear := self dayOfFirstWeekInYear:aDateOrTimestamp year + 1. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1162 |
aDateOrTimestamp asDate >= dayOfFirstWeekInNextYear asDate ifTrue:[ |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1163 |
^ 1 |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1164 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1165 |
]. |
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
1166 |
^ week |
5548 | 1167 |
|
1168 |
" |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
1169 |
Timestamp now weekInYear |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1170 |
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
|
1171 |
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
|
1172 |
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
|
1173 |
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
|
1174 |
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
|
1175 |
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
|
1176 |
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
|
1177 |
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
|
1178 |
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
|
1179 |
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
|
1180 |
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
|
1181 |
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
|
1182 |
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
|
1183 |
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
|
1184 |
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
|
1185 |
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
|
1186 |
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
|
1187 |
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
|
1188 |
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
|
1189 |
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
|
1190 |
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
|
1191 |
Date weekInYearOf:(Date newDay:7 month:1 year:2002) |
5548 | 1192 |
" |
1193 |
! |
|
1194 |
||
699 | 1195 |
yearAsDays: yearInteger |
1196 |
"Returns the number of days since Jan 1, 1901. (GNU) |
|
1197 |
to the first Jan of the year, yearInteger. |
|
1198 |
For 1901 this is zero, for 1902 its 365. |
|
1199 |
Defined for years >= 1901" |
|
1200 |
||
1201 |
|y "{ Class: SmallInteger }"| |
|
1202 |
||
1203 |
y := yearInteger - 1900. |
|
1204 |
y := y - 1. |
|
1205 |
^ (y * 365) |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1206 |
+ (y // 4) |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1207 |
- (y // 100) |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1208 |
+ ((y + 300) // 400) |
699 | 1209 |
|
1210 |
" |
|
11349
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1211 |
Date yearAsDays:5 |
699 | 1212 |
Date yearAsDays:1901 |
1213 |
Date yearAsDays:1902 |
|
1214 |
Date yearAsDays:1903 |
|
1215 |
Date yearAsDays:1904 |
|
1216 |
Date yearAsDays:1905 |
|
1217 |
Date yearAsDays:1994 |
|
1218 |
(Date yearAsDays:2001) - (Date yearAsDays:2000) |
|
1219 |
" |
|
1220 |
! ! |
|
1221 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1222 |
!Date class methodsFor:'obsolete'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1223 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1224 |
day:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1225 |
"return a new Date, given the day, month and year. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1226 |
Obsolete: |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1227 |
use newDay:month:year: for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1228 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1229 |
<resource: #obsolete> |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1230 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1231 |
^ self newDay:day month:month year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1232 |
! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1233 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1234 |
day:dayInYear year:year |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1235 |
"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
|
1236 |
Obsolete: |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1237 |
use newDay:year: for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1238 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1239 |
<resource: #obsolete> |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1240 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1241 |
^ self newDay:dayInYear year:year |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1242 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1243 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1244 |
isLeapYear:yearInteger |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1245 |
"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
|
1246 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1247 |
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
|
1248 |
since this method will vanish." |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1249 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1250 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1251 |
^ self leapYear:yearInteger |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1252 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1253 |
|
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
1254 |
!Date class methodsFor:'private'! |
1 | 1255 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1256 |
dayAbbrevsForLanguage:language |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1257 |
|langDayAbbrevs| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1258 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1259 |
(DayAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1260 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1261 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1262 |
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
|
1263 |
langDayAbbrevs isNil ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1264 |
langDayAbbrevs := DayAbbrevs at:#en. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1265 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1266 |
^ langDayAbbrevs |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1267 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1268 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1269 |
dayNamesForLanguage:language |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1270 |
|langDayNames| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1271 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1272 |
(DayNames isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1273 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1274 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1275 |
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
|
1276 |
langDayNames isNil ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1277 |
langDayNames := DayNames at:#en. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1278 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1279 |
^ langDayNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1280 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1281 |
|
699 | 1282 |
daysInMonthIndex: monthIndex forYear: yearInteger |
1283 |
"return the number of days in month monthIndex of |
|
1284 |
year yearInteger (modified GNU). |
|
1285 |
Return 0 for invalid month index. |
|
1286 |
This is the internal version of daysInMonth:forYear:" |
|
1287 |
||
1288 |
|days| |
|
1289 |
||
1290 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
|
1291 |
||
1292 |
days := #(31 28 31 "Jan Feb Mar" |
|
1293 |
30 31 30 "Apr May Jun" |
|
1294 |
31 31 30 "Jul Aug Sep" |
|
1295 |
31 30 31 "Oct Nov Dec" |
|
1296 |
) at: monthIndex. |
|
1297 |
||
1298 |
(monthIndex == 2) ifTrue:[ |
|
1299 |
(self leapYear:yearInteger) ifTrue:[ |
|
1300 |
^ days + 1 |
|
1301 |
] |
|
1302 |
]. |
|
1303 |
^ days |
|
1304 |
||
1305 |
" |
|
1306 |
Date daysInMonthIndex:2 forYear:1994 |
|
1307 |
Date daysInMonthIndex:2 forYear:1980 |
|
1308 |
Date daysInMonthIndex:2 forYear:1981 |
|
1309 |
" |
|
1310 |
! |
|
1311 |
||
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1312 |
daysUntilMonthIndex: monthIndex forYear: yearInteger |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1313 |
"return the number of days in month monthIndex of |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1314 |
year yearInteger (modified GNU). |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1315 |
Return 0 for invalid month index. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1316 |
This is the internal version of daysInMonth:forYear:" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1317 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1318 |
|days| |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1319 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1320 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1321 |
|sum| |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1322 |
sum := 0. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1323 |
#(31 28 31 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1324 |
30 31 30 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1325 |
31 31 30 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1326 |
31 30 31 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1327 |
) collect:[:each | |first| first:= sum. sum := sum + each. first] |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1328 |
#(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
|
1329 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1330 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1331 |
(monthIndex between:1 and:12) ifFalse:[^ 0]. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1332 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1333 |
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
|
1334 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1335 |
(monthIndex > 2) ifTrue:[ |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1336 |
(self leapYear:yearInteger) ifTrue:[ |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1337 |
^ days + 1 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1338 |
] |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1339 |
]. |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1340 |
^ days |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1341 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1342 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1343 |
Date daysUntilMonthIndex:3 forYear:1994 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1344 |
Date daysUntilMonthIndex:3 forYear:1980 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1345 |
Date daysUntilMonthIndex:3 forYear:1981 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1346 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1347 |
! |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1348 |
|
7793
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1349 |
monthAbbrevsForLanguage:language |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1350 |
|langMonthAbbrevs| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1351 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1352 |
(MonthAbbrevs isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1353 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1354 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1355 |
langMonthAbbrevs := MonthAbbrevs at:(language ? Smalltalk language) ifAbsent:nil. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1356 |
langMonthAbbrevs isNil ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1357 |
langMonthAbbrevs := MonthAbbrevs at:#en. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1358 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1359 |
^ langMonthAbbrevs |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1360 |
! |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1361 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1362 |
monthNamesForLanguage:language |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1363 |
|langMonthNames| |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1364 |
|
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1365 |
(MonthNames isNil or:[EnvironmentChange]) ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1366 |
self initNames |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1367 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1368 |
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
|
1369 |
langMonthNames isNil ifTrue:[ |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1370 |
langMonthNames := MonthNames at:#en. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1371 |
]. |
8abaefe33259
keep english strings for day/month names/abbrevs
Claus Gittinger <cg@exept.de>
parents:
7673
diff
changeset
|
1372 |
^ langMonthNames |
54 | 1373 |
! ! |
1374 |
||
7258 | 1375 |
!Date class methodsFor:'private-encoding'! |
54 | 1376 |
|
1377 |
encodeYear:y month:m day:d |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1378 |
"the internal encoding is strictly private, |
92 | 1379 |
and should not be used outside." |
1380 |
||
54 | 1381 |
^ (((y * 100) + m) * 100) + d |
1382 |
! ! |
|
1383 |
||
7258 | 1384 |
!Date class methodsFor:'private-instance creation'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1385 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1386 |
fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1387 |
"return a date, representing the date given by the operatingSystem time. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1388 |
This somewhat clumsy implementation hides the OS's date representation |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1389 |
(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
|
1390 |
Dont use this method, the osTime representation is totally unportable." |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1391 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1392 |
^ self basicNew fromOSTime:osTime |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1393 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1394 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1395 |
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
|
1396 |
thats where Unix time starts |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1397 |
On other systems, it may be something different. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1398 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1399 |
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
|
1400 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1401 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1402 |
|
7261 | 1403 |
!Date methodsFor:'Compatibility-ANSI'! |
6419 | 1404 |
|
1405 |
dayOfWeek |
|
1406 |
"return the week-day of the receiver - 1 is sunday, 7 for saturday. |
|
1407 |
WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday). |
|
1408 |
" |
|
1409 |
||
1410 |
|d| |
|
1411 |
||
1412 |
d := self dayInWeek. |
|
1413 |
d == 7 ifTrue:[ |
|
1414 |
^ 1 |
|
1415 |
]. |
|
1416 |
^ d + 1 |
|
1417 |
||
1418 |
" |
|
1419 |
Date today dayOfWeek |
|
1420 |
Date today dayInWeek |
|
1421 |
" |
|
1422 |
! |
|
1423 |
||
1424 |
dayOfWeekAbbreviation |
|
1425 |
"return the short week-day of the receiver as a string. |
|
1426 |
The returned string depends on the language setting. |
|
1427 |
Expect things like 'mon', 'tue' ..." |
|
1428 |
||
1429 |
^ self abbreviatedDayName |
|
1430 |
||
1431 |
" |
|
1432 |
Date today dayOfWeekAbbreviation |
|
1433 |
" |
|
1434 |
! |
|
1435 |
||
1436 |
dayOfWeekName |
|
1437 |
"return the week-day of the receiver as a string. |
|
1438 |
The returned string depends on the language setting. |
|
1439 |
Expect things like 'monday', 'tuesday' ..." |
|
1440 |
||
1441 |
^ self weekday |
|
1442 |
||
1443 |
" |
|
1444 |
Date today dayOfWeekName |
|
1445 |
Date today dayOfWeekAbbreviation |
|
1446 |
" |
|
1447 |
! |
|
1448 |
||
1449 |
dayOfYear |
|
1450 |
"return the day-nr within the year of the receiver - 1..365/366" |
|
1451 |
||
1452 |
^ self dayInYear |
|
1453 |
||
1454 |
" |
|
1455 |
Date today dayOfYear |
|
1456 |
" |
|
1457 |
! |
|
1458 |
||
1459 |
isLeapYear |
|
1460 |
"return true, if the receivers year is a leap year" |
|
1461 |
||
1462 |
^ self leap |
|
1463 |
||
1464 |
" |
|
1465 |
Date today isLeapYear |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1466 |
(Date newDay:1 month:1 year:1992) isLeapYear |
6419 | 1467 |
" |
1468 |
! |
|
1469 |
||
1470 |
monthAbbreviation |
|
1471 |
"return the month of the receiver as a string. |
|
1472 |
The returned string depends on the language setting. |
|
1473 |
Expect things like 'jan', 'feb' ..." |
|
1474 |
||
1475 |
^ self abbreviatedMonthName |
|
1476 |
||
1477 |
" |
|
1478 |
Date today monthAbbreviation |
|
1479 |
" |
|
1480 |
! ! |
|
1481 |
||
7261 | 1482 |
!Date methodsFor:'Compatibility-ST80'! |
5515 | 1483 |
|
6976 | 1484 |
previous:dayName |
1485 |
"Return the previous date whose weekday name is dayName. |
|
1486 |
Caveat; dayName is expected to be in the current language" |
|
1487 |
||
1488 |
^ self subtractDays:(self weekdayIndex - (self class dayOfWeek:dayName) - 1 \\ 7 + 1) |
|
1489 |
||
1490 |
" |
|
1491 |
Date today |
|
1492 |
Date today previous:#Monday |
|
1493 |
Date today previous:#Friday |
|
1494 |
" |
|
1495 |
! |
|
1496 |
||
7023 | 1497 |
printFormat:aFormatArray |
1498 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
1499 |
Return a string containing a printed representation of the receiver. |
|
1500 |
The formatArray argument consists of 6 or 7 integers which control |
|
1501 |
the resulting string. The entries are: |
|
1502 |
1 day position (1, 2 or 3) |
|
1503 |
2 month position (1..3) |
|
1504 |
3 year position (1..3) |
|
1505 |
4 asciiValue of separator character or separator character |
|
1506 |
or collection of 2 separator characters |
|
1507 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
1508 |
4: abbreviated uppercase 5: full uppercase) |
|
1509 |
6 year format (1 include century; 2 exclude century) |
|
1510 |
7 (optional) true/false. |
|
1511 |
if true, print numbers in 2-digit format |
|
1512 |
(i.e. with leading zeros); |
|
1513 |
Taken as false, if ommited |
|
1514 |
||
1515 |
Day and monthnames are in the currently active language. |
|
1516 |
||
1517 |
This method supports more options than the ST-80 version; month formats |
|
1518 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
1519 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
1520 |
||
1521 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
1522 |
This is an ST-80 compatibility method - I would have choosen another |
|
1523 |
(less cryptic) formatString ... |
|
1524 |
" |
|
1525 |
||
7961 | 1526 |
^ self printFormat:aFormatArray forLanguage:nil |
1527 |
||
1528 |
" |
|
1529 |
Date today printFormat:#(1 2 3 '' 1 2) |
|
1530 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
1531 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
|
1532 |
Date today printFormat:#(2 1 3 32 3 1) |
|
1533 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
1534 |
Date today printFormat:#(1 2 3 $- 2 1) |
|
1535 |
Date today printFormat:#(1 2 3 $- 4 1) |
|
1536 |
" |
|
1537 |
! |
|
1538 |
||
1539 |
printFormat:aFormatArray forLanguage:languageOrNil |
|
1540 |
"Obsolete, backward ST-80 compatible formatted printing - see printStringFormat: |
|
1541 |
Return a string containing a printed representation of the receiver. |
|
1542 |
The formatArray argument consists of 6 or 7 integers which control |
|
1543 |
the resulting string. The entries are: |
|
1544 |
1 day position (1, 2 or 3) |
|
1545 |
2 month position (1..3) |
|
1546 |
3 year position (1..3) |
|
1547 |
4 asciiValue of separator character or separator character |
|
1548 |
or collection of 2 separator characters |
|
1549 |
5 month format (1: numeric; 2: abbreviated name; 3: fullname |
|
1550 |
4: abbreviated uppercase 5: full uppercase) |
|
1551 |
6 year format (1 include century; 2 exclude century) |
|
1552 |
7 (optional) true/false. |
|
1553 |
if true, print numbers in 2-digit format |
|
1554 |
(i.e. with leading zeros); |
|
1555 |
Taken as false, if ommited |
|
1556 |
||
1557 |
Day and monthnames are in the currently active language. |
|
1558 |
||
1559 |
This method supports more options than the ST-80 version; month formats |
|
1560 |
4 and 5, non-numeric separators and the optional 7th parameter are not |
|
1561 |
supported by ST-80. Be aware of this for compatibility reasons. |
|
1562 |
||
1563 |
Notice that not all formats can be scanned (correctly) by #readFrom: |
|
1564 |
This is an ST-80 compatibility method - I would have choosen another |
|
1565 |
(less cryptic) formatString ... |
|
1566 |
" |
|
1567 |
||
7023 | 1568 |
|mf upperCase day month year components sep1 sep2 leadingZeros| |
1569 |
||
1570 |
aFormatArray size > 6 ifTrue:[ |
|
1571 |
leadingZeros := aFormatArray at:7 |
|
1572 |
] ifFalse:[ |
|
1573 |
leadingZeros := false. |
|
1574 |
]. |
|
1575 |
||
1576 |
components := Array new:3. |
|
1577 |
day := self day. |
|
1578 |
leadingZeros ifTrue:[ |
|
1579 |
day := day printStringLeftPaddedTo:2 with:$0 |
|
1580 |
] ifFalse:[ |
|
1581 |
day := day printString |
|
1582 |
]. |
|
1583 |
components at:(aFormatArray at:1) put:day. |
|
1584 |
||
1585 |
upperCase := false. |
|
1586 |
mf := aFormatArray at:5. |
|
1587 |
(mf between:4 and:5) ifTrue:[mf := mf - 2. upperCase := true]. |
|
1588 |
||
1589 |
mf == 1 ifTrue:[ |
|
1590 |
month := self month. |
|
1591 |
leadingZeros ifTrue:[ |
|
1592 |
month := month printStringLeftPaddedTo:2 with:$0 |
|
1593 |
] ifFalse:[ |
|
1594 |
month := month printString |
|
1595 |
] |
|
1596 |
] ifFalse:[ |
|
1597 |
mf == 2 ifTrue:[ |
|
7961 | 1598 |
month := self abbreviatedMonthNameForLanguage:languageOrNil |
7023 | 1599 |
] ifFalse:[ |
7961 | 1600 |
month := self monthNameForLanguage:languageOrNil |
7023 | 1601 |
] |
1602 |
]. |
|
1603 |
upperCase ifTrue:[month := month asUppercase]. |
|
1604 |
components at:(aFormatArray at:2) put:month. |
|
1605 |
||
1606 |
year := self year. |
|
1607 |
(aFormatArray at:6) == 2 ifTrue:[ |
|
1608 |
year := year \\ 100. |
|
1609 |
year := year printStringLeftPaddedTo:2 with:$0 |
|
1610 |
]. |
|
1611 |
year := year printString. |
|
1612 |
components at:(aFormatArray at:3) put:year. |
|
1613 |
||
1614 |
sep1 := sep2 := (aFormatArray at:4). |
|
1615 |
sep1 isString ifFalse:[ |
|
1616 |
sep1 isCollection ifTrue:[ |
|
1617 |
sep2 := (sep1 at:2). |
|
1618 |
sep1 := (sep1 at:1). |
|
1619 |
] ifFalse:[ |
|
1620 |
sep1 := sep2 := sep1 asCharacter |
|
1621 |
] |
|
1622 |
]. |
|
1623 |
||
1624 |
^ (components at:1) |
|
1625 |
, sep1 asString |
|
1626 |
, (components at:2) |
|
1627 |
, sep2 asString |
|
1628 |
, (components at:3) |
|
1629 |
||
1630 |
" |
|
7961 | 1631 |
Date today printFormat:#(1 2 3 '' 1 2) |
1632 |
Date today printFormat:#(1 2 3 $- 1 2) |
|
7023 | 1633 |
Date today printFormat:#(1 2 3 $. 1 2 true) |
1634 |
Date today printFormat:#(2 1 3 32 3 1) |
|
1635 |
Date today printFormat:#(2 1 3 #(' ' ', ') 3 1) |
|
7961 | 1636 |
Date today printFormat:#(1 2 3 $- 2 1) forLanguage:#en |
1637 |
Date today printFormat:#(1 2 3 $- 4 1) forLanguage:#en |
|
1638 |
" |
|
1639 |
! |
|
1640 |
||
1641 |
printFormat:aFormatArray forLanguage:languageOrNil on:aStream |
|
1642 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
1643 |
in printFormat:. |
|
1644 |
Append a printed representation of the receiver to aStream. |
|
1645 |
The argument, aFormatString controls the format, as described |
|
1646 |
in the #printFormat: method. |
|
1647 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
1648 |
||
1649 |
aStream nextPutAll:(self printFormat:aFormatArray forLanguage:languageOrNil) |
|
1650 |
||
1651 |
||
1652 |
"european formats: |
|
1653 |
||
1654 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
1655 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
1656 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1657 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
1658 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
1659 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
1660 |
||
1661 |
US formats: |
|
1662 |
||
1663 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
1664 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
1665 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
1666 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
1667 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
1668 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1669 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
7023 | 1670 |
" |
1671 |
! |
|
1672 |
||
1673 |
printFormat:aFormatArray on:aStream |
|
1674 |
"Obsolete, backward ST-80 compatible formatted printing - see comment |
|
1675 |
in printFormat:. |
|
1676 |
Append a printed representation of the receiver to aStream. |
|
1677 |
The argument, aFormatString controls the format, as described |
|
1678 |
in the #printFormat: method. |
|
1679 |
Notice that not all formats can be scanned (correctly) by #readFrom:" |
|
1680 |
||
1681 |
aStream nextPutAll:(self printFormat:aFormatArray) |
|
1682 |
||
1683 |
||
1684 |
"european formats: |
|
1685 |
||
1686 |
Date today printFormat:#(1 2 3 $- 1 2) on:Transcript. Transcript cr. |
|
1687 |
Date today printFormat:#(1 2 3 $- 2 2) on:Transcript. Transcript cr. |
|
1688 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1689 |
Date today printFormat:#(1 2 3 $- 3 2) on:Transcript. Transcript cr. |
|
1690 |
Date today printFormat:#(1 2 3 $. 1 2) on:Transcript. Transcript cr. |
|
1691 |
Date today printFormat:#(1 2 3 $. 1 2 true) on:Transcript. Transcript cr. |
|
1692 |
||
1693 |
US formats: |
|
1694 |
||
1695 |
Date today printFormat:#(2 1 3 32 3 1) on:Transcript. Transcript cr. |
|
1696 |
Date today printFormat:#(2 1 3 32 2 2) on:Transcript. Transcript cr. |
|
1697 |
Date today printFormat:#(2 1 3 $/ 1 2) on:Transcript. Transcript cr. |
|
1698 |
Date today printFormat:#(2 1 3 $- 2 1) on:Transcript. Transcript cr. |
|
1699 |
Date today printFormat:#(2 1 3 #(' ' ', ') 2 1) on:Transcript. Transcript cr. |
|
1700 |
Date today printFormat:#(1 2 3 $- 2 1) on:Transcript. Transcript cr. |
|
1701 |
Date today printFormat:#(1 2 3 $- 4 1) on:Transcript. Transcript cr. |
|
1702 |
" |
|
1703 |
! |
|
1704 |
||
5515 | 1705 |
shortPrintString |
1706 |
"dummy - for now" |
|
1707 |
||
1708 |
^ self printString |
|
1709 |
||
1710 |
"Created: 20.6.1997 / 17:16:48 / cg" |
|
6976 | 1711 |
! |
1712 |
||
1713 |
weekdayIndex |
|
1714 |
"Return the day index; Monday=1, ... , Sunday=7" |
|
1715 |
||
1716 |
^ (self asDays + 1) \\ 7 + 1 "1 January 1901 was a Tuesday" |
|
1717 |
||
1718 |
" |
|
1719 |
Date today dayName |
|
1720 |
Date today weekdayIndex |
|
1721 |
" |
|
5515 | 1722 |
! ! |
1723 |
||
7261 | 1724 |
!Date methodsFor:'Compatibility-Squeak'! |
4407 | 1725 |
|
1726 |
mmddyyyy |
|
4462 | 1727 |
"return a printed representation of the receiver in the |
1728 |
form mmddyyyy. |
|
1729 |
The receiver can be reconstructed with: |
|
1730 |
Date readMMDDYYYYFrom:aStringOrStream onError:[...]" |
|
1731 |
||
11182 | 1732 |
^ self printStringFormat:'%m%d%y' |
1733 |
||
1734 |
"/ ^ (self month printStringLeftPaddedTo:2 with:$0) |
|
1735 |
"/ , (self day printStringLeftPaddedTo:2 with:$0) |
|
1736 |
"/ , (self year printStringLeftPaddedTo:4 with:$0) |
|
4407 | 1737 |
|
1738 |
" |
|
1739 |
Date today mmddyyyy |
|
1740 |
" |
|
11181 | 1741 |
! |
1742 |
||
1743 |
yyyymmdd |
|
1744 |
"return a printed representation of the receiver in the |
|
1745 |
form yyyymmdd. |
|
1746 |
The receiver can be reconstructed with: |
|
1747 |
Date readYYYYMMDDFrom:aStringOrStream onError:[...]" |
|
1748 |
||
11182 | 1749 |
^ self printStringFormat:'%y%m%d' |
1750 |
||
1751 |
"/ ^ (self year printStringLeftPaddedTo:4 with:$0) |
|
1752 |
"/ , (self month printStringLeftPaddedTo:2 with:$0) |
|
1753 |
"/ , (self day printStringLeftPaddedTo:2 with:$0) |
|
11181 | 1754 |
|
1755 |
" |
|
11182 | 1756 |
Date today yyyymmdd |
11181 | 1757 |
" |
4407 | 1758 |
! ! |
1759 |
||
699 | 1760 |
!Date methodsFor:'accessing'! |
241 | 1761 |
|
699 | 1762 |
abbreviatedDayName |
1763 |
"return the short week-day of the receiver as a string. |
|
1764 |
The returned string depends on the language setting. |
|
1765 |
Expect things like 'mon', 'tue' ..." |
|
54 | 1766 |
|
699 | 1767 |
^ self class abbreviatedNameOfDay:(self dayInWeek) |
92 | 1768 |
|
1769 |
" |
|
699 | 1770 |
Date today abbreviatedDayName |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1771 |
(Date newDay:15 month:4 year:1959) abbreviatedDayName |
92 | 1772 |
" |
1773 |
! |
|
1774 |
||
699 | 1775 |
abbreviatedMonthName |
1776 |
"return the month of the receiver as a string. |
|
1777 |
The returned string depends on the language setting. |
|
1778 |
Expect things like 'jan', 'feb' ..." |
|
54 | 1779 |
|
699 | 1780 |
^ self class abbreviatedNameOfMonth:(self month) |
68 | 1781 |
|
92 | 1782 |
" |
699 | 1783 |
Date today abbreviatedMonthName |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1784 |
(Date newDay:15 month:4 year:1959) abbreviatedMonthName |
92 | 1785 |
" |
1786 |
! |
|
1787 |
||
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1788 |
abbreviatedMonthNameForLanguage:lang |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1789 |
"return the month of the receiver as a string. |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1790 |
The returned string depends on the language setting. |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1791 |
Expect things like 'jan', 'feb' ..." |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1792 |
|
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1793 |
^ self class abbreviatedNameOfMonth:(self month) language:lang |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1794 |
|
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1795 |
" |
7961 | 1796 |
Date today abbreviatedMonthNameForLanguage:#en |
1797 |
Date today abbreviatedMonthNameForLanguage:#de |
|
7794
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1798 |
" |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1799 |
! |
7f1901b11541
accessor for language specific abbreviated month name
penk
parents:
7793
diff
changeset
|
1800 |
|
92 | 1801 |
asDays |
1802 |
"return the number of days elapsed since 01-Jan-1901 |
|
1803 |
and the receiver's day; starts with 0 for 1-1-1901. |
|
1804 |
Date>>fromDays: is the reverse operation. |
|
1805 |
For ST-80 compatibility." |
|
68 | 1806 |
|
1807 |
|yr| |
|
1808 |
||
1809 |
yr := self year. |
|
1810 |
^ (self class yearAsDays:yr) |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
1811 |
+ (self class daysUntilMonthIndex:self month forYear:yr) |
68 | 1812 |
+ self day |
85 | 1813 |
- 1 |
68 | 1814 |
|
92 | 1815 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1816 |
(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
|
1817 |
(Date newDay: 1 month: 1 year: 1901) asDays -> 0 |
92 | 1818 |
Date today asDays |
1819 |
Date fromDays:(Date today asDays + 7) |
|
1820 |
" |
|
77 | 1821 |
! |
1822 |
||
1823 |
asSeconds |
|
92 | 1824 |
"return the seconds between 1.jan.1901 and the same time in the receivers |
1825 |
day. (i.e. midnight to midnight). |
|
1501 | 1826 |
This does not include any leapSeconds ... strictly speaking, this is incorrect. |
77 | 1827 |
ST-80 compatibility." |
1828 |
||
92 | 1829 |
^ 60*60*24 * self asDays |
77 | 1830 |
|
92 | 1831 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1832 |
(Date newDay: 5 month: 8 year: 1962) asSeconds |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1833 |
(Date newDay: 1 month: 1 year: 1901) asSeconds |
92 | 1834 |
(Date today addDays:7) asSeconds - Date today asSeconds |
1501 | 1835 |
" |
1836 |
||
1837 |
"Modified: 1.7.1996 / 14:19:17 / cg" |
|
699 | 1838 |
! |
1839 |
||
1840 |
day |
|
1841 |
"return the day (1..31) of the receiver" |
|
1842 |
||
1843 |
^ dateEncoding \\ 100 |
|
1844 |
||
8626 | 1845 |
"example: |
699 | 1846 |
Date today day |
1847 |
" |
|
1848 |
! |
|
1849 |
||
1850 |
dayInWeek |
|
5778 | 1851 |
"return the week-day of the receiver - 1 for monday, 7 for sunday. |
6419 | 1852 |
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
|
1853 |
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
|
1854 |
(i.e. do not use this for dates before 1583) |
5778 | 1855 |
" |
699 | 1856 |
|
3256
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1857 |
|wday| |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1858 |
|
5778 | 1859 |
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
|
1860 |
+ self asDays) \\ 7 + 1. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1861 |
wday < 1 ifTrue:[ |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1862 |
wday := wday + 7 |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1863 |
]. |
637d16a0c83b
care for date before 1.1.1900 in dayInWeek.
Claus Gittinger <cg@exept.de>
parents:
2706
diff
changeset
|
1864 |
^ wday |
699 | 1865 |
|
1866 |
" |
|
5778 | 1867 |
Date today dayInWeek |
5548 | 1868 |
Date tomorrow dayInWeek |
1869 |
Date yesterday dayInWeek |
|
5778 | 1870 |
(Date today subtractDays:2) dayInWeek |
3257 | 1871 |
Date today weekday |
5548 | 1872 |
Date tomorrow weekday |
1873 |
Date yesterday weekday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1874 |
(Date newDay:15 month:4 year:1959) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1875 |
(Date newDay:1 month:1 year:1901) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1876 |
(Date newDay:31 month:12 year:1900) dayInWeek |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1877 |
(Date newDay:31 month:12 year:1899) dayInWeek |
699 | 1878 |
" |
1501 | 1879 |
|
3257 | 1880 |
"Modified: / 1.2.1998 / 14:10:27 / cg" |
699 | 1881 |
! |
1882 |
||
5548 | 1883 |
dayInYear |
1884 |
"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
|
1885 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1886 |
" |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1887 |
|daysSoFar| |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1888 |
daysSoFar := 0. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1889 |
#(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
|
1890 |
" |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1891 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1892 |
|days month| |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1893 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1894 |
month := self month. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1895 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1896 |
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
|
1897 |
days := days + self day. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1898 |
(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
|
1899 |
days := days + 1. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1900 |
]. |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1901 |
|
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1902 |
^ days |
5548 | 1903 |
|
1904 |
" |
|
1905 |
Date today dayInYear |
|
1906 |
(Date newDay:1 year:1999) dayInYear |
|
1907 |
(Date newDay:1 year:2000) dayInYear |
|
1908 |
(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
|
1909 |
(Date newDay:59 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1910 |
(Date newDay:60 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1911 |
(Date newDay:61 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1912 |
(Date newDay:366 year:2004) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1913 |
(Date newDay:59 year:2005) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1914 |
(Date newDay:60 year:2005) dayInYear |
8ce689609977
Fix computation and printing of dates before 1901.
Stefan Vogel <sv@exept.de>
parents:
11182
diff
changeset
|
1915 |
(Date newDay:365 year:2005) dayInYear |
5548 | 1916 |
" |
1917 |
! |
|
1918 |
||
77 | 1919 |
dayOfMonth |
1920 |
"Answer the day of the month represented by me. |
|
1921 |
Same as day; for ST-80 compatibility." |
|
1922 |
||
1923 |
^ self day |
|
92 | 1924 |
|
1925 |
" |
|
1926 |
Date today dayOfMonth |
|
1927 |
" |
|
1928 |
! |
|
1929 |
||
1930 |
daysInMonth |
|
1931 |
"return the number of days in the month of the receiver" |
|
1932 |
||
1933 |
^ Date daysInMonth:(self month) forYear:(self year) |
|
1934 |
||
1935 |
" |
|
1936 |
Date today daysInMonth |
|
1937 |
" |
|
1938 |
! |
|
1939 |
||
1940 |
daysInYear |
|
1941 |
"return the number of days in the year of the receiver" |
|
1942 |
||
1943 |
^ Date daysInYear:(self year) |
|
1944 |
||
1945 |
" |
|
1946 |
Date today daysInYear |
|
1947 |
" |
|
1948 |
! |
|
1949 |
||
5778 | 1950 |
daysLeftInMonth |
1951 |
"return the number of days left in the month of the receiver" |
|
1952 |
||
1953 |
^ self daysInMonth - self day |
|
1954 |
||
1955 |
" |
|
1956 |
Date today daysLeftInMonth |
|
1957 |
" |
|
1958 |
! |
|
1959 |
||
92 | 1960 |
daysLeftInYear |
11079
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
1961 |
"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
|
1962 |
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
|
1963 |
the first january will return 364)" |
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
1964 |
|
cd8abd9e87a7
oops - daysLeftInYear was wrong
Claus Gittinger <cg@exept.de>
parents:
10912
diff
changeset
|
1965 |
^ (Date daysInYear:(self year)) - self dayOfYear |
92 | 1966 |
|
1967 |
" |
|
5282 | 1968 |
Date today daysLeftInYear |
92 | 1969 |
" |
77 | 1970 |
! |
1971 |
||
699 | 1972 |
leap |
1973 |
"return true, if the receivers year is a leap year" |
|
68 | 1974 |
|
699 | 1975 |
^ Date leapYear:(self year) |
68 | 1976 |
|
92 | 1977 |
" |
699 | 1978 |
Date today leap |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
1979 |
(Date newDay:1 month:1 year:1992) leap |
92 | 1980 |
" |
68 | 1981 |
! |
1982 |
||
699 | 1983 |
month |
1984 |
"return the month (1..12) of the receiver" |
|
92 | 1985 |
|
699 | 1986 |
^ (dateEncoding // 100) \\ 100 |
68 | 1987 |
|
92 | 1988 |
" |
699 | 1989 |
Date today month |
92 | 1990 |
" |
68 | 1991 |
! |
1992 |
||
77 | 1993 |
monthIndex |
1994 |
"return the index of the month (e.g. Feb.=2). |
|
1995 |
Same as month; for ST-80 compatibility." |
|
1996 |
||
1997 |
^ self month |
|
1998 |
! |
|
1999 |
||
68 | 2000 |
monthName |
2001 |
"return the month of the receiver as a string. |
|
2002 |
The returned string depends on the language setting. |
|
2003 |
Expect things like 'january', 'february' ..." |
|
2004 |
||
2005 |
^ self class nameOfMonth:(self month) |
|
2006 |
||
92 | 2007 |
" |
2008 |
Date today monthName |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2009 |
(Date newDay:15 month:4 year:1959) monthName |
92 | 2010 |
" |
68 | 2011 |
! |
2012 |
||
7961 | 2013 |
monthNameForLanguage:languageOrNil |
2014 |
"return the month of the receiver as a string. |
|
2015 |
The returned string depends on the language setting. |
|
2016 |
Expect things like 'january', 'february' ..." |
|
2017 |
||
2018 |
^ self class nameOfMonth:(self month) language:languageOrNil |
|
2019 |
||
2020 |
" |
|
2021 |
Date today monthName |
|
2022 |
Date today monthNameForLanguage:#en |
|
2023 |
" |
|
2024 |
! |
|
2025 |
||
5548 | 2026 |
weekInYear |
2027 |
"return the week number of the receiver - 1 for Jan, 1st. |
|
2028 |
each week is Mon .. Sun (i.e. Sunday belongs to the previous week)" |
|
2029 |
||
2030 |
^ self class weekInYearOf:self |
|
2031 |
||
2032 |
" |
|
2033 |
Date today weekInYear |
|
2034 |
(Date newDay:1 year:2000) weekInYear was a saturday |
|
2035 |
(Date newDay:2 year:2000) weekInYear was a sunday |
|
2036 |
(Date newDay:3 year:2000) weekInYear was a monday |
|
2037 |
(Date newDay:4 year:2000) weekInYear was a tuesday |
|
2038 |
(Date newDay:5 year:2000) weekInYear was a wed |
|
2039 |
(Date newDay:6 year:2000) weekInYear was a thursday |
|
2040 |
(Date newDay:7 year:2000) weekInYear was a fri |
|
2041 |
(Date newDay:8 year:2000) weekInYear was a sat |
|
2042 |
(Date newDay:9 year:2000) weekInYear was a sun |
|
2043 |
(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
|
2044 |
(Date newDay:3 month:1 year:2001) weekInYear |
5548 | 2045 |
" |
2046 |
! |
|
2047 |
||
699 | 2048 |
weekday |
2049 |
"return the week-day of the receiver as a string. |
|
68 | 2050 |
The returned string depends on the language setting. |
699 | 2051 |
Expect things like 'monday', 'tuesday' ... |
2052 |
For ST-80 compatibility" |
|
2053 |
||
2054 |
^ self class nameOfDay:(self dayInWeek) |
|
2055 |
||
2056 |
" |
|
2057 |
Date today weekday |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2058 |
(Date newDay:15 month:4 year:1959) weekday |
699 | 2059 |
" |
2060 |
! |
|
2061 |
||
2062 |
year |
|
2063 |
"return the year (1..12) of the receiver" |
|
2064 |
||
2065 |
^ dateEncoding // (100*100) |
|
68 | 2066 |
|
699 | 2067 |
" |
2068 |
Date today year |
|
2069 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2070 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2071 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2072 |
year:year month:month day:day |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2073 |
dateEncoding := self class encodeYear:year month:month day:day |
699 | 2074 |
! ! |
2075 |
||
2076 |
!Date methodsFor:'arithmetic'! |
|
2077 |
||
8201 | 2078 |
+ days |
2079 |
"return a new date representing 'days' after the receiver. |
|
2080 |
The argument should be some kind of integer. |
|
2081 |
This is the same as #addDays." |
|
2082 |
||
2083 |
^ self class fromDays:(self asDays + days) |
|
2084 |
||
2085 |
" |
|
2086 |
Date today + 7. |
|
2087 |
||
2088 |
Date today to:(Date today + 28) by:7 do:[:date| |
|
2089 |
Transcript show:date weekday; show:', '; showCr:date |
|
2090 |
]. |
|
2091 |
" |
|
2092 |
! |
|
2093 |
||
2094 |
- aDateOrNumberOfDays |
|
2095 |
"return the delta in days (anInteger) between 2 dates or |
|
2096 |
subtract a number of days from a date returning a Date" |
|
2097 |
||
2098 |
aDateOrNumberOfDays class == self class ifTrue:[ |
|
2099 |
^ self asDays - aDateOrNumberOfDays asDays |
|
2100 |
]. |
|
2101 |
||
2102 |
^ self class fromDays:(self asDays - aDateOrNumberOfDays asInteger) |
|
2103 |
||
2104 |
" |
|
2105 |
Date today - Date yesterday |
|
2106 |
Date today - 3 |
|
2107 |
" |
|
2108 |
! |
|
2109 |
||
699 | 2110 |
addDays:days |
2111 |
"return a new date representing 'days' after the receiver. |
|
2112 |
The argument should be some kind of integer. |
|
2113 |
For ST-80 compatibility." |
|
2114 |
||
2115 |
^ self class fromDays:(self asDays + days) |
|
2116 |
||
2117 |
" |
|
2118 |
Date today addDays:7 |
|
2119 |
" |
|
2120 |
! |
|
2121 |
||
9262 | 2122 |
daysSince:aDate |
2123 |
"return the number of days between the receiver and the argument, |
|
2124 |
aDate, which should be some kind of date" |
|
2125 |
||
2126 |
^ self asDays - aDate asDays |
|
2127 |
||
2128 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2129 |
Date today daysSince:(Date newDay:1 month:1 year:1901) |
9262 | 2130 |
" |
2131 |
! |
|
2132 |
||
699 | 2133 |
daysUntil:aDate |
2134 |
"return the number of days between the receiver and the argument, |
|
8201 | 2135 |
aDate, which should be some kind of date" |
699 | 2136 |
|
2137 |
^ aDate asDays - self asDays |
|
68 | 2138 |
|
92 | 2139 |
" |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2140 |
(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
|
2141 |
(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
|
2142 |
(Date newDay:1 month:2 year:1994) daysUntil:(Date day:1 month:3 year:1994) |
699 | 2143 |
|
2144 |
|delta| |
|
2145 |
delta := Date today |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2146 |
daysUntil:(Date newDay:25 month:12 year:Date today year). |
699 | 2147 |
Transcript show:'still '; |
8201 | 2148 |
show:delta ; |
2149 |
showCR:' days till xmas' |
|
699 | 2150 |
" |
2151 |
! |
|
2152 |
||
2153 |
subtractDate:aDate |
|
2154 |
"return the number of days between the receiver and aDate" |
|
2155 |
||
2156 |
^ self asDays - aDate asDays |
|
2157 |
||
2158 |
" |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2159 |
(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
|
2160 |
(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
|
2161 |
(Date newDay:1 month:3 year:1994) subtractDate:(Date newDay:1 month:2 year:1994) |
699 | 2162 |
" |
2163 |
! |
|
2164 |
||
2165 |
subtractDays:days |
|
2166 |
"return a new date representing 'days' before the receiver. |
|
2167 |
The argument should be some kind of integer. |
|
2168 |
For ST-80 compatibility" |
|
2169 |
||
2170 |
^ self class fromDays:(self asDays - days) |
|
2171 |
||
2172 |
" |
|
2173 |
Date today subtractDays:7 |
|
92 | 2174 |
" |
1 | 2175 |
! ! |
2176 |
||
2177 |
!Date methodsFor:'comparing'! |
|
2178 |
||
29 | 2179 |
< aDate |
2180 |
"return true, if the date represented by the receiver |
|
2181 |
is before the argument, aDate" |
|
2182 |
||
54 | 2183 |
(aDate isMemberOf:Date) ifTrue:[ |
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2184 |
^ dateEncoding < aDate dateEncoding |
54 | 2185 |
]. |
29 | 2186 |
|
54 | 2187 |
"the argument must understand year, month and day to be |
2188 |
comparable, whatever it is" |
|
2189 |
||
2190 |
^ dateEncoding < (Date encodeYear:aDate year |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2191 |
month:aDate month |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2192 |
day:aDate day) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2193 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2194 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2195 |
Date today < (Date day:24 month:12 year:2000) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2196 |
Date today < (Date day:24 month:12 year:1900) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2197 |
Date today < Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2198 |
Date today-1 < Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2199 |
" |
29 | 2200 |
! |
1 | 2201 |
|
2202 |
= aDate |
|
2203 |
"return true, if the date represented by the receiver |
|
2204 |
is the same as the one represented by argument, aDate" |
|
2205 |
||
155 | 2206 |
(aDate isMemberOf:Date) ifFalse:[^ false]. |
2207 |
||
2208 |
^ dateEncoding = aDate dateEncoding |
|
54 | 2209 |
|
2210 |
"the argument must understand year, month and day to be |
|
2211 |
comparable, whatever it is" |
|
2212 |
||
155 | 2213 |
" |
54 | 2214 |
^ dateEncoding = (Date encodeYear:aDate year |
155 | 2215 |
month:aDate month |
2216 |
day:aDate day) |
|
2217 |
" |
|
68 | 2218 |
"Date today = ((Date today plusDays:7) minusDays:7)" |
92 | 2219 |
! |
2220 |
||
699 | 2221 |
> aDate |
2222 |
"return true, if the date represented by the receiver |
|
2223 |
is after the argument, aDate" |
|
2224 |
||
2225 |
(aDate isMemberOf:Date) ifTrue:[ |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2226 |
^ dateEncoding > aDate dateEncoding |
699 | 2227 |
]. |
2228 |
||
2229 |
"the argument must understand year, month and day to be |
|
2230 |
comparable, whatever it is" |
|
2231 |
||
2232 |
^ dateEncoding > (Date encodeYear:aDate year |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2233 |
month:aDate month |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2234 |
day:aDate day) |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2235 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2236 |
" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2237 |
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
|
2238 |
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
|
2239 |
Date today > Timestamp now |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2240 |
Date today+1 > Timestamp now |
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2241 |
" |
699 | 2242 |
! |
2243 |
||
92 | 2244 |
hash |
2245 |
"return an integer useful for hashing on dates" |
|
2246 |
||
2247 |
^ dateEncoding |
|
1 | 2248 |
! ! |
2249 |
||
1501 | 2250 |
!Date methodsFor:'converting'! |
2251 |
||
4408 | 2252 |
asDate |
2253 |
"return the receiver" |
|
2254 |
||
2255 |
^ self |
|
8247
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2256 |
! |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2257 |
|
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2258 |
asTimestamp |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2259 |
"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
|
2260 |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2261 |
^ Timestamp |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2262 |
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
|
2263 |
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
|
2264 |
|
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2265 |
" |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2266 |
Date today asTimestamp |
146e7e7dcf57
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8201
diff
changeset
|
2267 |
" |
5775
92b02a4a7e83
week in year - again (based upon thursday-rule)
Claus Gittinger <cg@exept.de>
parents:
5679
diff
changeset
|
2268 |
! ! |
1501 | 2269 |
|
8201 | 2270 |
!Date methodsFor:'obsolete'! |
2271 |
||
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2272 |
asAbsoluteTime |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2273 |
"deprecated, use #asTimestamp" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2274 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2275 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2276 |
^ self asTimestamp |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2277 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2278 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2279 |
dayCount |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2280 |
"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
|
2281 |
starting with 0 for this date. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2282 |
Date>>fromDays: is the reverse operation. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2283 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2284 |
please use asDays for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2285 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2286 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2287 |
^ self asDays. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2288 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2289 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2290 |
dayName |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2291 |
"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
|
2292 |
The returned string depends on the language setting. |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2293 |
Expect things like 'monday', 'tuesday' ... |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2294 |
Obsolete: |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2295 |
use #weekday for ST-80 compatibility" |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2296 |
<resource:#obsolete> |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2297 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2298 |
^ self weekday |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2299 |
! |
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2300 |
|
8201 | 2301 |
minusDays:days |
2302 |
"return a new date representing 'days' before the receiver. |
|
2303 |
The argument should be some kind of integer. |
|
2304 |
Obsolete: |
|
2305 |
Please dont use this method since it will vanish. |
|
2306 |
Use #subtractDays: instead for ST-80 compatibility." |
|
2307 |
||
2308 |
<resource: #obsolete> |
|
2309 |
||
2310 |
self obsoleteMethodWarning:'use #substractDays:'. |
|
2311 |
^ self subtractDays:days |
|
2312 |
! |
|
2313 |
||
2314 |
plusDays:days |
|
2315 |
"return a new date representing 'days' after the receiver. |
|
2316 |
The argument should be some kind of integer. |
|
2317 |
Obsolete: |
|
2318 |
Please dont use this method since it will vanish. |
|
2319 |
Use #addDays: instead for ST-80 compatibility." |
|
2320 |
||
2321 |
<resource: #obsolete> |
|
2322 |
||
2323 |
self obsoleteMethodWarning:'use #addDays:'. |
|
2324 |
^ self addDays:days |
|
2325 |
! ! |
|
2326 |
||
54 | 2327 |
!Date methodsFor:'printing & storing'! |
1 | 2328 |
|
5778 | 2329 |
addPrintBindingsTo:aDictionary |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2330 |
self addPrintBindingsTo:aDictionary language:nil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2331 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2332 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2333 |
addPrintBindingsTo:aDictionary language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2334 |
"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
|
2335 |
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
|
2336 |
valid format items are: |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2337 |
%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
|
2338 |
%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
|
2339 |
%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
|
2340 |
%y - year, full i.e. 1999, 2004 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2341 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2342 |
special: |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2343 |
%D - day - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2344 |
%M - month - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2345 |
%W - week in year - unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2346 |
%Y - year, last 2 digits only i.e. 99, 04 (danger: year 2k bug) |
5778 | 2347 |
|
2348 |
%weekDay - day in week (1->monday, 2->tuesday, ... ,7->sunday) |
|
2349 |
||
2350 |
%dayName - full day name |
|
2351 |
%DayName - full day name, first character uppercase |
|
2352 |
%DAYNAME - full day name, all uppercase |
|
2353 |
||
2354 |
%monthName - full month name |
|
2355 |
%MonthName - full month name, first character uppercase |
|
2356 |
%MONTHNAME - full month name, all uppercase |
|
2357 |
||
2358 |
%shortDayName - short (abbreviated) day name |
|
2359 |
%ShortDayName - short (abbreviated) day name, first character uppercase |
|
2360 |
%SHORTDAYNAME - short (abbreviated) day name, all uppercase |
|
2361 |
||
2362 |
%shortMonthName - short (abbreviated) month name |
|
2363 |
%ShortMonthName - short (abbreviated) month name, first character uppercase |
|
2364 |
%SHORTMONTHNAME - short (abbreviated) month name, all uppercase |
|
2365 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2366 |
%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
|
2367 |
%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
|
2368 |
%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
|
2369 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2370 |
|day ds dsPadded0 dsPaddedB month ms msPadded0 msPaddedB |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2371 |
year weekInYear monthName shortMonthName |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2372 |
dayInWeek dayOfWeek dayName shortDayName ws wsPadded0| |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2373 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2374 |
day := self day. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2375 |
ds := day printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2376 |
dsPaddedB := day printStringLeftPaddedTo:2. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2377 |
dsPadded0 := day printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2378 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2379 |
month := self month. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2380 |
ms := month printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2381 |
msPaddedB := month printStringLeftPaddedTo:2. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2382 |
msPadded0 := month printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2383 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2384 |
year := self year. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2385 |
weekInYear := self weekInYear. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2386 |
ws := weekInYear printString. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2387 |
wsPadded0 := weekInYear printStringLeftPaddedTo:2 with:$0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2388 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2389 |
dayInWeek := self dayInWeek. "/ 1 .. 7 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2390 |
dayOfWeek := self dayOfWeek. "/ 0 .. 6 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2391 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2392 |
monthName := self class nameOfMonth:(self month) language:languageOrNil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2393 |
dayName := self class nameOfDay:dayInWeek language:languageOrNil. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2394 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2395 |
aDictionary at:#day put:dsPadded0. "/ 0-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2396 |
aDictionary at:#daypadded put:dsPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2397 |
aDictionary at:#dayPadded put:dsPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2398 |
aDictionary at:#Day put:ds. "/ unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2399 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2400 |
aDictionary at:#month put:msPadded0. "/ 0-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2401 |
aDictionary at:#monthPadded put:msPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2402 |
aDictionary at:#monthpadded put:msPaddedB. "/ Blank-padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2403 |
aDictionary at:#Month put:ms. "/ unpadded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2404 |
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
|
2405 |
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
|
2406 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2407 |
aDictionary at:#year put:year. "/ padded |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2408 |
aDictionary at:#week put:wsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2409 |
aDictionary at:#Week put:ws. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2410 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2411 |
year ~~ Date today year ifTrue:[ |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2412 |
aDictionary at:#yearOrTime put:(' ' , year printString). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2413 |
]. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2414 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2415 |
aDictionary at:$d put:dsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2416 |
aDictionary at:$D put:ds. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2417 |
aDictionary at:$m put:msPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2418 |
aDictionary at:$M put:ms. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2419 |
aDictionary at:$y put:year. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2420 |
aDictionary at:$Y put:((year \\ 100)printStringLeftPaddedTo:2 with:$0). |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2421 |
aDictionary at:$w put:wsPadded0. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2422 |
aDictionary at:$W put:ws. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2423 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2424 |
aDictionary at:#monthName put:monthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2425 |
aDictionary at:#monthname put:monthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2426 |
aDictionary at:#MonthName put:monthName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2427 |
aDictionary at:#MONTHNAME put:monthName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2428 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2429 |
aDictionary at:#dayName put:dayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2430 |
aDictionary at:#dayname put:dayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2431 |
aDictionary at:#DayName put:dayName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2432 |
aDictionary at:#DAYNAME put:dayName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2433 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2434 |
aDictionary at:#weekDay put:dayInWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2435 |
aDictionary at:#weekday put:dayInWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2436 |
aDictionary at:#weekDayUS put:dayOfWeek. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2437 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2438 |
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
|
2439 |
aDictionary at:#shortdayname put:shortDayName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2440 |
aDictionary at:#ShortDayName put:shortDayName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2441 |
aDictionary at:#SHORTDAYNAME put:shortDayName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2442 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2443 |
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
|
2444 |
aDictionary at:#shortmonthname put:shortMonthName. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2445 |
aDictionary at:#ShortMonthName put:shortMonthName asUppercaseFirst. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2446 |
aDictionary at:#SHORTMONTHNAME put:shortMonthName asUppercase. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2447 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2448 |
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
|
2449 |
"/ 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
|
2450 |
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
|
2451 |
"/ 0 1 2 3 4 5 6 |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2452 |
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
|
2453 |
"/ 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
|
2454 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2455 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2456 |
printOn:aStream |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2457 |
"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
|
2458 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2459 |
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
|
2460 |
|
5778 | 2461 |
" |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2462 |
Date today printOn:Transcript. Transcript cr. |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2463 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2464 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2465 |
"Modified: 27.8.1995 / 01:01:49 / claus" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2466 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2467 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2468 |
printOn:aStream format:aFormatStringOrSqueakFormatArray |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2469 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2470 |
see #addPrintBindingsTo: for a list of valid format strings" |
5778 | 2471 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2472 |
self printOn:aStream format:aFormatStringOrSqueakFormatArray language:nil. |
5778 | 2473 |
|
2474 |
" |
|
2475 |
Date today printOn:Transcript format:'%y%m%d' (iso format) |
|
2476 |
Date today printOn:Transcript format:'%y-%m-%d' (iso format) |
|
2477 |
Date today printOn:Transcript format:'%y-W%w' (iso format - working week) |
|
2478 |
Date today printOn:Transcript format:'%d-%m-%y' (european trivia format) |
|
2479 |
Date today printOn:Transcript format:'%m/%d/%y' (us trivia format) |
|
2480 |
Date today printOn:Transcript format:'%D-%(monthName)-%y' (us trivia format) |
|
2481 |
Date today printOn:Transcript format:'%D-%(MonthName)-%y' (us trivia format) |
|
2482 |
Date today printOn:Transcript format:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
2483 |
Date today printOn:Transcript format:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
2484 |
Date today printOn:Transcript format:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
2485 |
Date today printOn:Transcript format:'%d%m%Y' (millenium bug format - danger) |
|
2486 |
Date today printOn:Transcript format:'Today is the %(weekDay) day of the week' |
|
2487 |
" |
|
7023 | 2488 |
" |
2489 |
String streamContents:[:s | |
|
2490 |
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
|
2491 |
] |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2492 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2493 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2494 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2495 |
printOn:aStream format:aFormatStringOrSqueakFormatArray language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2496 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2497 |
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
|
2498 |
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
|
2499 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2500 |
|dict| |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2501 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2502 |
aFormatStringOrSqueakFormatArray isArray ifTrue:[ |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2503 |
"backward compatibility: a squeak/st80 format array" |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2504 |
self printFormat:aFormatStringOrSqueakFormatArray on:aStream. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2505 |
^ self. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2506 |
]. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2507 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2508 |
dict := IdentityDictionary new. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2509 |
self addPrintBindingsTo:dict language:languageOrNil. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2510 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2511 |
aFormatStringOrSqueakFormatArray expandPlaceholdersWith:dict on:aStream |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2512 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2513 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2514 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2515 |
Date today |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2516 |
printOn:Transcript |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2517 |
format:'%y%m%d' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2518 |
language:#en |
7023 | 2519 |
" |
5778 | 2520 |
! |
2521 |
||
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2522 |
printOn:aStream language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2523 |
"append a printed representation of the receiver to aStream. |
8179 | 2524 |
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
|
2525 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2526 |
|format| |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2527 |
|
8118 | 2528 |
(DefaultFormats isNil or:[EnvironmentChange]) ifTrue:[ |
8145 | 2529 |
self class initNames |
8118 | 2530 |
]. |
8179 | 2531 |
format := DefaultFormats at:(languageOrNil ? Language) ifAbsent:[DefaultFormats at:#en]. |
2532 |
self printOn:aStream format:format language:languageOrNil. |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2533 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2534 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2535 |
Date today printOn:Transcript language:#en |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2536 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2537 |
|
8179 | 2538 |
"Modified: / 27-08-1995 / 01:01:49 / claus" |
2539 |
"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
|
2540 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2541 |
|
7023 | 2542 |
printStringFormat:aFormatStringOrArray |
5778 | 2543 |
"print using a format string; |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2544 |
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
|
2545 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2546 |
^ self printStringFormat:aFormatStringOrArray language:nil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2547 |
|
5778 | 2548 |
" |
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2549 |
Date today printStringFormat:'%y%m%d' (iso format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2550 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2551 |
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
|
2552 |
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
|
2553 |
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
|
2554 |
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
|
2555 |
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
|
2556 |
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
|
2557 |
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
|
2558 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2559 |
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
|
2560 |
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
|
2561 |
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
|
2562 |
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
|
2563 |
" |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2564 |
! |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2565 |
|
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2566 |
printStringFormat:aFormatStringOrArray language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2567 |
"print using a format string; |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7961
diff
changeset
|
2568 |
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
|
2569 |
see #addPrintBindingsTo: for a list of valid format strings" |
5778 | 2570 |
|
10908
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2571 |
|s| |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2572 |
|
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2573 |
s := WriteStream on:(String new:20). |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2574 |
self printOn:s format:aFormatStringOrArray language:languageOrNil. |
88b75a3ed4eb
Now printStringXXXX uses printOn:XXXX.
Stefan Vogel <sv@exept.de>
parents:
10879
diff
changeset
|
2575 |
^ s contents. |
5778 | 2576 |
|
2577 |
" |
|
2578 |
Date today printStringFormat:'%y%m%d' (iso format) |
|
2579 |
Date today printStringFormat:'%y-%m-%d' (iso format) |
|
2580 |
Date today printStringFormat:'%y-W%w' (iso format - working week) |
|
2581 |
Date today printStringFormat:'%d-%m-%y' (european trivia format) |
|
2582 |
Date today printStringFormat:'%m/%d/%y' (us trivia format) |
|
2583 |
Date today printStringFormat:'%D-%(monthName)-%y' (us trivia format) |
|
2584 |
Date today printStringFormat:'%D-%(MonthName)-%y' (us trivia format) |
|
2585 |
Date today printStringFormat:'%D-%(MONTHNAME)-%y' (us trivia format) |
|
2586 |
Date today printStringFormat:'%(DayName), %D%(nth) of %(MonthName), %y' |
|
2587 |
Date today printStringFormat:'%(ShortDayName), %D-%(ShortMonthName)-%y' |
|
2588 |
Date today printStringFormat:'%d%m%Y' (millenium bug format - danger) |
|
7327 | 2589 |
Date today printStringFormat:'Today is day %(weekDay) of the week' |
2590 |
Date today printStringFormat:'Today is the %(weekDay)%(weekDayNth) day of the week' |
|
2591 |
Date today printStringFormat:'Today is the %(Day)%(nth) day of the month' |
|
5778 | 2592 |
" |
2593 |
! |
|
2594 |
||
699 | 2595 |
storeOn:aStream |
2596 |
"append a representation to aStream, from which the receiver |
|
2597 |
can be reconstructed" |
|
2598 |
||
2599 |
aStream nextPutAll:'('; nextPutAll:'Date day:'. |
|
2600 |
self day printOn:aStream. |
|
2601 |
aStream nextPutAll:' month:'. |
|
2602 |
self month printOn:aStream. |
|
2603 |
aStream nextPutAll:' year:'. |
|
2604 |
self year printOn:aStream. |
|
2605 |
aStream nextPutAll:')' |
|
2606 |
||
2607 |
" |
|
2608 |
Date today storeOn:Transcript |
|
2609 |
Date today storeString |
|
2610 |
" |
|
1 | 2611 |
! ! |
699 | 2612 |
|
7258 | 2613 |
!Date methodsFor:'private-accessing'! |
699 | 2614 |
|
2615 |
dateEncoding |
|
2616 |
"the internal encoding is stricktly private, |
|
2617 |
and should not be used outside." |
|
2618 |
||
2619 |
^ dateEncoding |
|
2620 |
! |
|
2621 |
||
2622 |
dateEncoding:anInteger |
|
2623 |
"the internal encoding is stricktly private, |
|
2624 |
and should not be used outside." |
|
2625 |
||
2626 |
dateEncoding := anInteger |
|
2627 |
! |
|
2628 |
||
2629 |
fromOSTime:osTime |
|
2630 |
"set my dateEncoding from an OS time. |
|
2631 |
This somewhat clumsy implementation hides the OS's date representation |
|
2632 |
(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
|
2633 |
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
|
2634 |
|
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2635 |
|v| |
5858 | 2636 |
|
2637 |
v := OperatingSystem computeTimeAndDateFrom:osTime. |
|
11350
68606ef82813
Fix examples. Use common dateEncoding methods.
Stefan Vogel <sv@exept.de>
parents:
11349
diff
changeset
|
2638 |
dateEncoding := self class encodeYear:v year month:v month day:v day |
1501 | 2639 |
|
2640 |
"Modified: 1.7.1996 / 15:23:12 / cg" |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2641 |
! |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2642 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2643 |
getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2644 |
"compatibility with Timestamp for comparing" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2645 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2646 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2647 |
((Timestamp epoch addDays:365) asDate asDays - 365) -> 25202 |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2648 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2649 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2650 |
^ 1000 * 60*60*24 * (self asDays - 25202) |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2651 |
|
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2652 |
" |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2653 |
Date today asTimestamp getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2654 |
- |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2655 |
Date today getMilliseconds |
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2656 |
" |
699 | 2657 |
! ! |
2658 |
||
11176 | 2659 |
!Date methodsFor:'visiting'! |
2660 |
||
2661 |
acceptVisitor:aVisitor with:aParameter |
|
2662 |
||
2663 |
^ aVisitor visitDate:self with:aParameter |
|
2664 |
! ! |
|
2665 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
2666 |
!Date class methodsFor:'documentation'! |
699 | 2667 |
|
2668 |
version |
|
11593
4d5d359f2008
Allow for comparisons with TimeStamp
Stefan Vogel <sv@exept.de>
parents:
11553
diff
changeset
|
2669 |
^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.115 2009-02-26 21:00:23 stefan Exp $' |
699 | 2670 |
! ! |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6624
diff
changeset
|
2671 |
|
699 | 2672 |
Date initialize! |