--- a/UtcTimestamp.st Tue Nov 11 13:13:44 2014 +0100
+++ b/UtcTimestamp.st Tue Nov 11 13:14:23 2014 +0100
@@ -75,12 +75,53 @@
!UtcTimestamp methodsFor:'converting'!
+asDate
+ "return a Date object from the receiver.
+ The returned date will only represent the day - not the timeOfDay.
+ Notice: if you convert a local timestamp, you will get the local date;
+ otherwise if you convert an utcTimestamp, you'll get the utc date."
+
+ (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
+ |dayDelta day0|
+
+ dayDelta := osTime // (24 * 3600 * 1000).
+ day0 := Epoch asDate.
+ ^ day0 addDays:dayDelta.
+ ].
+ ^ self timeInfo asDate
+
+ "
+ Timestamp now
+ Timestamp now asDate
+ (Timestamp now addTime:3600) asDate
+ (Timestamp now addTime:3600) asTime
+ Timestamp fromSeconds:(Timestamp now asSeconds + 3600)
+ (Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate
+ "
+!
+
asLocalTimestamp
"represent myself as a timestamp in the local timezone"
^ Timestamp fromOSTime:osTime
!
+asTime
+ "return a Time object from the receiver.
+ The returned time will only represent the timeOfDay - not the day,
+ and does not include the milliseconds."
+
+ |secondDelta|
+
+ (osTime between:MinOSTime and:MaxOSTime) ifFalse:[
+ secondDelta := osTime // 1000.
+ "/ we do not know about DST in the far future and in the long gone past.
+ secondDelta := secondDelta rem:(24*3600) .
+ ^ Epoch asTime addSeconds:secondDelta.
+ ].
+ ^ self timeInfo asTime
+!
+
asUtcTimestamp
"I am an UtcTimestamp"
@@ -130,10 +171,10 @@
!UtcTimestamp class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.11 2014-11-08 00:20:53 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.12 2014-11-11 12:14:23 stefan Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.11 2014-11-08 00:20:53 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UtcTimestamp.st,v 1.12 2014-11-11 12:14:23 stefan Exp $'
! !