#REFACTORING by cg
class: Time
added: #asTZTimestamp
comment/format in:
#asLocalTimestamp
#asUtcTimestamp
changed: #asTime
class: Time class
added: #hours:minutes:
changed:
#hour:minute:
#hour:minute:second:
--- a/Time.st Mon Jul 17 14:14:20 2017 +0200
+++ b/Time.st Mon Jul 17 14:14:37 2017 +0200
@@ -95,21 +95,33 @@
hour:h minute:m
"compatibility"
+ <resource:#obsolete>
+
+ self obsoleteMethodWarning:'use #hours:minutes:seconds:'.
+
^ self hours:h minutes:m seconds:0
"
Time hour:2 minute:33
"
+
+ "Modified: / 17-07-2017 / 14:04:39 / cg"
!
hour:h minute:m second:s
"compatibility"
+ <resource:#obsolete>
+
+ self obsoleteMethodWarning:'use #hours:minutes:seconds:'.
+
^ self hours:h minutes:m seconds:s
"
Time hour:2 minute:33 second:0
"
+
+ "Modified: / 17-07-2017 / 14:04:34 / cg"
!
hour:h minutes:m seconds:s
@@ -133,6 +145,18 @@
"Modified: 19.4.1996 / 15:32:40 / cg"
!
+hours:h minutes:m
+ "return a new TimeDuration representing a duration of h hours and m minutes.
+ See also Time now / Date today / Timestamp now."
+
+ ^ self basicNew setHours:h minutes:m seconds:0 milliseconds:0
+
+ "
+ TimeDuration hours:2 minutes:33
+ TimeDuration hours:100 minutes:33
+ "
+!
+
hours:h minutes:m seconds:s
"return an instance of Time representing the given time.
See also Time now / Date today / Timestamp now."
@@ -499,6 +523,8 @@
^ '%h:%m:%s.%i'
! !
+
+
!Time methodsFor:'Compatibility-Backward'!
asMilliSeconds
@@ -791,21 +817,48 @@
|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
+ 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
"
+
+ "Modified (format): / 17-07-2017 / 14:07:27 / cg"
+!
+
+asTZTimestamp
+ "return a TZTimestamp object from the receiver.
+ This includes the local timezone information."
+
+ ^ self asLocalTimestamp asTZTimestamp.
+
+ "
+ Time now asTZTimestamp -> 2017-07-17 14:11:16+02
+ Time now asUtcTimestamp -> 2017-07-17 12:11:16Z
+ Time now asLocalTimestamp -> 2017-07-17 14:11:16
+ "
+
+ "Created: / 17-07-2017 / 14:11:14 / cg"
!
asTime
"return a Time object from the receiver - that's the receiver."
- ^ self
+ self class == Time ifTrue:[
+ ^ self
+ ].
+ ^ super asTime
+
+ "Modified: / 17-07-2017 / 14:06:53 / cg"
!
asTimeDuration
@@ -835,18 +888,15 @@
So I am interpreted as a Time in the UTC zone.
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 asUtcTimestamp.
+ ^ self asLocalTimestamp asUtcTimestamp.
"
- Time now asUtcTimestamp
+ Time now asTimestamp -> 2017-07-17 14:08:22
+ Time now asLocalTimestamp -> 2017-07-17 14:08:24
+ Time now asUtcTimestamp -> 2017-07-17 12:08:27Z
"
+
+ "Modified (comment): / 17-07-2017 / 14:09:45 / cg"
! !
!Time methodsFor:'printing & storing'!
@@ -1091,6 +1141,7 @@
timeEncoding := encoding
! !
+
!Time class methodsFor:'documentation'!
version