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