added:
#asLocalTimestamp
#asUtcTimestamp
#fromUtcOSTime:
#utcNow
comment/format in:
#fromOSTime:
#midnight
#noon
changed:
#asTimestamp
#documentation
--- a/Time.st Mon Jan 24 20:56:01 2011 +0100
+++ b/Time.st Mon Jan 24 20:56:23 2011 +0100
@@ -43,6 +43,9 @@
Use instances of Timestamp (and read the comment there) to do this.
+ Time now returns the time in the local timezone.
+ Use Time utcNow to get the time in the UTC zone.
+
Examples:
|t|
@@ -128,7 +131,7 @@
midnight
"Answer a new instance at midnight."
- ^self fromSeconds: 0
+ ^ self fromSeconds: 0
"
Time midnight
@@ -138,7 +141,7 @@
noon
"Answer a new instance at noon."
- ^self fromSeconds: 43200 "12*60*60"
+ ^ self fromSeconds: 43200 "12*60*60"
"
Time noon
@@ -245,6 +248,22 @@
"
"Modified: 8.10.1996 / 19:32:11 / cg"
+!
+
+utcNow
+ "return an instance of myself representing this moment."
+
+ ^ self basicNew fromUtcOSTime:(OperatingSystem getOSTime)
+
+ "
+ Timestamp now
+ Timestamp utcNow
+
+ Time now
+ Time utcNow
+ "
+
+ "Modified: 1.7.1996 / 15:20:10 / cg"
! !
!Time class methodsFor:'format strings'!
@@ -472,6 +491,25 @@
!Time methodsFor:'converting'!
+asLocalTimestamp
+ "return an Timestamp object from the receiver.
+ So I am interpreted as a Time in the local timezone.
+ The date components are taken from today."
+
+ |todayTimestamp|
+
+ todayTimestamp := Timestamp now.
+ todayTimestamp year:todayTimestamp year month:todayTimestamp month day:todayTimestamp day
+ hour:(self hours) minute:(self minutes) second:(self seconds)
+ millisecond:(self milliseconds).
+
+ ^ todayTimestamp.
+
+ "
+ Time now asLocalTimestamp
+ "
+!
+
asSeconds
"return the number of seconds elapsed since midnight"
@@ -504,15 +542,30 @@
"return an Timestamp object from the receiver.
The date components are taken from today."
- |today|
+ ^ self asLocalTimestamp
- today := Date today.
- ^ Timestamp year:today year month:today month day:today day
- hour:(self hours) minute:(self minutes) second:(self seconds)
- millisecond:(self milliseconds)
"
Time now asTimestamp
"
+!
+
+asUtcTimestamp
+ "return an UtcTimestamp object from the receiver.
+ So I am interpreted as a Time in the UTC zone.
+ The date components are taken from today."
+
+ |todayTimestamp|
+
+ todayTimestamp := UtcTimestamp now.
+ todayTimestamp year:todayTimestamp year month:todayTimestamp month day:todayTimestamp day
+ hour:(self hours) minute:(self minutes) second:(self seconds)
+ millisecond:(self milliseconds).
+
+ ^ todayTimestamp.
+
+ "
+ Time now asUtcTimestamp
+ "
! !
!Time methodsFor:'printing & storing'!
@@ -643,7 +696,7 @@
!Time methodsFor:'private'!
fromOSTime:osTime
- "set my time, given an osTime"
+ "set my time in the local timezone, given an osTime"
|i|
@@ -653,6 +706,17 @@
"Modified: 1.7.1996 / 15:21:06 / cg"
!
+fromUtcOSTime:osTime
+ "set my time in the local timezone, given an osTime"
+
+ |i|
+
+ i := OperatingSystem computeUTCTimeAndDateFrom:osTime.
+ self setHours:(i hours) minutes:(i minutes) seconds:(i seconds)
+
+ "Modified: 1.7.1996 / 15:21:06 / cg"
+!
+
getMilliseconds
"return the number of milliseconds since midnight"
@@ -719,9 +783,9 @@
!Time class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.88 2011-01-16 10:28:01 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.89 2011-01-24 19:56:23 stefan Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.88 2011-01-16 10:28:01 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.89 2011-01-24 19:56:23 stefan Exp $'
! !