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