#BUGFIX by stefan
class: Timestamp
added:
#differenceFromTimestamp:
comment/format in: #printStringIso8601Compressed
changed:
#millisecondDeltaFrom:
#printIso8601FormatOn:compressed:timeSeparator:
#printOn:
#setMicrosecond:
#setMillisecond:
#setNanosecond:
#utcOffset:
Fix comparing (RegressionTests::TimeAndDateTest)
Lint removal
class: Timestamp class
changed: #readFrom:format:language:onError:
--- a/Timestamp.st Fri Jul 27 12:12:31 2018 +0200
+++ b/Timestamp.st Fri Jul 27 12:13:09 2018 +0200
@@ -1040,7 +1040,7 @@
|day month year dayOfYear monthAndDay
hour minute second millisecond
utcOffset inStream formatStream error fChar format itemHandler
- len now s fractionString fraction picos ts|
+ len s fractionString fraction picos ts|
error := [:msg |
exceptionalValue isBlock ifTrue:[
@@ -1206,7 +1206,7 @@
].
year isNil ifTrue:[
- year := (now := Timestamp now) year
+ year := Timestamp now year
].
dayOfYear notNil ifTrue:[
@@ -1258,6 +1258,8 @@
Timestamp readFrom:'20-2-1995 13:11:06.001' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt]
Timestamp readFrom:'20-2-1995 13:11:06.12345' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt]
"
+
+ "Modified: / 27-07-2018 / 11:57:59 / Stefan Vogel"
!
readFrom:aStringOrStream onError:exceptionBlock
@@ -1952,40 +1954,6 @@
! !
-!Timestamp methodsFor:'Compatibility-ST80'!
-
-hour
- "return the hour (0..23).
- ST-80 Timestamp compatibility
- (I'd prefer the name #hours, for Time compatibility)."
-
- ^ self hours
-
- "Created: 1.7.1996 / 15:14:50 / cg"
- "Modified: 1.7.1996 / 15:15:32 / cg"
-!
-
-minute
- "return the minute (0..59).
- ST-80 Timestamp compatibility
- (I'd prefer the name #minutes, for Time compatibility)."
-
- ^ self minutes
-
- "Created: 1.7.1996 / 15:14:29 / cg"
- "Modified: 1.7.1996 / 15:15:37 / cg"
-!
-
-second
- "return the second (0..59).
- ST-80 Timestamp compatibility
- (I'd prefer the name #seconds, for Time compatibility)."
-
- ^ self seconds
-
- "Created: 1.7.1996 / 15:14:19 / cg"
- "Modified: 1.7.1996 / 15:15:49 / cg"
-! !
!Timestamp methodsFor:'accessing'!
@@ -2619,9 +2587,9 @@
millisecondDeltaFrom:aTimestamp
"return the delta in milliseconds between 2 absolute times.
The argument is supposed to be BEFORE the receiver,
- computes self - aTimestamp"
-
- ^ self getMilliseconds - (aTimestamp getMilliseconds)
+ computes self - aTimestamp"
+
+ ^ osTime - (aTimestamp getMilliseconds)
"
|t1 t2|
@@ -2633,6 +2601,7 @@
"
"Modified: / 10-07-2010 / 09:37:18 / cg"
+ "Modified: / 27-07-2018 / 10:34:11 / Stefan Vogel"
!
roundedToSecond
@@ -2889,7 +2858,8 @@
^ TZTimestamp new
osTime:osTime;
- utcOffset:(anOffset asTimeDuration)
+ utcOffset:(anOffset asTimeDuration);
+ yourself.
"
Timestamp now -- now as local time
@@ -2900,6 +2870,8 @@
Timestamp now utcOffset:(5 hours) -- now in Eastern time
Timestamp now asTZTimestampInZone:'EST' -- now in Eastern time
"
+
+ "Modified: / 27-07-2018 / 11:54:45 / Stefan Vogel"
!
utcSecondsSince1901
@@ -2918,6 +2890,21 @@
"
! !
+!Timestamp methodsFor:'double dispatching'!
+
+differenceFromTimestamp:aTimestamp
+ |newMillis newPicos|
+
+ newMillis := aTimestamp getMilliseconds - osTime.
+ newPicos := (aTimestamp additionalPicoseconds) - (additionalPicoseconds ? 0).
+
+ ^ TimeDuration basicNew
+ setMilliseconds:newMillis additionalPicoseconds:newPicos.
+
+ "Created: / 27-07-2018 / 08:45:22 / Stefan Vogel"
+ "Modified (format): / 27-07-2018 / 10:50:05 / Stefan Vogel"
+! !
+
!Timestamp methodsFor:'initialization'!
UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis
@@ -3248,11 +3235,8 @@
self isUtcTimestamp ifTrue:[
asUTC := true. asLocal := false.
] ifFalse:[
- self isLocalTimestamp ifTrue:[
- asUTC := false. asLocal := true.
- ] ifFalse:[
- asUTC := false. asLocal := false.
- ]
+ asUTC := false.
+ asLocal := self isLocalTimestamp.
].
Timestamp::TimestampISO8601Builder
@@ -3288,6 +3272,7 @@
"Created: / 24-05-2018 / 17:28:25 / Claus Gittinger"
"Modified (comment): / 25-05-2018 / 12:00:14 / Claus Gittinger"
+ "Modified: / 27-07-2018 / 11:57:21 / Stefan Vogel"
!
printIso8601FormatOn:aStream timeSeparator:sepChar
@@ -3333,20 +3318,16 @@
|asUTC asLocal|
self isUtcTimestamp ifTrue:[
- asUTC := true. asLocal := false.
+ asUTC := true. asLocal := false.
] ifFalse:[
- self isLocalTimestamp ifTrue:[
- asUTC := false. asLocal := true.
- ] ifFalse:[
- asUTC := false. asLocal := false.
- ]
+ asLocal := self isLocalTimestamp.
].
Timestamp::TimestampISO8601Builder
- print:self compact:false
- asLocal:asLocal asUTC:asUTC withMilliseconds:true
- timeSeparator:(Character space)
- on:aStream
+ print:self compact:false
+ asLocal:asLocal asUTC:asUTC withMilliseconds:true
+ timeSeparator:(Character space)
+ on:aStream
"/ self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'
"/ self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i'
@@ -3375,7 +3356,8 @@
Date today printOn:Transcript. Transcript cr.
"
- "Modified: 1.7.1996 / 15:20:59 / cg"
+ "Modified: / 01-07-1996 / 15:20:59 / cg"
+ "Modified: / 27-07-2018 / 11:58:58 / Stefan Vogel"
!
printRFC1123FormatOn:aStream
@@ -3438,34 +3420,6 @@
"
!
-printStringIso8601Compressed
- "return a printString as UTC in a format like 20141017T170939Z.
- Notice: if the receiver is a UTCTimestamp, it is printed as 20141017T170939Z;
- if it has timezone info attached (i.e. is a TZTimestamp), it is printed as 20141017T170939+01;
- if it is a local timestamp (without any TZ info), it is printed as such: 20141017T170939"
-
- ^ String streamContents:[:s | self printIso8601CompressedOn:s]
-
- "
- Timestamp now printStringIso8601Compressed
- TZTimestamp now printStringIso8601Compressed
- UtcTimestamp now printStringIso8601Compressed
- Timestamp now asUtcTimestamp printStringIso8601Compressed
-
- Time now printStringIso8601Compressed
-
- (Timestamp readFrom:'2018-05-24T17:26:40.271') printStringIso8601
- (Timestamp readFrom:'2018-05-24T17:26:40.271+02') printStringIso8601
- Timestamp now printStringIso8601
- TZTimestamp now printStringIso8601
- UtcTimestamp now printStringIso8601
- Timestamp now asUtcTimestamp printStringIso8601
- "
-
- "Created: / 16-06-2005 / 16:11:31 / masca"
- "Modified (comment): / 25-05-2018 / 12:02:18 / Claus Gittinger"
-!
-
printStringRFC1123Format
"return the RFC1123 representation of the receiver.
This format is used in HTTP requests and looks like:
@@ -3641,7 +3595,7 @@
"change the sub-second fractional part only (leaves everything above seconds unchanged)"
self
- setMilliseconds:(self getMilliseconds // 1000) * 1000 "/ strip off any sub-second part
+ setMilliseconds:(osTime // 1000) * 1000 "/ strip off any sub-second part
additionalPicoseconds:(aNumber * 1000000) truncated. "/ set picos
"
@@ -3649,14 +3603,14 @@
Timestamp now setMicrosecond:0.1 - 100 nanoseconds after the current second's start
"
- "Modified (format): / 22-05-2018 / 16:53:26 / Stefan Vogel"
+ "Modified: / 27-07-2018 / 10:34:18 / Stefan Vogel"
!
setMillisecond:aNumber
"change the sub-second fractional part only (leaves everything above seconds unchanged)"
self
- setMilliseconds:(self getMilliseconds // 1000) * 1000 "/ strip off any sub-second part
+ setMilliseconds:(osTime // 1000) * 1000 "/ strip off any sub-second part
additionalPicoseconds:(aNumber * 1000000000) truncated. "/ set picos
"
@@ -3664,7 +3618,7 @@
Timestamp now setMillisecond:0.05 - 50 microseconds after the current second's start
"
- "Modified (format): / 22-05-2018 / 16:53:38 / Stefan Vogel"
+ "Modified: / 27-07-2018 / 10:34:42 / Stefan Vogel"
!
setMilliseconds:millis
@@ -3705,13 +3659,15 @@
"change the sub-second fractional part only (leaves everything above seconds unchanged)"
self
- setMilliseconds:(self getMilliseconds // 1000) * 1000 "/ strip off any sub-second part
+ setMilliseconds:(osTime // 1000) * 1000 "/ strip off any sub-second part
additionalPicoseconds:(aNumber * 1000) rounded. "/ set picos
"
Timestamp now setNanosecond:15 - 15 nanoseconds after the current second's start
Timestamp now setNanosecond:0.1 - 10 picoseconds after the current second's start
"
+
+ "Modified: / 27-07-2018 / 10:34:52 / Stefan Vogel"
!
setSeconds:secs