TZTimestamp.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 24164 a75b5edab98a
child 24880 1ba2822c99b7
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18453
71812472e0a5 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 18450
diff changeset
     1
"{ Encoding: utf8 }"
71812472e0a5 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 18450
diff changeset
     2
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2014 by eXept Software AG
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic' }"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    16
"{ NameSpace: Smalltalk }"
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    17
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Timestamp subclass:#TZTimestamp
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'utcOffset'
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Magnitude-Time'
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!TZTimestamp class methodsFor:'documentation'!
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
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 2014 by eXept Software AG
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
              All Rights Reserved
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    This class represents time values in milliSeconds starting some time in the past,
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    which were created in another (explicit) timezone.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    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
    46
    so the time values can be compared easily.
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    47
    However, when printed, the original timezone information is taken into account.
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    Also Note:
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        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
    51
        However, timestamp instances can hold negative osTime values (which are timestamps
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
        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
    53
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    54
    [example:]
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    55
      the current time as local time:
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    56
        Transcript showCR:Timestamp now
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    57
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    58
      the current time as utc time:       
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    59
        Transcript showCR:UtcTimestamp now.
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    60
      same:
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    61
        Transcript showCR:Timestamp now asUtcTimestamp.
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    62
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    63
      the current time in NewYork:         
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    64
        Transcript showCR:( Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'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 asTZTimestampInZone:'EST' )
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    67
      same
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    68
        Transcript showCR:( Timestamp now asTZTimestamp:(5*3600) ) 
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    69
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    70
      what is the current time in Berlin:
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    71
        Transcript showCR:( Timestamp now asTZTimestampInZone:'MEZ' ) 
22889
faa5502c4f9f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18453
diff changeset
    72
17134
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    73
      and the date:
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    74
        Transcript showCR:( Timestamp now asTZTimestampInZone:'MEZ' ) asDate
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    75
      and the date in Tokio:
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    76
        Transcript showCR:( Timestamp now asTZTimestampInZone:'JST' ) asDate
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    77
      and the date in Hawai:
161e73014492 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17103
diff changeset
    78
        Transcript showCR:( Timestamp now asTZTimestampInZone:'HAST' ) asDate
22889
faa5502c4f9f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18453
diff changeset
    79
      and the date in NewYork:
faa5502c4f9f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18453
diff changeset
    80
        Transcript showCR:( Timestamp now asTZTimestampInZone:'EST' ) asDate
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    81
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    [author:]
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
        Claus Gittinger
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    [See also:]
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
        Timestamp UtcTimestamp Time Date
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
! !
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    90
!TZTimestamp class methodsFor:'instance creation'!
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    91
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    92
fromDate:aDate andTime:aTime utcOffset:utcOffsetSeconds
22892
aaf413123349 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22889
diff changeset
    93
    "return an instance of the receiver, 
aaf413123349 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22889
diff changeset
    94
     initialized from a time and a date object. 
22893
8398b8003a8e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22892
diff changeset
    95
     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
    96
     See also `Timestamp now' and other protocol inherited
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    97
     from my superclass."
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    98
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
    99
    ^ (self
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   100
        UTCYear:aDate year
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   101
        month:aDate month
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   102
        day:aDate day
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   103
        hour:aTime hours
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   104
        minute:aTime minutes
22892
aaf413123349 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22889
diff changeset
   105
        second:(aTime seconds + utcOffsetSeconds)
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   106
        millisecond:aTime milliseconds)
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   107
            utcOffset:utcOffsetSeconds
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   108
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   109
    "
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   110
     Timestamp fromDate:(Date today) andTime:(Time now)
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   111
     Timestamp fromDate:(Date today) andTime:(Time nowWithMilliseconds)
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   112
22892
aaf413123349 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22889
diff changeset
   113
     TZTimestamp fromDate:(Date today) andTime:(Time now) utcOffset:3600
aaf413123349 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22889
diff changeset
   114
17423
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   115
     Timestamp fromDate:(Date today plusDays:1) andTime:(Time now)
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   116
     Timestamp now
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   117
    "
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   118
! !
f8f1483630b2 class: TZTimestamp
Stefan Vogel <sv@exept.de>
parents: 17134
diff changeset
   119
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
!TZTimestamp methodsFor:'accessing'!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   122
isLocalTimestamp
23004
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   123
    "return true, if I am a local timestamp (i.e. with no TZ info)"
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   124
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   125
    ^ false
23004
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   126
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   127
    "Modified (comment): / 24-05-2018 / 17:29:26 / Claus Gittinger"
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   128
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   129
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   130
timeInfo
16984
46430aef9bec class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16980
diff changeset
   131
    "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
   132
     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
   133
     Also, it (currently) only works for timestamps after the epoch"
16966
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
    |ti|
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   136
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   137
    "/ utcOffset negative: east of GMT
18453
71812472e0a5 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 18450
diff changeset
   138
    ti := OperatingSystem computeUTCTimeAndDateFrom:(osTime - ((utcOffset ? 0) * 1000)).
71812472e0a5 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 18450
diff changeset
   139
    ti utcOffset:(utcOffset ? 0).
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   140
    ^ ti
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   141
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   142
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
utcOffset
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    "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
   145
     If daylight saving time applies to ourself, take that into account.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
     Add utcOffset to convert from local time to UTC time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
     Subtract utcOffset to convert from UTC time to local time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
     If utcOffset is negative, the local timezone is east of Greenwich.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
     If utcOffset is positive, the local timezone is west of Greenwich."
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
18453
71812472e0a5 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 18450
diff changeset
   153
    ^ utcOffset ? 0
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
24164
a75b5edab98a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23004
diff changeset
   156
utcOffset:secondsOrTimeDuration
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    "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
   158
     If daylight saving time applies to ourself, take that into account.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
     Add utcOffset to convert from local time to UTC time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
     Subtract utcOffset to convert from UTC time to local time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
     If utcOffset is negative, the local timezone is east of Greenwich.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
     If utcOffset is positive, the local timezone is west of Greenwich."
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
24164
a75b5edab98a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23004
diff changeset
   166
    utcOffset := secondsOrTimeDuration asInteger.
17103
d390437c201f class: TZTimestamp
sr
parents: 17050
diff changeset
   167
d390437c201f class: TZTimestamp
sr
parents: 17050
diff changeset
   168
    "Modified: / 20-11-2014 / 13:05:48 / sr"
24164
a75b5edab98a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23004
diff changeset
   169
    "Modified (format): / 26-05-2019 / 12:09:21 / Claus Gittinger"
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
! !
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   172
!TZTimestamp methodsFor:'converting'!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   173
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   174
asLocalTimestamp
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   175
    "return a local timestamp, representing the same time as the receiver"
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
    ^ Timestamp fromOSTime:osTime.
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   178
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   179
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   180
asTZTimestamp:utcOffsetArg
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   181
    "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
   182
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   183
    utcOffset = utcOffsetArg ifTrue:[
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   184
        ^ self.
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   185
    ].
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   186
    ^ super asTZTimestamp:utcOffsetArg
16976
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   187
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   188
    "what is the time now in NewYork?
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   189
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST') 
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   190
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   191
     what is the time now in Stuttgart?
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   192
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'MEZ')  
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   193
    "
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   194
! !
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   195
17019
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   196
!TZTimestamp methodsFor:'private'!
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   197
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   198
speciesNew
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   199
    ^ self species basicNew 
18450
77835f6f73ad class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 17423
diff changeset
   200
        utcOffset:(utcOffset ? 0);
17019
15fb22ffb5fe class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16984
diff changeset
   201
        yourself
17050
f421040c58ae class: TZTimestamp
ca
parents: 17019
diff changeset
   202
!
f421040c58ae class: TZTimestamp
ca
parents: 17019
diff changeset
   203
f421040c58ae class: TZTimestamp
ca
parents: 17019
diff changeset
   204
storeStringClass
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
23004
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   208
!TZTimestamp methodsFor:'testing'!
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   209
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   210
isTZTimestamp
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   211
    "return true, if I am a timestamp with TZ info"
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   212
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   213
    ^ true
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   214
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   215
    "Created: / 24-05-2018 / 17:30:38 / Claus Gittinger"
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
diff changeset
   216
! !
0fc6b6027916 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22893
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
22889
faa5502c4f9f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18453
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
22889
faa5502c4f9f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18453
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