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