16954
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2014 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:#TZTimestamp
|
|
15 |
instanceVariableNames:'utcOffset'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Magnitude-Time'
|
|
19 |
!
|
|
20 |
|
|
21 |
!TZTimestamp class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2014 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 |
documentation
|
|
38 |
"
|
|
39 |
This class represents time values in milliSeconds starting some time in the past,
|
|
40 |
which were created in another (explicit) timezone.
|
|
41 |
Internally, they keep the milliseconds based on UTC time (just like the other timestamps),
|
|
42 |
so the time values can be compared easily.
|
|
43 |
However, wehn printed, the original timezone information is taken into account.
|
|
44 |
|
|
45 |
Also Note:
|
|
46 |
On UNIX, osTime can only hold dates between 1970-01-01T00:00:00Z and 2038-01-19T00:00:00Z
|
|
47 |
However, timestamp instances can now hold negative osTime values (which are timestamps
|
|
48 |
before 1.1.1970 and greater than 4294967295 (2^32-1) for timestamps after 2038-01-19.
|
|
49 |
|
16966
|
50 |
[example:]
|
|
51 |
the current time as local time:
|
|
52 |
Transcript showCR:Timestamp now
|
|
53 |
|
|
54 |
the current time as utc time:
|
|
55 |
Transcript showCR:UtcTimestamp now
|
|
56 |
|
|
57 |
same:
|
|
58 |
Transcript showCR:Timestamp now asUtcTimestamp
|
|
59 |
|
|
60 |
the current time in NewYork:
|
16976
|
61 |
Transcript showCR:( Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST'))
|
16966
|
62 |
|
16954
|
63 |
[author:]
|
|
64 |
Claus Gittinger
|
|
65 |
|
|
66 |
[See also:]
|
|
67 |
Timestamp UtcTimestamp Time Date
|
|
68 |
"
|
|
69 |
! !
|
|
70 |
|
|
71 |
!TZTimestamp methodsFor:'accessing'!
|
|
72 |
|
16966
|
73 |
isLocalTimestamp
|
|
74 |
^ false
|
|
75 |
!
|
|
76 |
|
|
77 |
timeInfo
|
|
78 |
"fake it"
|
|
79 |
|
|
80 |
|ti|
|
|
81 |
|
|
82 |
"/ utcOffset negative: east of GMT
|
|
83 |
ti := OperatingSystem computeUTCTimeAndDateFrom:(osTime - (utcOffset * 1000)).
|
|
84 |
ti utcOffset:utcOffset.
|
|
85 |
^ ti
|
|
86 |
!
|
|
87 |
|
16954
|
88 |
utcOffset
|
|
89 |
"return the difference between UTC (Greenwich Mean Time) and the local time in seconds.
|
|
90 |
If daylight saving time applies to ourself, take that into account.
|
|
91 |
|
|
92 |
Add utcOffset to convert from local time to UTC time.
|
|
93 |
Subtract utcOffset to convert from UTC time to local time.
|
|
94 |
|
|
95 |
If utcOffset is negative, the local timezone is east of Greenwich.
|
|
96 |
If utcOffset is positive, the local timezone is west of Greenwich."
|
|
97 |
|
|
98 |
^ utcOffset
|
|
99 |
!
|
|
100 |
|
|
101 |
utcOffset:seconds
|
|
102 |
"set the difference between UTC (Greenwich Mean Time) and the local time in seconds.
|
|
103 |
If daylight saving time applies to ourself, take that into account.
|
|
104 |
|
|
105 |
Add utcOffset to convert from local time to UTC time.
|
|
106 |
Subtract utcOffset to convert from UTC time to local time.
|
|
107 |
|
|
108 |
If utcOffset is negative, the local timezone is east of Greenwich.
|
|
109 |
If utcOffset is positive, the local timezone is west of Greenwich."
|
|
110 |
|
|
111 |
utcOffset := seconds
|
|
112 |
! !
|
|
113 |
|
16966
|
114 |
!TZTimestamp methodsFor:'converting'!
|
|
115 |
|
|
116 |
asLocalTimestamp
|
|
117 |
"return a local timestamp, representing the same time as the receiver"
|
|
118 |
|
|
119 |
^ Timestamp fromOSTime:osTime.
|
|
120 |
!
|
|
121 |
|
|
122 |
asTZTimestamp:utcOffsetArg
|
|
123 |
"return a timestamp in a given timezone, representing the same time as the receiver"
|
|
124 |
|
|
125 |
utcOffset = utcOffsetArg ifTrue:[
|
|
126 |
^ self.
|
|
127 |
].
|
|
128 |
^ super asTZTimestamp:utcOffsetArg
|
16976
|
129 |
|
|
130 |
"what is the time now in NewYork?
|
|
131 |
Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')
|
|
132 |
|
|
133 |
what is the time now in Stuttgart?
|
|
134 |
Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'MEZ')
|
|
135 |
"
|
16966
|
136 |
! !
|
|
137 |
|
16954
|
138 |
!TZTimestamp class methodsFor:'documentation'!
|
|
139 |
|
|
140 |
version
|
16976
|
141 |
^ '$Header: /cvs/stx/stx/libbasic/TZTimestamp.st,v 1.3 2014-11-07 18:45:04 cg Exp $'
|
16954
|
142 |
!
|
|
143 |
|
|
144 |
version_CVS
|
16976
|
145 |
^ '$Header: /cvs/stx/stx/libbasic/TZTimestamp.st,v 1.3 2014-11-07 18:45:04 cg Exp $'
|
16954
|
146 |
! !
|
|
147 |
|