TZTimestamp.st
author Claus Gittinger <cg@exept.de>
Fri, 07 Nov 2014 19:45:04 +0100
changeset 16976 34cb1703d013
parent 16966 7d549c75105f
child 16980 299ae06e2db4
permissions -rw-r--r--
class: TZTimestamp comment/format in: #asTZTimestamp: #documentation
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
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
Timestamp subclass:#TZTimestamp
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'utcOffset'
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Magnitude-Time'
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!TZTimestamp class methodsFor:'documentation'!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
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 (c) 2014 by eXept Software AG
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
              All Rights Reserved
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
documentation
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
    This class represents time values in milliSeconds starting some time in the past,
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    which were created in another (explicit) timezone.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    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
    42
    so the time values can be compared easily.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    However, wehn printed, the original timezone information is taken into account.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    Also Note:
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
        On UNIX, osTime can only hold dates between 1970-01-01T00:00:00Z and 2038-01-19T00:00:00Z
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
        However, timestamp instances can now hold negative osTime values (which are timestamps
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
        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
    49
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    50
    [example:]
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    51
      the current time as local time:
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    52
        Transcript showCR:Timestamp now
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    53
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    54
      the current time as utc time:       
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    55
        Transcript showCR:UtcTimestamp now
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    56
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    57
      same:
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    58
        Transcript showCR:Timestamp now asUtcTimestamp
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    59
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    60
      the current time in NewYork:         
16976
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
    61
        Transcript showCR:( Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')) 
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    62
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    [author:]
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
        Claus Gittinger
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    [See also:]
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
        Timestamp UtcTimestamp Time Date
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
"
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
! !
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
!TZTimestamp methodsFor:'accessing'!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    73
isLocalTimestamp
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    74
    ^ false
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    75
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    76
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    77
timeInfo
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    78
    "fake it"
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    79
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    80
    |ti|
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    81
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    82
    "/ utcOffset negative: east of GMT
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    83
    ti := OperatingSystem computeUTCTimeAndDateFrom:(osTime - (utcOffset * 1000)).
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    84
    ti utcOffset:utcOffset.
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    85
    ^ ti
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    86
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
    87
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
utcOffset
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    "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
    90
     If daylight saving time applies to ourself, take that into account.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
     Add utcOffset to convert from local time to UTC time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
     Subtract utcOffset to convert from UTC time to local time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
     If utcOffset is negative, the local timezone is east of Greenwich.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
     If utcOffset is positive, the local timezone is west of Greenwich."
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    ^  utcOffset
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
utcOffset:seconds
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    "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
   103
     If daylight saving time applies to ourself, take that into account.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
     Add utcOffset to convert from local time to UTC time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
     Subtract utcOffset to convert from UTC time to local time.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
     If utcOffset is negative, the local timezone is east of Greenwich.
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
     If utcOffset is positive, the local timezone is west of Greenwich."
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    utcOffset := seconds
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
! !
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
16966
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   114
!TZTimestamp methodsFor:'converting'!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   115
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   116
asLocalTimestamp
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   117
    "return a local timestamp, representing the same time as the receiver"
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   118
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   119
    ^ Timestamp fromOSTime:osTime.
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   120
!
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   121
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   122
asTZTimestamp:utcOffsetArg
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   123
    "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
   124
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   125
    utcOffset = utcOffsetArg ifTrue:[
7d549c75105f class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16954
diff changeset
   126
        ^ self.
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
    ^ super asTZTimestamp:utcOffsetArg
16976
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   129
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   130
    "what is the time now in NewYork?
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   131
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST') 
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   132
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   133
     what is the time now in Stuttgart?
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   134
     Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'MEZ')  
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   135
    "
16966
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
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!TZTimestamp class methodsFor:'documentation'!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
version
16976
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   141
    ^ '$Header: /cvs/stx/stx/libbasic/TZTimestamp.st,v 1.3 2014-11-07 18:45:04 cg Exp $'
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
!
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
version_CVS
16976
34cb1703d013 class: TZTimestamp
Claus Gittinger <cg@exept.de>
parents: 16966
diff changeset
   145
    ^ '$Header: /cvs/stx/stx/libbasic/TZTimestamp.st,v 1.3 2014-11-07 18:45:04 cg Exp $'
16954
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
! !
e13618117ebc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147