author | Stefan Vogel <sv@exept.de> |
Tue, 11 Nov 2014 13:14:23 +0100 | |
changeset 17028 | 7f4490e83429 |
parent 16997 | f0867a7f248b |
child 17032 | e2c097d59814 |
permissions | -rw-r--r-- |
13227 | 1 |
" |
2 |
COPYRIGHT (c) 2011 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
"{ Package: 'stx:libbasic' }" |
|
13 |
||
14 |
Timestamp subclass:#UtcTimestamp |
|
15 |
instanceVariableNames:'' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Magnitude-Time' |
|
19 |
! |
|
20 |
||
21 |
!UtcTimestamp class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2011 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
||
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
This is a Timestamp, that represents itself as UTC. |
|
13231 | 41 |
Internally it stores exactly the same value as Timestamp, |
15828 | 42 |
so the following expression is always true: |
13231 | 43 |
|
44 |
someTimestamp asUtcTimestamp = someTimestamp asLocalTimestamp |
|
45 |
||
46 |
But when printing, accessing hour, minute, ... and converting to Date and Time, |
|
47 |
it returns the values represented in the UTC zone instead of the local timezone. |
|
13227 | 48 |
|
49 |
[author:] |
|
50 |
Stefan Vogel (stefan@zwerg.nil.exept.de) |
|
51 |
||
52 |
[instance variables:] |
|
53 |
||
54 |
[class variables:] |
|
55 |
||
56 |
[see also:] |
|
13231 | 57 |
Time Date |
13227 | 58 |
|
59 |
" |
|
60 |
! ! |
|
61 |
||
62 |
!UtcTimestamp methodsFor:'accessing'! |
|
63 |
||
64 |
timeInfo |
|
16979 | 65 |
^ self utcTimeInfo |
13227 | 66 |
! |
67 |
||
68 |
timeZoneName |
|
16987 | 69 |
^ 'UTC' |
16969 | 70 |
! |
71 |
||
72 |
utcOffset |
|
73 |
^ 0 |
|
13227 | 74 |
! ! |
75 |
||
76 |
!UtcTimestamp methodsFor:'converting'! |
|
77 |
||
17028 | 78 |
asDate |
79 |
"return a Date object from the receiver. |
|
80 |
The returned date will only represent the day - not the timeOfDay. |
|
81 |
Notice: if you convert a local timestamp, you will get the local date; |
|
82 |
otherwise if you convert an utcTimestamp, you'll get the utc date." |
|
83 |
||
84 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
|
85 |
|dayDelta day0| |
|
86 |
||
87 |
dayDelta := osTime // (24 * 3600 * 1000). |
|
88 |
day0 := Epoch asDate. |
|
89 |
^ day0 addDays:dayDelta. |
|
90 |
]. |
|
91 |
^ self timeInfo asDate |
|
92 |
||
93 |
" |
|
94 |
Timestamp now |
|
95 |
Timestamp now asDate |
|
96 |
(Timestamp now addTime:3600) asDate |
|
97 |
(Timestamp now addTime:3600) asTime |
|
98 |
Timestamp fromSeconds:(Timestamp now asSeconds + 3600) |
|
99 |
(Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate |
|
100 |
" |
|
101 |
! |
|
102 |
||
13227 | 103 |
asLocalTimestamp |
13232
23a5fb2c645f
comment/format in: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents:
13231
diff
changeset
|
104 |
"represent myself as a timestamp in the local timezone" |
13227 | 105 |
|
106 |
^ Timestamp fromOSTime:osTime |
|
107 |
! |
|
108 |
||
17028 | 109 |
asTime |
110 |
"return a Time object from the receiver. |
|
111 |
The returned time will only represent the timeOfDay - not the day, |
|
112 |
and does not include the milliseconds." |
|
113 |
||
114 |
|secondDelta| |
|
115 |
||
116 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
|
117 |
secondDelta := osTime // 1000. |
|
118 |
"/ we do not know about DST in the far future and in the long gone past. |
|
119 |
secondDelta := secondDelta rem:(24*3600) . |
|
120 |
^ Epoch asTime addSeconds:secondDelta. |
|
121 |
]. |
|
122 |
^ self timeInfo asTime |
|
123 |
! |
|
124 |
||
13227 | 125 |
asUtcTimestamp |
13232
23a5fb2c645f
comment/format in: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents:
13231
diff
changeset
|
126 |
"I am an UtcTimestamp" |
23a5fb2c645f
comment/format in: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents:
13231
diff
changeset
|
127 |
|
13227 | 128 |
^ self |
129 |
! ! |
|
130 |
||
131 |
!UtcTimestamp methodsFor:'initialization'! |
|
132 |
||
16931 | 133 |
setOSTimeFromYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
16987 | 134 |
"private: ask the operating system to compute the internal osTime (based on the epoch), |
135 |
given y,m,d and h,m,s in utc time" |
|
136 |
||
16997 | 137 |
self setOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
13794
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
138 |
|
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
139 |
" |
16997 | 140 |
UtcTimestamp now |
141 |
Timestamp now |
|
142 |
Timestamp now asTZTimestamp |
|
143 |
Timestamp now asUtcTimestamp |
|
13794
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
144 |
" |
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
145 |
|
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
146 |
"Modified (comment): / 13-10-2011 / 22:05:41 / cg" |
13227 | 147 |
! ! |
148 |
||
149 |
!UtcTimestamp methodsFor:'testing'! |
|
150 |
||
16969 | 151 |
isLocalTimestamp |
16987 | 152 |
"return true, if I am a local timestamp" |
153 |
||
16969 | 154 |
^ false |
155 |
! |
|
156 |
||
13227 | 157 |
isUtcTimestamp |
16987 | 158 |
"return true, if I am a utc timestamp" |
159 |
||
13227 | 160 |
^ true |
161 |
! ! |
|
162 |
||
163 |
!UtcTimestamp methodsFor:'visiting'! |
|
164 |
||
165 |
acceptVisitor:aVisitor with:aParameter |
|
16715 | 166 |
"dispatch for visitor pattern; send #visitUtcTimestamp:with: to aVisitor." |
167 |
||
13227 | 168 |
^ aVisitor visitUtcTimestamp:self with:aParameter |
169 |
! ! |
|
170 |
||
171 |
!UtcTimestamp class methodsFor:'documentation'! |
|
172 |
||
16987 | 173 |
version |
17028 | 174 |
^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.12 2014-11-11 12:14:23 stefan Exp $' |
16987 | 175 |
! |
176 |
||
13227 | 177 |
version_CVS |
17028 | 178 |
^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.12 2014-11-11 12:14:23 stefan Exp $' |
13227 | 179 |
! ! |
15828 | 180 |