author | Jan Vrany <jan.vrany@labware.com> |
Wed, 22 Mar 2023 13:57:18 +0000 | |
branch | jv |
changeset 25445 | 1623217d2268 |
parent 25423 | bcfde4da086a |
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 |
||
18452 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
13227 | 16 |
Timestamp subclass:#UtcTimestamp |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Magnitude-Time' |
|
21 |
! |
|
22 |
||
23 |
!UtcTimestamp class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2011 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
||
37 |
" |
|
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
This is a Timestamp, that represents itself as UTC. |
|
13231 | 43 |
Internally it stores exactly the same value as Timestamp, |
15828 | 44 |
so the following expression is always true: |
13231 | 45 |
|
46 |
someTimestamp asUtcTimestamp = someTimestamp asLocalTimestamp |
|
47 |
||
48 |
But when printing, accessing hour, minute, ... and converting to Date and Time, |
|
49 |
it returns the values represented in the UTC zone instead of the local timezone. |
|
17130 | 50 |
Be aware that this may lead to interesting results; for example when converting a timestamp |
51 |
to a date, you may get a different date from an UTCTimestamp and a local timestamp. |
|
13227 | 52 |
|
53 |
[author:] |
|
54 |
Stefan Vogel (stefan@zwerg.nil.exept.de) |
|
55 |
||
56 |
[instance variables:] |
|
57 |
||
58 |
[class variables:] |
|
59 |
||
60 |
[see also:] |
|
13231 | 61 |
Time Date |
13227 | 62 |
|
63 |
" |
|
64 |
! ! |
|
65 |
||
66 |
!UtcTimestamp methodsFor:'accessing'! |
|
67 |
||
68 |
timeInfo |
|
16979 | 69 |
^ self utcTimeInfo |
13227 | 70 |
! |
71 |
||
72 |
timeZoneName |
|
16987 | 73 |
^ 'UTC' |
16969 | 74 |
! |
75 |
||
76 |
utcOffset |
|
18452 | 77 |
"I am an UTC timestamp, so there is no offset" |
78 |
||
16969 | 79 |
^ 0 |
17032 | 80 |
! |
81 |
||
82 |
utcOffsetWithoutDst |
|
83 |
^ 0 |
|
13227 | 84 |
! ! |
85 |
||
86 |
!UtcTimestamp methodsFor:'converting'! |
|
87 |
||
88 |
asLocalTimestamp |
|
13232
23a5fb2c645f
comment/format in: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents:
13231
diff
changeset
|
89 |
"represent myself as a timestamp in the local timezone" |
13227 | 90 |
|
91 |
^ Timestamp fromOSTime:osTime |
|
92 |
! |
|
93 |
||
94 |
asUtcTimestamp |
|
13232
23a5fb2c645f
comment/format in: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents:
13231
diff
changeset
|
95 |
"I am an UtcTimestamp" |
23a5fb2c645f
comment/format in: #asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents:
13231
diff
changeset
|
96 |
|
13227 | 97 |
^ self |
98 |
! ! |
|
99 |
||
100 |
!UtcTimestamp methodsFor:'initialization'! |
|
101 |
||
16931 | 102 |
setOSTimeFromYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
16987 | 103 |
"private: ask the operating system to compute the internal osTime (based on the epoch), |
104 |
given y,m,d and h,m,s in utc time" |
|
105 |
||
16997 | 106 |
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
|
107 |
|
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
108 |
" |
16997 | 109 |
UtcTimestamp now |
110 |
Timestamp now |
|
111 |
Timestamp now asTZTimestamp |
|
112 |
Timestamp now asUtcTimestamp |
|
13794
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
113 |
" |
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
114 |
|
600bc500741b
changed: #year:month:day:hour:minute:second:millisecond:
Claus Gittinger <cg@exept.de>
parents:
13232
diff
changeset
|
115 |
"Modified (comment): / 13-10-2011 / 22:05:41 / cg" |
13227 | 116 |
! ! |
117 |
||
17051 | 118 |
!UtcTimestamp methodsFor:'private'! |
119 |
||
120 |
storeStringClass |
|
25423
bcfde4da086a
Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
121 |
"my storeString will ask Timestamp to read the instance" |
bcfde4da086a
Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
122 |
|
17051 | 123 |
^ Timestamp |
124 |
! ! |
|
125 |
||
13227 | 126 |
!UtcTimestamp methodsFor:'testing'! |
127 |
||
16969 | 128 |
isLocalTimestamp |
25423
bcfde4da086a
Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
129 |
"return true, if I am a local timestamp (i.e. with no TZ info)" |
16987 | 130 |
|
16969 | 131 |
^ false |
25423
bcfde4da086a
Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
132 |
|
bcfde4da086a
Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
133 |
"Modified (comment): / 24-05-2018 / 17:29:35 / Claus Gittinger" |
16969 | 134 |
! |
135 |
||
13227 | 136 |
isUtcTimestamp |
16987 | 137 |
"return true, if I am a utc timestamp" |
138 |
||
13227 | 139 |
^ true |
140 |
! ! |
|
141 |
||
142 |
!UtcTimestamp methodsFor:'visiting'! |
|
143 |
||
144 |
acceptVisitor:aVisitor with:aParameter |
|
16715 | 145 |
"dispatch for visitor pattern; send #visitUtcTimestamp:with: to aVisitor." |
146 |
||
13227 | 147 |
^ aVisitor visitUtcTimestamp:self with:aParameter |
148 |
! ! |
|
149 |
||
150 |
!UtcTimestamp class methodsFor:'documentation'! |
|
151 |
||
16987 | 152 |
version |
25423
bcfde4da086a
Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
153 |
^ '$Header$' |
16987 | 154 |
! |
155 |
||
13227 | 156 |
version_CVS |
25423
bcfde4da086a
Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
157 |
^ '$Header$' |
13227 | 158 |
! ! |
15828 | 159 |