TZTimestamp.st
author Jan Vrany <jan.vrany@labware.com>
Mon, 29 Nov 2021 23:00:04 +0000
branchjv
changeset 25437 622824e701ea
parent 25423 bcfde4da086a
permissions -rw-r--r--
Fix `ObjectMemory >> #nameForSnapshot` ...to actually do what the comment says: return current image name (if any).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2014 by eXept Software AG
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic' }"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    14
"{ NameSpace: Smalltalk }"
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    15
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Timestamp subclass:#TZTimestamp
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'utcOffset'
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Magnitude-Time'
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!TZTimestamp class methodsFor:'documentation'!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2014 by eXept Software AG
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    This class represents time values in milliSeconds starting some time in the past,
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    which were created in another (explicit) timezone.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    Internally, they keep the milliseconds based on UTC time (just like the other timestamps),
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    so the time values can be compared easily.
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    45
    However, when printed, the original timezone information is taken into account.
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    Also Note:
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
        On UNIX, osTime can only hold dates between 1970-01-01T00:00:00Z and 2038-01-19T00:00:00Z
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    49
        However, timestamp instances can hold negative osTime values (which are timestamps
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        before 1.1.1970 and greater than 4294967295 (2^32-1) for timestamps after 2038-01-19.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    52
    [example:]
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    53
      the current time as local time:
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    54
        Transcript showCR:Timestamp now
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    55
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    56
      the current time as utc time:       
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    57
        Transcript showCR:UtcTimestamp now.
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    58
      same:
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    59
        Transcript showCR:Timestamp now asUtcTimestamp.
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    60
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    61
      the current time in NewYork:         
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    62
        Transcript showCR:( Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST') ) 
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    63
      same
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    64
        Transcript showCR:( Timestamp now asTZTimestampInZone:'EST' )
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    65
      same
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    66
        Transcript showCR:( Timestamp now asTZTimestamp:(5*3600) ) 
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    67
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    68
      what is the current time in Berlin:
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    69
        Transcript showCR:( Timestamp now asTZTimestampInZone:'MEZ' ) 
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
    70
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    71
      and the date:
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    72
        Transcript showCR:( Timestamp now asTZTimestampInZone:'MEZ' ) asDate
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    73
      and the date in Tokio:
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    74
        Transcript showCR:( Timestamp now asTZTimestampInZone:'JST' ) asDate
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    75
      and the date in Hawai:
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    76
        Transcript showCR:( Timestamp now asTZTimestampInZone:'HAST' ) asDate
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
    77
      and the date in NewYork:
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
    78
        Transcript showCR:( Timestamp now asTZTimestampInZone:'EST' ) asDate
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    79
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    [author:]
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
        Claus Gittinger
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    [See also:]
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
        Timestamp UtcTimestamp Time Date
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
! !
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    88
!TZTimestamp class methodsFor:'instance creation'!
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    89
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    90
fromDate:aDate andTime:aTime utcOffset:utcOffsetSeconds
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
    91
    "return an instance of the receiver, 
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
    92
     initialized from a time and a date object. 
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
    93
     Both date and time are assumed to be the utcOffset's local time.
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    94
     See also `Timestamp now' and other protocol inherited
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    95
     from my superclass."
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    96
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    97
    ^ (self
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    98
        UTCYear:aDate year
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    99
        month:aDate month
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   100
        day:aDate day
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   101
        hour:aTime hours
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   102
        minute:aTime minutes
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   103
        second:(aTime seconds + utcOffsetSeconds)
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   104
        millisecond:aTime milliseconds)
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   105
            utcOffset:utcOffsetSeconds
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   106
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   107
    "
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   108
     Timestamp fromDate:(Date today) andTime:(Time now)
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   109
     Timestamp fromDate:(Date today) andTime:(Time nowWithMilliseconds)
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   110
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   111
     TZTimestamp fromDate:(Date today) andTime:(Time now) utcOffset:3600
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   112
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   113
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now)
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   114
     Timestamp now
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   115
    "
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   116
! !
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   117
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
!TZTimestamp methodsFor:'accessing'!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   120
isLocalTimestamp
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   121
    "return true, if I am a local timestamp (i.e. with no TZ info)"
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   122
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   123
    ^ false
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   124
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   125
    "Modified (comment): / 24-05-2018 / 17:29:26 / Claus Gittinger"
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   126
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   127
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   128
timeInfo
16984
46430aef9bec class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16980
diff changeset
   129
    "fake it. Convert to utc, ask OS for the info, then convert back.
46430aef9bec class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16980
diff changeset
   130
     This is returns wrong info for weekday and we have to compensate again.
46430aef9bec class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16980
diff changeset
   131
     Also, it (currently) only works for timestamps after the epoch"
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   132
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   133
    |ti|
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   134
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   135
    "/ utcOffset negative: east of GMT
18453
71812472e0a5 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 18450
diff changeset
   136
    ti := OperatingSystem computeUTCTimeAndDateFrom:(osTime - ((utcOffset ? 0) * 1000)).
71812472e0a5 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 18450
diff changeset
   137
    ti utcOffset:(utcOffset ? 0).
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   138
    ^ ti
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   139
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   140
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
utcOffset
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    "return the difference between UTC (Greenwich Mean Time) and the local time in seconds.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
     If daylight saving time applies to ourself, take that into account.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
     Add utcOffset to convert from local time to UTC time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
     Subtract utcOffset to convert from UTC time to local time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
     If utcOffset is negative, the local timezone is east of Greenwich.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
     If utcOffset is positive, the local timezone is west of Greenwich."
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
18453
71812472e0a5 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 18450
diff changeset
   151
    ^ utcOffset ? 0
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   154
utcOffset:secondsOrTimeDuration
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    "set the difference between UTC (Greenwich Mean Time) and the local time in seconds.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
     If daylight saving time applies to ourself, take that into account.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
     Add utcOffset to convert from local time to UTC time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
     Subtract utcOffset to convert from UTC time to local time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
     If utcOffset is negative, the local timezone is east of Greenwich.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
     If utcOffset is positive, the local timezone is west of Greenwich."
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   164
    utcOffset := secondsOrTimeDuration asInteger.
17103
d390437c201f class: TZTimestamp
sr
parents: 17050
diff changeset
   165
d390437c201f class: TZTimestamp
sr
parents: 17050
diff changeset
   166
    "Modified: / 20-11-2014 / 13:05:48 / sr"
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   167
    "Modified (format): / 26-05-2019 / 12:09:21 / Claus Gittinger"
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
! !
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   170
!TZTimestamp methodsFor:'converting'!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   171
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   172
asLocalTimestamp
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   173
    "return a local timestamp, representing the same time as the receiver"
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   174
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   175
    ^ Timestamp fromOSTime:osTime.
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   176
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   177
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   178
asTZTimestamp:utcOffsetArg
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   179
    "return a timestamp in a given timezone, representing the same time as the receiver"
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   180
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   181
    utcOffset = utcOffsetArg ifTrue:[
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   182
        ^ self.
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   183
    ].
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   184
    ^ super asTZTimestamp:utcOffsetArg
16976
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   185
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   186
    "what is the time now in NewYork?
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   187
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST') 
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   188
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   189
     what is the time now in Stuttgart?
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   190
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'MEZ')  
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   191
    "
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   192
! !
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   193
17019
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   194
!TZTimestamp methodsFor:'private'!
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   195
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   196
speciesNew
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   197
    ^ self species basicNew 
18450
77835f6f73ad class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17423
diff changeset
   198
        utcOffset:(utcOffset ? 0);
17019
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   199
        yourself
17050
f421040c58ae class: TZTimestamp
ca
parents: 17019
diff changeset
   200
!
f421040c58ae class: TZTimestamp
ca
parents: 17019
diff changeset
   201
f421040c58ae class: TZTimestamp
ca
parents: 17019
diff changeset
   202
storeStringClass
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   203
    "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
   204
17050
f421040c58ae class: TZTimestamp
ca
parents: 17019
diff changeset
   205
    ^ Timestamp
17019
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   206
! !
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   207
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   208
!TZTimestamp methodsFor:'testing'!
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   209
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   210
isTZTimestamp
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   211
    "return true, if I am a timestamp with TZ info"
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   212
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   213
    ^ true
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   214
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   215
    "Created: / 24-05-2018 / 17:30:38 / Claus Gittinger"
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   216
! !
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   217
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
!TZTimestamp class methodsFor:'documentation'!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
version
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   221
    ^ '$Header$'
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
version_CVS
25423
bcfde4da086a Cherry-picked `AbstractTime.st`, `Time`, `TimeDuration`, `Timestamp` `TZTimestamp` and `UtcTimestamp`
Jan Vrany <jan.vrany@labware.com>
parents: 23547
diff changeset
   225
    ^ '$Header$'
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
! !
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227