UtcTimestamp.st
changeset 17028 7f4490e83429
parent 16997 f0867a7f248b
child 17032 e2c097d59814
equal deleted inserted replaced
17027:ee9d70ce8559 17028:7f4490e83429
    73     ^ 0
    73     ^ 0
    74 ! !
    74 ! !
    75 
    75 
    76 !UtcTimestamp methodsFor:'converting'!
    76 !UtcTimestamp methodsFor:'converting'!
    77 
    77 
       
    78 asDate
       
    79     "return a Date object from the receiver.
       
    80      The returned date will only represent the day - not the timeOfDay.
       
    81      Notice: if you convert a local timestamp, you will get the local date;
       
    82      otherwise if you convert an utcTimestamp, you'll get the utc date."
       
    83 
       
    84     (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
       
    85         |dayDelta day0|
       
    86 
       
    87         dayDelta := osTime // (24 * 3600 * 1000).
       
    88         day0 := Epoch asDate.
       
    89         ^ day0 addDays:dayDelta.
       
    90     ].
       
    91     ^ self timeInfo asDate
       
    92 
       
    93     "
       
    94      Timestamp now
       
    95      Timestamp now asDate
       
    96      (Timestamp now addTime:3600) asDate
       
    97      (Timestamp now addTime:3600) asTime
       
    98      Timestamp fromSeconds:(Timestamp now asSeconds + 3600)
       
    99      (Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate
       
   100     "
       
   101 !
       
   102 
    78 asLocalTimestamp
   103 asLocalTimestamp
    79     "represent myself as a timestamp in the local timezone"
   104     "represent myself as a timestamp in the local timezone"
    80 
   105 
    81     ^ Timestamp fromOSTime:osTime
   106     ^ Timestamp fromOSTime:osTime
       
   107 !
       
   108 
       
   109 asTime
       
   110     "return a Time object from the receiver.
       
   111      The returned time will only represent the timeOfDay - not the day,
       
   112      and does not include the milliseconds."
       
   113 
       
   114     |secondDelta|
       
   115 
       
   116     (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
       
   117         secondDelta := osTime // 1000.
       
   118         "/ we do not know about DST in the far future and in the long gone past.
       
   119         secondDelta := secondDelta rem:(24*3600) .
       
   120         ^ Epoch asTime addSeconds:secondDelta.
       
   121     ].
       
   122     ^ self timeInfo asTime
    82 !
   123 !
    83 
   124 
    84 asUtcTimestamp
   125 asUtcTimestamp
    85     "I am an UtcTimestamp"
   126     "I am an UtcTimestamp"
    86 
   127 
   128 ! !
   169 ! !
   129 
   170 
   130 !UtcTimestamp class methodsFor:'documentation'!
   171 !UtcTimestamp class methodsFor:'documentation'!
   131 
   172 
   132 version
   173 version
   133     ^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.11 2014-11-08 00:20:53 cg Exp $'
   174     ^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.12 2014-11-11 12:14:23 stefan Exp $'
   134 !
   175 !
   135 
   176 
   136 version_CVS
   177 version_CVS
   137     ^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.11 2014-11-08 00:20:53 cg Exp $'
   178     ^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.12 2014-11-11 12:14:23 stefan Exp $'
   138 ! !
   179 ! !
   139 
   180