author | Claus Gittinger <cg@exept.de> |
Tue, 23 Mar 2004 19:24:46 +0100 | |
changeset 8271 | c39b75be3c3f |
parent 8264 | b14c26a88e96 |
child 8286 | d4c7d4d34b8b |
permissions | -rw-r--r-- |
30 | 1 |
" |
2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 3 |
All Rights Reserved |
30 | 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 |
||
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
14 |
|
8246 | 15 |
AbstractTime subclass:#Timestamp |
795 | 16 |
instanceVariableNames:'osTime' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
8246 | 19 |
category:'Magnitude-Time' |
30 | 20 |
! |
21 |
||
8246 | 22 |
!Timestamp class methodsFor:'documentation'! |
30 | 23 |
|
82 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 27 |
All Rights Reserved |
82 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
30 | 38 |
documentation |
39 |
" |
|
8264
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
40 |
This class represents time values in milliSeconds starting some |
1501 | 41 |
time in the past. |
42 |
(typically, from 1st. Jan 1970, as used in the Unix operating system, |
|
43 |
but other systems may bias the time differently. |
|
44 |
Actually, the implementation does not depend or even know which time/date |
|
45 |
the OperatingSystem bases its time upon - it is simply keeping the value(s) |
|
7671 | 46 |
as returned from the OS. |
1501 | 47 |
For conversion, these values are given back to the OS, which will know |
7671 | 48 |
how to convert these times. This has the advantage, that timestamps on files |
49 |
(such as last-access-time or last-modification-time) can be handled transparently - |
|
50 |
especially when performing comparisons). |
|
241 | 51 |
|
1501 | 52 |
You should not interpret the osTime instance variable directly, instead |
7671 | 53 |
(if at all), ask the OS to convert. |
30 | 54 |
|
7671 | 55 |
The implementation of this class is not the same as in ST-80 |
56 |
(which represents the time as seconds from Jan 1., 1901). |
|
30 | 57 |
|
241 | 58 |
This class should not be confused with Time (which only represents the |
7671 | 59 |
time within one day). Time instances cannot be used to compare times across midnight; |
8246 | 60 |
instances of Timestamp can. |
241 | 61 |
|
8264
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
62 |
Notice: this class was once called AbsoluteTime. Einstein told us in 1905, that talking |
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
63 |
about a absolute time is not a good idea (at least in our universe). So the class |
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
64 |
has been renamed to Timestamp which makes us more compatible to other ST dialects (e.g. VW) |
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
65 |
AbsoluteTime is still kept as an alias for backward compatibility. |
3479 | 66 |
|
1306 | 67 |
[author:] |
7671 | 68 |
Claus Gittinger |
1306 | 69 |
|
1282 | 70 |
[See also:] |
7671 | 71 |
Time Date |
72 |
Delay ProcessorScheduler |
|
30 | 73 |
" |
74 |
! ! |
|
75 |
||
8246 | 76 |
!Timestamp class methodsFor:'initialization'! |
77 |
||
78 |
initialize |
|
79 |
||
80 |
AbsoluteTime := self. "backward compatibility" |
|
81 |
! ! |
|
82 |
||
83 |
!Timestamp class methodsFor:'instance creation'! |
|
30 | 84 |
|
4378 | 85 |
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
1501 | 86 |
"return an instance of the receiver, given individual components. |
8246 | 87 |
See also `Timestamp now' and other protocol inherited |
1501 | 88 |
from my superclass." |
89 |
||
423 | 90 |
^ self basicNew |
8246 | 91 |
fromOSTime:(OperatingSystem |
92 |
computeOSTimeFromUTCYear:y month:m day:d |
|
93 |
hour:h minute:min second:s |
|
94 |
millisecond:millis) |
|
30 | 95 |
|
241 | 96 |
" |
8246 | 97 |
Timestamp UTCYear:1970 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
98 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0 |
|
99 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
100 |
Timestamp UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
101 |
Timestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
241 | 102 |
" |
1228 | 103 |
|
4378 | 104 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
105 |
"Created: / 13.7.1999 / 12:34:37 / stefan" |
|
106 |
"Modified: / 13.7.1999 / 12:42:30 / stefan" |
|
107 |
! |
|
108 |
||
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
109 |
basicReadFrom:aStringOrStream |
8246 | 110 |
"return a new Timestamp, reading a printed representation from aStream. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
111 |
The string is interpreted as 24 hour format, as printed. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
112 |
Notice, that this is not the storeString format and |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
113 |
is different from the format expected by readFrom:. |
5677
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
114 |
KLUDGE: |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
115 |
us and non-us format have different ordering of day and month; |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
116 |
The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
117 |
or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
118 |
On error, raise an exception" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
119 |
|
5677
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
120 |
|str first second day month year hour min sec millis usFormat| |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
121 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
122 |
str := aStringOrStream readStream. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
123 |
|
5677
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
124 |
first := Integer readFrom:str. |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
125 |
|
7058 | 126 |
first > 31 ifTrue:[ |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
127 |
"/ assume iso8601 format; |
6955
adc3cc02fd7e
oops - skipped year in basicReadFrom if reading from a stream
Claus Gittinger <cg@exept.de>
parents:
6795
diff
changeset
|
128 |
^ self readIso8601FormatFrom:str yearAlreadyRead:first. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
129 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
130 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
131 |
"/ consider this a kludge |
5677
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
132 |
usFormat := (str peek == $/ ). |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
133 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
134 |
[str peek isDigit] whileFalse:[str next]. |
5677
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
135 |
second := Integer readFrom:str. |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
136 |
|
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
137 |
usFormat ifTrue:[ |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
138 |
month := first. |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
139 |
day := second. |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
140 |
] ifFalse:[ |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
141 |
month := second. |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
142 |
day := first. |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
143 |
]. |
52bd6bf1775f
us/non-us format reading ($/ as separator: us-format)
Claus Gittinger <cg@exept.de>
parents:
5656
diff
changeset
|
144 |
|
6686
ac70c231c14e
raise ConversionError (instead of generic error)
Claus Gittinger <cg@exept.de>
parents:
6684
diff
changeset
|
145 |
(day between:1 and:31) ifFalse:[ ConversionError raiseErrorString:'bad day' ]. |
ac70c231c14e
raise ConversionError (instead of generic error)
Claus Gittinger <cg@exept.de>
parents:
6684
diff
changeset
|
146 |
(month between:1 and:12) ifFalse:[ ConversionError raiseErrorString:'bad month' ]. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
147 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
148 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
149 |
year := Integer readFrom:str. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
150 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
151 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
152 |
hour := Integer readFrom:str. |
6686
ac70c231c14e
raise ConversionError (instead of generic error)
Claus Gittinger <cg@exept.de>
parents:
6684
diff
changeset
|
153 |
(hour between:0 and:24) ifFalse:[ ConversionError raiseErrorString:'bad hour' ]. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
154 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
155 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
156 |
min := Integer readFrom:str. |
6686
ac70c231c14e
raise ConversionError (instead of generic error)
Claus Gittinger <cg@exept.de>
parents:
6684
diff
changeset
|
157 |
(min between:0 and:59) ifFalse:[ ConversionError raiseErrorString:'bad minute' ]. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
158 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
159 |
str atEnd ifTrue:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
160 |
sec := millis := 0. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
161 |
] ifFalse:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
162 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
163 |
sec := Integer readFrom:str. |
6686
ac70c231c14e
raise ConversionError (instead of generic error)
Claus Gittinger <cg@exept.de>
parents:
6684
diff
changeset
|
164 |
(sec between:0 and:59) ifFalse:[ ConversionError raiseErrorString:'bad second' ]. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
165 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
166 |
str peek = $. ifTrue:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
167 |
str next. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
168 |
millis := Integer readFrom:str. |
6686
ac70c231c14e
raise ConversionError (instead of generic error)
Claus Gittinger <cg@exept.de>
parents:
6684
diff
changeset
|
169 |
millis >= 1000 ifTrue:[ ConversionError raiseErrorString:'bad millisecond' ]. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
170 |
] ifFalse:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
171 |
millis := 0. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
172 |
]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
173 |
]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
174 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
175 |
"special check - only 24:00:00 is allowed; |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
176 |
every time after that must wrap" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
177 |
hour == 24 ifTrue:[ |
6686
ac70c231c14e
raise ConversionError (instead of generic error)
Claus Gittinger <cg@exept.de>
parents:
6684
diff
changeset
|
178 |
(min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ ConversionError raiseErrorString:'bad hour' ]. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
179 |
]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
180 |
^ self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
181 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
182 |
" |
8246 | 183 |
Timestamp basicReadFrom:'20-2-1995 13:11:06' |
184 |
(Timestamp basicReadFrom:'10-9-1995 13:11:06') month |
|
185 |
(Timestamp basicReadFrom:'10/9/1995 13:11:06') month |
|
186 |
Timestamp basicReadFrom:'20-2-1995 13:11' |
|
187 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.100' |
|
188 |
Timestamp basicReadFrom:'32-2-1995 13:11:06.100' |
|
189 |
Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' |
|
190 |
Timestamp basicReadFrom:'20-13-1995 13:11:06.100' |
|
191 |
Timestamp basicReadFrom:'20-12-1995 25:11:06.100' |
|
192 |
Timestamp basicReadFrom:'20-12-1995 23:61:06.100' |
|
193 |
Timestamp basicReadFrom:'20-12-1995 23:10:66.100' |
|
194 |
Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' |
|
195 |
Timestamp basicReadFrom:'20-2-1995 24:01:00.100' |
|
196 |
Timestamp basicReadFrom:'20-2-1995 24:00:01.100' |
|
197 |
Timestamp basicReadFrom:'foo' |
|
198 |
Timestamp basicReadFrom:(Timestamp now printString) |
|
199 |
Timestamp basicReadFrom:'1995-10-20 24:00:00.000' |
|
200 |
Timestamp basicReadFrom:'1995-10-20 12:10:00.000' |
|
5719
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
201 |
" |
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
202 |
! |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
203 |
|
4378 | 204 |
day:d month:m year:y hour:h minutes:min seconds:s |
205 |
"This is obsolete. User #year:month:day:hour:minute:second:" |
|
206 |
||
207 |
^ self |
|
8246 | 208 |
year:y month:m day:d hour:h |
209 |
minute:min second:s millisecond:0 |
|
4378 | 210 |
|
211 |
" |
|
8246 | 212 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 |
213 |
Timestamp day:8 month:1 year:1995 hour:0 minute:43 second:48 |
|
4378 | 214 |
" |
215 |
||
216 |
"Modified: / 1.7.1996 / 15:22:26 / cg" |
|
217 |
"Modified: / 13.7.1999 / 12:29:56 / stefan" |
|
218 |
! |
|
219 |
||
220 |
day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis |
|
221 |
"This is obsolete. User #year:month:day:hour:minute:second:millisecond:" |
|
222 |
||
223 |
^ self year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
224 |
||
225 |
" |
|
8246 | 226 |
Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0 |
227 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 |
|
228 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 millisecond:100 |
|
4378 | 229 |
" |
230 |
||
231 |
"Created: / 1.7.1996 / 14:46:09 / cg" |
|
232 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
233 |
"Modified: / 13.7.1999 / 12:30:26 / stefan" |
|
275 | 234 |
! |
235 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
236 |
decodeFromLiteralArray:anArray |
8246 | 237 |
"decode an Timestamp literalArray. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
238 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
239 |
anArray may be: |
8246 | 240 |
#(Timestamp '200004182000.123') |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
241 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
242 |
or the deprecated old format, that is not portable between different architectures. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
243 |
We parse this for backward compatibility (will be eventually removed). |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
244 |
|
8246 | 245 |
#(Timestamp #osTime: 12345678) |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
246 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
247 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
248 |
(anArray at:2) == #osTime: ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
249 |
^ self new osTime:(anArray at:3). |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
250 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
251 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
252 |
^ self readGeneralizedFrom:(anArray at:2) onError:[self error:'literal array decoding'] |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
253 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
254 |
|
423 | 255 |
fromDate:aDate andTime:aTime |
256 |
"return an instance of the receiver, initialized from a time and a date |
|
1228 | 257 |
object. |
8246 | 258 |
See also `Timestamp now' and other protocol inherited |
1228 | 259 |
from my superclass." |
423 | 260 |
|
261 |
^ self |
|
8246 | 262 |
year:aDate year |
263 |
month:aDate month |
|
264 |
day:aDate day |
|
265 |
hour:aTime hours |
|
266 |
minute:aTime minutes |
|
267 |
second:aTime seconds |
|
423 | 268 |
|
269 |
" |
|
8246 | 270 |
Timestamp fromDate:(Date today) andTime:(Time now) |
271 |
Timestamp fromDate:(Date today plusDays:1) andTime:(Time now) |
|
272 |
Timestamp now |
|
423 | 273 |
" |
274 |
||
4378 | 275 |
"Modified: / 8.9.1995 / 15:07:30 / claus" |
276 |
"Modified: / 19.4.1996 / 15:25:46 / cg" |
|
277 |
"Modified: / 13.7.1999 / 12:30:47 / stefan" |
|
423 | 278 |
! |
279 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
280 |
newDay:dayInYear year:year |
8246 | 281 |
"return a new Timestamp, given the year and the day-in-year (starting at 1). |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
282 |
Date protocol compatibility" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
283 |
|
8246 | 284 |
^ (Date newDay:dayInYear year:year) asTimestamp |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
285 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
286 |
" |
8246 | 287 |
Timestamp newDay:183 year:1996 |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
288 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
289 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
290 |
"Modified: 2.7.1996 / 09:39:30 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
291 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
292 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
293 |
readFrom:aStringOrStream onError:exceptionBlock |
8246 | 294 |
"return a new Timestamp, reading a printed representation from aStream. |
275 | 295 |
The string is interpreted as 24 hour format, as printed. |
296 |
Notice, that this is not the storeString format and |
|
4898 | 297 |
is different from the format expected by readFrom:. |
298 |
The format read here is dd-mm-yyyy hh:mm:ss.iii" |
|
275 | 299 |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
300 |
|newTime| |
275 | 301 |
|
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7058
diff
changeset
|
302 |
Error handle:[:ex | |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
303 |
^ super readFrom:aStringOrStream onError:exceptionBlock |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
304 |
] do:[ |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
305 |
newTime := self basicReadFrom:aStringOrStream. |
275 | 306 |
]. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
307 |
^ newTime |
275 | 308 |
|
309 |
" |
|
8246 | 310 |
Timestamp readFrom:'20-2-1995 13:11:06' |
311 |
Timestamp readFrom:'20-2-1995 13:11' |
|
312 |
Timestamp readFrom:'20-2-2001 13:11' |
|
313 |
Timestamp readFrom:'20-2-1995 13:11:06.100' |
|
314 |
Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong' |
|
315 |
Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong' |
|
316 |
Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong' |
|
317 |
Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong' |
|
318 |
Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong' |
|
319 |
Timestamp readFrom:'foo' onError:'wrong' |
|
320 |
Timestamp readFrom:(Timestamp now storeString) onError:'wrong' |
|
275 | 321 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
322 |
|
4378 | 323 |
"Modified: / 8.10.1996 / 19:25:59 / cg" |
324 |
"Modified: / 13.7.1999 / 12:31:14 / stefan" |
|
2311 | 325 |
! |
326 |
||
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
327 |
readGeneralizedFrom:aStringOrStream onError:exceptionBlock |
8246 | 328 |
"return a new Timestamp, reading a printed representation from aStream. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
329 |
The string is interpreted as 24 hour format, as printed. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
330 |
|
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
331 |
Notice, that this is not the storeString format and |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
332 |
is different from the format expected by readFrom:. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
333 |
The format read here is yyyymmddHHMMSS.iii+uuuu, |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
334 |
which is the ASN1 GeneralizedTime format." |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
335 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
336 |
|newTime| |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
337 |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
338 |
^ [ |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
339 |
|str day month year hour min sec millis c| |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
340 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
341 |
sec := millis := 0. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
342 |
str := aStringOrStream readStream. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
343 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
344 |
year := Integer readFrom:(str next:4). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
345 |
month := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
346 |
(month between:1 and:12) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
347 |
day := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
348 |
(day between:1 and:31) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
349 |
hour:= Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
350 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
351 |
min:= Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
352 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
353 |
str atEnd ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
354 |
sec := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
355 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
356 |
str peek == $. ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
357 |
str next. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
358 |
millis := Integer readFrom:str. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
359 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
360 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
361 |
str atEnd ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
362 |
"/ this is local time |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
363 |
newTime := self year:year month:month day:day |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
364 |
hour:hour minute:min second:sec millisecond:millis. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
365 |
] ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
366 |
c := str next. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
367 |
c ~~ $Z ifTrue:[ |tzh tzmin| |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
368 |
tzh := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
369 |
tzmin := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
370 |
c == $+ ifTrue:[ |
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
371 |
"/ add hours and minutes |
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
372 |
hour := hour + tzh. |
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
373 |
min := min + tzmin. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
374 |
] ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
375 |
c ~~ $- ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
376 |
self error:'bad time offset'. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
377 |
]. |
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
378 |
"/ subtract hours and minutes |
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
379 |
hour := hour - tzh. |
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
380 |
min := min - tzmin. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
381 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
382 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
383 |
"/ this is UTC time |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
384 |
newTime := self UTCYear:year month:month day:day |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
385 |
hour:hour minute:min second:sec millisecond:millis. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
386 |
]. |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
387 |
newTime |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
388 |
] on:Error do:exceptionBlock. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
389 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
390 |
" |
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
391 |
|s| |
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
392 |
s := '' writeStream. |
8246 | 393 |
Timestamp now printGeneralizedOn:s. |
394 |
Timestamp readGeneralizedFrom:s contents onError:[] |
|
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
395 |
|
8246 | 396 |
Timestamp readGeneralizedFrom:'20001018000000+0200' onError:[] |
397 |
Timestamp readGeneralizedFrom:'20001018000000+0300' onError:[] |
|
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
398 |
|
8246 | 399 |
Timestamp readGeneralizedFrom:'20000202000000+0100' onError:[] |
400 |
Timestamp readGeneralizedFrom:'20000202000000+0200' onError:[] |
|
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
401 |
|
8246 | 402 |
Timestamp readGeneralizedFrom:'19950220131106' onError:[] |
403 |
Timestamp readGeneralizedFrom:'199502201311' onError:[] |
|
404 |
Timestamp readGeneralizedFrom:'19950220131106.100' onError:[] |
|
405 |
Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong' |
|
406 |
Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong' |
|
407 |
Timestamp readGeneralizedFrom:'foo' onError:'wrong' |
|
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
408 |
" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
409 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
410 |
"Modified: / 8.10.1996 / 19:25:59 / cg" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
411 |
"Modified: / 13.7.1999 / 12:31:14 / stefan" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
412 |
! |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
413 |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
414 |
readIso8601FormatFrom:aStringOrStream |
8246 | 415 |
"return a new Timestamp, reading an iso8601 UTC representation from aStream. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
416 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
417 |
is the same as 1999-01-01T24:00:00. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
418 |
Missing minute, second and ms values are replaced with 0; |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
419 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
420 |
Of course, a 24 hour clock is used. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
421 |
On error, raise an exception. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
422 |
Please use this format for all external representations - its the standard." |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
423 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
424 |
^ self |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
425 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
426 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
427 |
" |
8246 | 428 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06' |
429 |
Timestamp readIso8601FormatFrom:'1995-02T13:11:06' |
|
430 |
Timestamp readIso8601FormatFrom:'1995T13:11:06' |
|
431 |
Timestamp readIso8601FormatFrom:'1995T13:11' |
|
432 |
Timestamp readIso8601FormatFrom:'1995T13' |
|
433 |
Timestamp readIso8601FormatFrom:'1995' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
434 |
|
8246 | 435 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06' |
436 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11' |
|
437 |
Timestamp readIso8601FormatFrom:'1995-02-20 13' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
438 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
439 |
24 is allowed with ISO, and is 00:00 of the next day: |
8246 | 440 |
Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00' |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
441 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
442 |
" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
443 |
! |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
444 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
445 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
446 |
"common helper for read methods. |
8246 | 447 |
Return a new Timestamp, reading an iso8601 UTC representation from aStream. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
448 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
449 |
is the same as 1999-01-01T24:00:00. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
450 |
Missing minute, second and ms values are replaced with 0; |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
451 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
452 |
Of course, a 24 hour clock is used. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
453 |
On error, raise an exception. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
454 |
Please use this format for all external representations - its the standard." |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
455 |
|
7008 | 456 |
|str day month year hour min sec millis fraction| |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
457 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
458 |
str := aStringOrStream readStream. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
459 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
460 |
month := day := 1. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
461 |
hour := min := sec := millis := 0. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
462 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
463 |
yearOrNil notNil ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
464 |
year := yearOrNil |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
465 |
] ifFalse:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
466 |
year := Integer readFrom:str. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
467 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
468 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
469 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
470 |
str peek == $- ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
471 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
472 |
"/ month follows. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
473 |
month := Integer readFrom:str. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
474 |
(month between:1 and:12) ifFalse:[ ConversionError raiseErrorString:'bad month' ]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
475 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
476 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
477 |
str peek == $- ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
478 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
479 |
"/ day follows. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
480 |
day := Integer readFrom:str. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
481 |
(day between:1 and:31) ifFalse:[ ConversionError raiseErrorString:'bad day' ]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
482 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
483 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
484 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
485 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
486 |
str atEnd ifFalse:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
487 |
"time follows" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
488 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
489 |
str peek == $T ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
490 |
"we treat the T as optional here" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
491 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
492 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
493 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
494 |
hour := Integer readFrom:str. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
495 |
(hour between:0 and:24) ifFalse:[ ConversionError raiseErrorString:'bad hour' ]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
496 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
497 |
str peek == $: ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
498 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
499 |
"/ minutes follow. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
500 |
min := Integer readFrom:str. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
501 |
(min between:0 and:59) ifFalse:[ ConversionError raiseErrorString:'bad minute' ]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
502 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
503 |
str peek == $: ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
504 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
505 |
"/ seconds follow. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
506 |
sec := Integer readFrom:str. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
507 |
(sec between:0 and:59) ifFalse:[ ConversionError raiseErrorString:'bad seconds' ]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
508 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
509 |
str peek == $. ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
510 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
511 |
"/ millis follow. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
512 |
fraction := Number readMantissaFrom:str radix:10. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
513 |
millis := 1000 * fraction rounded. "/ mhmh - should it be truncated ? |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
514 |
] |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
515 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
516 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
517 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
518 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
519 |
"special check - only 24:00:00 is allowed; |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
520 |
every time after that must wrap" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
521 |
hour == 24 ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
522 |
(min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ Error raiseErrorString:'bad hour' ]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
523 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
524 |
^ self |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
525 |
year:year month:month day:day |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
526 |
hour:hour minute:min second:sec millisecond:millis. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
527 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
528 |
" |
8246 | 529 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06' |
530 |
Timestamp readIso8601FormatFrom:'1995-02T13:11:06' |
|
531 |
Timestamp readIso8601FormatFrom:'1995T13:11:06' |
|
532 |
Timestamp readIso8601FormatFrom:'1995T13:11' |
|
533 |
Timestamp readIso8601FormatFrom:'1995T13' |
|
534 |
Timestamp readIso8601FormatFrom:'1995' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
535 |
|
8246 | 536 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06' |
537 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11' |
|
538 |
Timestamp readIso8601FormatFrom:'1995-02-20 13' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
539 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
540 |
24 is allowed with ISO, and is 00:00 of the next day: |
8246 | 541 |
Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00' |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
542 |
" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
543 |
! |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
544 |
|
2311 | 545 |
secondsSince1970:sec |
546 |
"set time from elapsed seconds since 1-1-1970, 0:0:0. |
|
547 |
This is the format used in the UNIX world" |
|
548 |
||
7733 | 549 |
|divMod| |
550 |
||
551 |
divMod := sec divMod:3600. |
|
552 |
^ self year:1970 month:1 day:1 hour:(divMod at:1) minute:0 second:(divMod at:2). |
|
7111 | 553 |
|
554 |
"/ ^ self year:1970 month:1 day:1 hour:0 minute:0 second:sec. |
|
4378 | 555 |
|
556 |
" |
|
8246 | 557 |
Timestamp secondsSince1970:0 |
558 |
Timestamp secondsSince1970:3600 |
|
559 |
Timestamp secondsSince1970:3600*24 |
|
4378 | 560 |
" |
561 |
||
562 |
"Created: / 21.10.1996 / 17:48:30 / stefan" |
|
563 |
"Modified: / 13.7.1999 / 12:31:22 / stefan" |
|
564 |
! |
|
565 |
||
566 |
year:y month:m day:d hour:h minute:min second:s |
|
567 |
"return an instance of the receiver, given individual components. |
|
8246 | 568 |
See also `Timestamp now' and other protocol inherited |
4378 | 569 |
from my superclass." |
570 |
||
571 |
^ self year:y month:m day:d hour:h minute:min second:s millisecond:0 |
|
2311 | 572 |
|
573 |
" |
|
8246 | 574 |
Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0 |
575 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
576 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
577 |
Timestamp year:2000 month:1 day:1 hour:1 minutes:0 second:0 |
|
2311 | 578 |
" |
579 |
||
4378 | 580 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
581 |
"Created: / 13.7.1999 / 12:06:39 / stefan" |
|
582 |
"Modified: / 13.7.1999 / 12:27:47 / stefan" |
|
583 |
! |
|
584 |
||
585 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
586 |
"return an instance of the receiver, given individual components. |
|
8246 | 587 |
See also `Timestamp now' and other protocol inherited |
4378 | 588 |
from my superclass." |
589 |
||
590 |
^ self basicNew |
|
8246 | 591 |
fromOSTime:(OperatingSystem |
592 |
computeOSTimeFromYear:y month:m day:d |
|
593 |
hour:h minute:min seconds:s millis:millis) |
|
4378 | 594 |
|
595 |
" |
|
8246 | 596 |
Timestamp year:1970 month:1 day:1 hour:1 minute:0 seconds:0 |
597 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
598 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
599 |
Timestamp year:2000 month:1 day:1 hour:1 minute:0 second:0 |
|
4378 | 600 |
" |
601 |
||
602 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
603 |
"Created: / 13.7.1999 / 12:28:44 / stefan" |
|
604 |
"Modified: / 13.7.1999 / 12:37:57 / stefan" |
|
241 | 605 |
! ! |
30 | 606 |
|
8246 | 607 |
!Timestamp methodsFor:'accessing'! |
30 | 608 |
|
609 |
day |
|
92 | 610 |
"return the day-in-month of the receiver (1..31). |
275 | 611 |
For compatibility, use instances of Date for this." |
30 | 612 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
613 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) day. |
54 | 614 |
|
92 | 615 |
" |
8246 | 616 |
Timestamp now day |
92 | 617 |
" |
1501 | 618 |
|
619 |
"Modified: 1.7.1996 / 15:23:02 / cg" |
|
620 |
! |
|
621 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
622 |
dayInWeek |
7327 | 623 |
"return the week-day of the receiver - 1 for monday, 7 for sunday |
624 |
WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday). |
|
625 |
WARNING: does not care for pre-julian dates |
|
626 |
(i.e. do not use this for dates before 1752)" |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
627 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
628 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) dayInWeek |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
629 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
630 |
" |
8246 | 631 |
Timestamp now dayInWeek |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
632 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
633 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
634 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
635 |
"Created: 2.7.1996 / 09:35:48 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
636 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
637 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
638 |
dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
639 |
"return the year-day of the receiver - 1 for Jan, 1st." |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
640 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
641 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) dayInYear |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
642 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
643 |
" |
8246 | 644 |
Timestamp now dayInYear |
645 |
Timestamp newDay:184 year:1996 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
646 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
647 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
648 |
"Modified: 2.7.1996 / 10:21:02 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
649 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
650 |
|
1501 | 651 |
hour |
652 |
"return the hour (0..23). |
|
653 |
ST-80 Timestamp compatibility (I'd prefer the name #hours, for Time compatibility)." |
|
654 |
||
655 |
^ self hours |
|
656 |
||
657 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
658 |
"Modified: 1.7.1996 / 15:15:32 / cg" |
|
30 | 659 |
! |
660 |
||
241 | 661 |
hours |
662 |
"return the hours (0..23)" |
|
663 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
664 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) hours |
54 | 665 |
|
92 | 666 |
" |
8246 | 667 |
Timestamp now hours |
241 | 668 |
" |
669 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
670 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
1501 | 671 |
! |
672 |
||
673 |
millisecond |
|
674 |
"return the millisecond (0..999). |
|
675 |
ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)." |
|
676 |
||
677 |
^ self milliseconds |
|
678 |
||
679 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
680 |
"Modified: 1.7.1996 / 15:15:24 / cg" |
|
681 |
! |
|
682 |
||
683 |
milliseconds |
|
684 |
"return the milliseconds (0..999)" |
|
685 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
686 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) milliseconds |
1501 | 687 |
|
688 |
" |
|
8246 | 689 |
Timestamp now milliseconds |
1501 | 690 |
" |
691 |
||
692 |
"Created: 1.7.1996 / 15:15:02 / cg" |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
693 |
"Modified: 2.7.1996 / 09:21:41 / cg" |
1501 | 694 |
! |
695 |
||
696 |
minute |
|
697 |
"return the minute (0..59). |
|
698 |
ST-80 Timestamp compatibility (I'd prefer the name #minutes, for Time compatibility)." |
|
699 |
||
700 |
^ self minutes |
|
701 |
||
702 |
"Created: 1.7.1996 / 15:14:29 / cg" |
|
703 |
"Modified: 1.7.1996 / 15:15:37 / cg" |
|
241 | 704 |
! |
705 |
||
706 |
minutes |
|
707 |
"return the minutes (0..59)" |
|
708 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
709 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) minutes |
241 | 710 |
|
711 |
" |
|
8246 | 712 |
Timestamp now minutes |
92 | 713 |
" |
241 | 714 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
715 |
"Modified: 2.7.1996 / 09:20:49 / cg" |
241 | 716 |
! |
717 |
||
699 | 718 |
month |
719 |
"return the month of the receiver (1..12). |
|
720 |
For compatibility, use instances of Date for this." |
|
721 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
722 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) month |
699 | 723 |
|
724 |
" |
|
8246 | 725 |
Timestamp now month |
699 | 726 |
" |
1501 | 727 |
|
728 |
"Modified: 1.7.1996 / 15:23:05 / cg" |
|
729 |
! |
|
730 |
||
4807 | 731 |
osTime:aTime |
5726 | 732 |
"set the internal representation of the time" |
733 |
||
4807 | 734 |
osTime := aTime. |
735 |
! |
|
736 |
||
1501 | 737 |
second |
738 |
"return the second (0..59). |
|
739 |
ST-80 Timestamp compatibility (I'd prefer the name #seconds, for Time compatibility)." |
|
740 |
||
741 |
^ self seconds |
|
742 |
||
743 |
"Created: 1.7.1996 / 15:14:19 / cg" |
|
744 |
"Modified: 1.7.1996 / 15:15:49 / cg" |
|
699 | 745 |
! |
746 |
||
241 | 747 |
seconds |
748 |
"return the seconds (0..59)" |
|
749 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
750 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) seconds |
241 | 751 |
|
752 |
" |
|
8246 | 753 |
Timestamp now seconds |
241 | 754 |
" |
755 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
756 |
"Modified: 2.7.1996 / 09:20:54 / cg" |
92 | 757 |
! |
758 |
||
7734 | 759 |
timeInfo |
760 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) |
|
761 |
! |
|
762 |
||
799 | 763 |
utcOffset |
764 |
"return the difference between UTC (Greenwich Mean Time) and the local time |
|
765 |
if daylight saving time applies to ourself, take that into account. |
|
5853 | 766 |
Add utcOffset before converting to get UTC-Time resp. UTC-Date. |
799 | 767 |
" |
768 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
769 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) utcOffset |
799 | 770 |
|
771 |
" |
|
8246 | 772 |
Timestamp now utcOffset |
773 |
(Timestamp day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) utcOffset |
|
799 | 774 |
" |
775 |
||
776 |
"Modified: 20.12.1995 / 17:28:49 / stefan" |
|
1501 | 777 |
"Modified: 1.7.1996 / 15:21:29 / cg" |
799 | 778 |
! |
779 |
||
699 | 780 |
year |
781 |
"return the year of the receiver i.e. 1992. |
|
782 |
For compatibility, use instances of Date for this." |
|
241 | 783 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
784 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) year |
241 | 785 |
|
786 |
" |
|
8246 | 787 |
Timestamp now year |
241 | 788 |
" |
1501 | 789 |
|
790 |
"Modified: 1.7.1996 / 15:23:08 / cg" |
|
241 | 791 |
! ! |
792 |
||
8246 | 793 |
!Timestamp methodsFor:'arithmetic'! |
30 | 794 |
|
8246 | 795 |
millisecondDeltaFrom:aTimestamp |
3510 | 796 |
"return the delta in milliseconds between 2 absolute times. |
797 |
The argument is supposed to be AFTER the receiver" |
|
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
798 |
|
8246 | 799 |
^ self getMilliseconds - (aTimestamp getMilliseconds) |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
800 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
801 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
802 |
|t1 t2| |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
803 |
|
8246 | 804 |
t1 := Timestamp now. |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
805 |
Delay waitForSeconds:0.5. |
8246 | 806 |
t2 := Timestamp now. |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
807 |
t2 millisecondDeltaFrom:t1 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
808 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
809 |
|
3510 | 810 |
"Modified: / 5.6.1998 / 04:21:33 / cg" |
30 | 811 |
! ! |
812 |
||
8246 | 813 |
!Timestamp methodsFor:'comparing'! |
699 | 814 |
|
815 |
= aTime |
|
816 |
"return true if the argument, aTime represents the same time" |
|
817 |
||
818 |
(aTime species == self species) ifFalse:[^ false]. |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
819 |
^ (self getMilliseconds = aTime getMilliseconds) |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
820 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
821 |
"Modified: 3.7.1996 / 13:10:24 / cg" |
699 | 822 |
! |
823 |
||
824 |
hash |
|
825 |
"return an integer useful for hashing on times" |
|
826 |
||
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
827 |
^ osTime // 1000 |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
828 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
829 |
"Modified: 3.7.1996 / 13:10:52 / cg" |
699 | 830 |
! ! |
831 |
||
8246 | 832 |
!Timestamp methodsFor:'converting'! |
699 | 833 |
|
834 |
asAbsoluteTime |
|
8254
73b6109ab982
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8246
diff
changeset
|
835 |
"deprecated, use #asTimestamp" |
8246 | 836 |
|
837 |
<resource:#obsolete> |
|
699 | 838 |
|
839 |
^ self |
|
840 |
! |
|
841 |
||
842 |
asDate |
|
843 |
"return a Date object from the receiver. |
|
844 |
The returned date will only represent the day - not the timeOfDay." |
|
845 |
||
846 |
^ Date fromOSTime:osTime |
|
847 |
||
848 |
" |
|
8246 | 849 |
Timestamp now |
850 |
Timestamp now asDate |
|
851 |
(Timestamp now addTime:3600) asDate |
|
852 |
(Timestamp now addTime:3600) asTime |
|
853 |
Timestamp fromSeconds:(Timestamp now asSeconds + 3600) |
|
854 |
(Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate |
|
699 | 855 |
" |
856 |
! |
|
857 |
||
7466
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
858 |
asMilliseconds |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
859 |
"return the number of milliSeconds elapsed since whatever time the |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
860 |
OperatingSystem bases its time upon. Since this is totally |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
861 |
OS-dependent, do not interpret the value returned by this method. |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
862 |
You can use it to add/subtract milliSeconds or get time deltas, though." |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
863 |
|
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
864 |
^ self getMilliseconds |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
865 |
! |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
866 |
|
699 | 867 |
asSeconds |
868 |
"return the number of seconds elapsed since whatever time the |
|
869 |
OperatingSystem bases its time upon. Since this is totally |
|
870 |
OS-dependent, do not interpret the value returned by this method. |
|
871 |
You can use it to add/subtract seconds or get time deltas, though." |
|
872 |
||
873 |
^ self getSeconds |
|
874 |
||
7004 | 875 |
" |
8246 | 876 |
Timestamp now asSeconds |
877 |
Timestamp fromSeconds:(Timestamp now asSeconds + 3600) |
|
699 | 878 |
Time hour:23 minutes:33 seconds:0 |
879 |
Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) |
|
880 |
" |
|
881 |
! |
|
882 |
||
883 |
asTime |
|
884 |
"return a Time object from the receiver. |
|
885 |
The returned time will only represent the timeOfDay - not the day." |
|
886 |
||
887 |
^ Time fromOSTime:osTime |
|
888 |
||
889 |
" |
|
8246 | 890 |
Timestamp now |
891 |
Timestamp now asTime |
|
892 |
(Timestamp now addTime:3600) asTime |
|
699 | 893 |
" |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
894 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
895 |
|
8246 | 896 |
asTimestamp |
897 |
"return an Timestamp object from the receiver - thats the receiver." |
|
898 |
||
899 |
^ self |
|
900 |
! |
|
901 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
902 |
literalArrayEncoding |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
903 |
"encode myself as an array, from which a copy of the receiver |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
904 |
can be reconstructed with #decodeAsLiteralArray. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
905 |
The encoding is: |
8246 | 906 |
(#Timestamp YYYYMMDDhhmmss.iii) |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
907 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
908 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
909 |
|s| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
910 |
|
8223
56da5d8f8bc1
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8111
diff
changeset
|
911 |
s := WriteStream on:(String new:18). |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
912 |
self printGeneralizedOn:s isLocal:true. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
913 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
914 |
^ Array |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
915 |
with:self class name asSymbol |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
916 |
with:s contents |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
917 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
918 |
" |
8246 | 919 |
Timestamp now literalArrayEncoding |
920 |
Timestamp decodeFromLiteralArray:Timestamp now literalArrayEncoding |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
921 |
" |
7006 | 922 |
! |
923 |
||
924 |
utcSecondsSince1901 |
|
925 |
"return the number of seconds elapsed since Jan, 1st 1901" |
|
926 |
||
927 |
|daysBetween1901and1970 secondsPerDay| |
|
928 |
||
929 |
daysBetween1901and1970 := (Date day:1 month:1 year:1970) subtractDate:(Date day:1 month:1 year:1901). |
|
930 |
secondsPerDay := 24 * 60 * 60. |
|
931 |
^ self utcSecondsSince1970 " since 1.1.1970 " |
|
932 |
+ (daysBetween1901and1970 * secondsPerDay). |
|
933 |
||
934 |
" |
|
8246 | 935 |
Timestamp now utcSecondsSince1901 |
7006 | 936 |
" |
699 | 937 |
! ! |
938 |
||
8246 | 939 |
!Timestamp methodsFor:'encoding'! |
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5390
diff
changeset
|
940 |
|
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5390
diff
changeset
|
941 |
encodeOn:anEncoder with:aParameter |
5726 | 942 |
"encoder visitor support" |
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5390
diff
changeset
|
943 |
|
8246 | 944 |
anEncoder encodeTimestamp:self with:aParameter |
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5390
diff
changeset
|
945 |
! ! |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5390
diff
changeset
|
946 |
|
8246 | 947 |
!Timestamp methodsFor:'printing & storing'! |
30 | 948 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
949 |
addPrintBindingsTo:dict language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
950 |
"private print support: add bindings for printing to aDictionary |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
951 |
languageOrNil can only be #en or nil for the current language." |
5726 | 952 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
953 |
self asDate addPrintBindingsTo:dict language:languageOrNil. |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
954 |
|
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
955 |
self year == Date today year ifTrue:[ |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
956 |
dict at:#yearOrTime put:(self asTime printStringFormat:'%h:%m'). |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
957 |
]. |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
958 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
959 |
super addPrintBindingsTo:dict language:languageOrNil. |
4843 | 960 |
! |
961 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
962 |
printGeneralizedOn:aStream |
5290 | 963 |
"append a representation of the receiver to aStream in a general format, |
964 |
top-down, without separtors: 'yyyymmddHHMMSS.mmm+0100' |
|
965 |
This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
|
966 |
so read this before changing the output format." |
|
967 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
968 |
^ self printGeneralizedOn:aStream isLocal:false. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
969 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
970 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
971 |
printGeneralizedOn:aStream isLocal:isLocal |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
972 |
"append a representation of the receiver to aStream in a general format, |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
973 |
top-down, without separtors: 'yyyymmddHHMMSS.mmm+0100' |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
974 |
This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
975 |
so read this before changing the output format. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
976 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
977 |
If isLocal is true, represent as local time, otherwise add UTC time offset." |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
978 |
|
5290 | 979 |
|t off| |
980 |
||
981 |
t := OperatingSystem computeTimeAndDateFrom:osTime. |
|
982 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
983 |
t year printOn:aStream leftPaddedTo:4 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
984 |
t month printOn:aStream leftPaddedTo:2 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
985 |
t day printOn:aStream leftPaddedTo:2 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
986 |
t hours printOn:aStream leftPaddedTo:2 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
987 |
t minutes printOn:aStream leftPaddedTo:2 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
988 |
t seconds printOn:aStream leftPaddedTo:2 with:$0. |
5290 | 989 |
aStream nextPut:$.. |
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
990 |
t milliseconds printOn:aStream leftPaddedTo:3 with:$0. |
5290 | 991 |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
992 |
isLocal ifFalse:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
993 |
"/ this should be printed as non-local-time |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
994 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
995 |
off := t utcOffset. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
996 |
off == 0 ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
997 |
aStream nextPut:$Z. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
998 |
] ifFalse:[ |min| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
999 |
off < 0 ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1000 |
aStream nextPut:$+. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1001 |
off := off negated. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1002 |
] ifFalse:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1003 |
aStream nextPut:$-. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1004 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1005 |
min := off // 60. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1006 |
min // 60 printOn:aStream leftPaddedTo:2 with:$0. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1007 |
min \\ 60 printOn:aStream leftPaddedTo:2 with:$0. |
5290 | 1008 |
]. |
1009 |
]. |
|
1010 |
||
1011 |
" |
|
8246 | 1012 |
Timestamp now printGeneralizedOn:Transcript. Transcript cr. |
1013 |
(Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr. |
|
5290 | 1014 |
Time now printOn:Transcript. Transcript cr. |
1015 |
Date today printOn:Transcript. Transcript cr. |
|
1016 |
||
8246 | 1017 |
Time now asTimestamp printGeneralizedOn:Transcript. Transcript cr. |
1018 |
Timestamp now printGeneralizedOn:Transcript. Transcript cr. |
|
5290 | 1019 |
|
8246 | 1020 |
Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr. |
5290 | 1021 |
Date today printOn:Transcript. Transcript cr. |
1022 |
" |
|
1023 |
||
1024 |
"Modified: / 1.7.1996 / 15:20:59 / cg" |
|
1025 |
"Modified: / 17.1.2000 / 15:53:02 / stefan" |
|
1026 |
! |
|
1027 |
||
241 | 1028 |
printOn:aStream |
275 | 1029 |
"append a user readable representation of the receiver to aStream. |
1030 |
The format is compatible with readFromString:, but not with readFrom:." |
|
1031 |
||
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1032 |
"/ now, use ISO format... |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1033 |
self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i' |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1034 |
"/ self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i' |
5678 | 1035 |
"/ self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i' |
92 | 1036 |
|
1037 |
" |
|
8246 | 1038 |
Timestamp now printOn:Transcript. Transcript cr. |
1039 |
(Timestamp fromSeconds:0) printOn:Transcript. Transcript cr. |
|
275 | 1040 |
Time now printOn:Transcript. Transcript cr. |
1041 |
Date today printOn:Transcript. Transcript cr. |
|
1501 | 1042 |
|
8246 | 1043 |
Time now asTimestamp printOn:Transcript. Transcript cr. |
1044 |
Timestamp now printOn:Transcript. Transcript cr. |
|
1501 | 1045 |
|
8246 | 1046 |
Date today asTimestamp printOn:Transcript. Transcript cr. |
1501 | 1047 |
Date today printOn:Transcript. Transcript cr. |
92 | 1048 |
" |
1501 | 1049 |
|
5719
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
1050 |
"Modified: 1.7.1996 / 15:20:59 / cg" |
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
1051 |
! |
30 | 1052 |
|
7474 | 1053 |
printRFC1123FormatOn:aStream |
1054 |
"append the RFC1123 representation of the receiver to aStream. |
|
1055 |
This format is used in HTTP requests and looks like: |
|
7671 | 1056 |
'Fri, 04 Jul 2003 15:56:11 GMT' |
1057 |
(always GMT and all names in english)" |
|
1058 |
||
1059 |
"/ HTTP-date = rfc1123-date | rfc850-date | asctime-date |
|
1060 |
"/ |
|
1061 |
"/ rfc1123-date = wkday "," SP date1 SP time SP "GMT" |
|
1062 |
"/ rfc850-date = weekday "," SP date2 SP time SP "GMT" |
|
1063 |
"/ asctime-date = wkday SP date3 SP time SP 4DIGIT |
|
1064 |
"/ |
|
1065 |
"/ date1 = 2DIGIT SP month SP 4DIGIT |
|
1066 |
"/ ; day month year (e.g., 02 Jun 1982) |
|
1067 |
"/ date2 = 2DIGIT "-" month "-" 2DIGIT |
|
1068 |
"/ ; day-month-year (e.g., 02-Jun-82) |
|
1069 |
"/ date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
|
1070 |
"/ ; month day (e.g., Jun 2) |
|
1071 |
"/ |
|
1072 |
"/ time = 2DIGIT ":" 2DIGIT ":" 2DIGIT |
|
1073 |
"/ ; 00:00:00 - 23:59:59 |
|
1074 |
"/ |
|
1075 |
"/ wkday = "Mon" | "Tue" | "Wed" |
|
1076 |
"/ | "Thu" | "Fri" | "Sat" | "Sun" |
|
1077 |
"/ |
|
1078 |
"/ weekday = "Monday" | "Tuesday" | "Wednesday" |
|
1079 |
"/ | "Thursday" | "Friday" | "Saturday" | "Sunday" |
|
1080 |
"/ |
|
1081 |
"/ month = "Jan" | "Feb" | "Mar" | "Apr" |
|
1082 |
"/ | "May" | "Jun" | "Jul" | "Aug" |
|
1083 |
"/ | "Sep" | "Oct" | "Nov" | "Dec" |
|
7474 | 1084 |
|
7734 | 1085 |
|meUTC timeInfo| |
7474 | 1086 |
|
8246 | 1087 |
meUTC := self class fromSeconds:((self asSeconds) + (self utcOffset)). |
7734 | 1088 |
timeInfo := meUTC timeInfo. |
7474 | 1089 |
|
7734 | 1090 |
aStream nextPutAll:(#('Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun') at:timeInfo dayInWeek); |
7671 | 1091 |
nextPutAll:', '. |
7734 | 1092 |
timeInfo day printOn:aStream leftPaddedTo:2 with:$0. |
7671 | 1093 |
aStream space. |
7734 | 1094 |
aStream nextPutAll:(#('Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec') at:timeInfo month). |
7671 | 1095 |
|
1096 |
"/ The following line is wrong, because the names are printed in the current locale!! |
|
7734 | 1097 |
"/ timeInfo printOn:aStream format:'%(ShortDayName), %(day) %(ShortMonthName) %y %h:%m:%s GMT'. |
7474 | 1098 |
|
7677 | 1099 |
"/ the following is too slow for heavy use |
7734 | 1100 |
"/ timeInfo printOn:aStream format:' %y %h:%m:%s GMT'. |
7677 | 1101 |
|
1102 |
aStream nextPut:Character space. |
|
7734 | 1103 |
timeInfo year printOn:aStream. |
7677 | 1104 |
aStream nextPut:Character space. |
7734 | 1105 |
timeInfo hours printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1106 |
aStream nextPut:$:. |
7734 | 1107 |
timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1108 |
aStream nextPut:$:. |
7734 | 1109 |
timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1110 |
aStream nextPutAll:' GMT'. |
1111 |
||
7474 | 1112 |
" |
8246 | 1113 |
TimeStamp now printRFC1123FormatOn:Transcript |
7474 | 1114 |
" |
1115 |
! |
|
1116 |
||
1117 |
printStringRFC1123Format |
|
1118 |
"return the RFC1123 representation of the receiver. |
|
1119 |
This format is used in HTTP requests and looks like: |
|
7671 | 1120 |
'Fri, 04 Jul 2003 15:56:11 GMT' |
7474 | 1121 |
(always GMT)" |
1122 |
||
1123 |
^ String streamContents:[:s | self printRFC1123FormatOn:s] |
|
1124 |
||
1125 |
" |
|
8246 | 1126 |
Timestamp now printStringRFC1123Format |
7474 | 1127 |
" |
1128 |
! |
|
1129 |
||
241 | 1130 |
storeOn:aStream |
275 | 1131 |
"store the receiver in a format suitable for reconstruction of the |
1132 |
receiver via readFrom:" |
|
1133 |
||
241 | 1134 |
aStream nextPut:$(; |
8246 | 1135 |
nextPutAll:self class name; |
1136 |
nextPutAll:' new setSeconds:'. |
|
275 | 1137 |
self getSeconds storeOn:aStream. |
241 | 1138 |
aStream nextPut:$). |
54 | 1139 |
|
241 | 1140 |
" |
8246 | 1141 |
Timestamp now storeString |
30 | 1142 |
|
8246 | 1143 |
Timestamp readFrom:(Timestamp now storeString) readStream |
241 | 1144 |
" |
30 | 1145 |
! ! |
699 | 1146 |
|
8246 | 1147 |
!Timestamp methodsFor:'private'! |
699 | 1148 |
|
1501 | 1149 |
fromOSTime:anUninterpretedOSTime |
699 | 1150 |
"strictly private: set the seconds from an OS time (since whatever)" |
1151 |
||
1501 | 1152 |
osTime := anUninterpretedOSTime |
1153 |
||
1154 |
"Created: 1.7.1996 / 14:33:21 / cg" |
|
1155 |
! |
|
1156 |
||
1157 |
getMilliseconds |
|
1158 |
"strictly private: return the milliseconds (since whatever)" |
|
1159 |
||
1160 |
^ osTime |
|
1161 |
||
1162 |
"Created: 1.7.1996 / 14:33:56 / cg" |
|
699 | 1163 |
! |
1164 |
||
1165 |
getSeconds |
|
1166 |
"strictly private: return the seconds (since whatever)" |
|
1167 |
||
1501 | 1168 |
^ osTime // 1000 |
699 | 1169 |
! |
1170 |
||
1501 | 1171 |
setMilliseconds:millis |
1172 |
"strictly private: set the milliseconds (since whatever)" |
|
1173 |
||
1174 |
osTime := millis. |
|
1175 |
||
1176 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1177 |
"Created: 1.7.1996 / 14:34:24 / cg" |
|
1178 |
! |
|
1179 |
||
699 | 1180 |
setSeconds:secs |
1181 |
"strictly private: set the seconds (since whatever)" |
|
1182 |
||
1501 | 1183 |
osTime := secs * 1000. |
795 | 1184 |
|
1185 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1501 | 1186 |
"Modified: 1.7.1996 / 14:34:10 / cg" |
5853 | 1187 |
! |
1188 |
||
1189 |
utcSecondsSince1970 |
|
1190 |
"return the UTC seconds since 1970" |
|
1191 |
||
1192 |
|localTimeSeconds| |
|
1193 |
||
1194 |
localTimeSeconds := self getSeconds. |
|
1195 |
^ localTimeSeconds - self utcOffset |
|
1196 |
||
1197 |
" |
|
8246 | 1198 |
Timestamp now utcSecondsSince1970 |
5853 | 1199 |
" |
699 | 1200 |
! ! |
1201 |
||
8246 | 1202 |
!Timestamp class methodsFor:'documentation'! |
699 | 1203 |
|
1204 |
version |
|
8271 | 1205 |
^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.92 2004-03-23 18:24:46 cg Exp $' |
699 | 1206 |
! ! |
8246 | 1207 |
|
1208 |
Timestamp initialize! |