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