--- a/AbstractTime.st Wed May 09 18:57:23 2018 +0200
+++ b/AbstractTime.st Wed May 09 18:57:35 2018 +0200
@@ -691,6 +691,17 @@
"
!
+nanoseconds
+ "return the nanoseconds within the current second (0..999999)"
+
+ ^ (self milliseconds * 1000000) + (self additionalPicoseconds // (1000)).
+
+ "
+ Timestamp now nanoseconds
+ Timestamp nowWithMicroseconds nanoseconds
+ "
+!
+
picoseconds
"return the picoseconds within the current second (0..999999999).
notice: that is NOT the total number of picoseconds,
@@ -698,11 +709,22 @@
Use this only for printing.
Here, fall back and generate something based on the milliseconds"
- ^ self milliseconds * 1000 * 1000 * 1000.
+ ^ (self milliseconds * 1000 * 1000 * 1000) + (self additionalPicoseconds).
"
Timestamp now picoseconds
Timestamp nowWithMicroseconds picoseconds
+
+ (TimeDuration fromPicoseconds:100) picoseconds
+ (TimeDuration fromPicoseconds:100000) picoseconds
+ (TimeDuration fromPicoseconds:100000) nanoseconds
+ (TimeDuration fromPicoseconds:100000000) picoseconds
+ (TimeDuration fromPicoseconds:100000000) nanoseconds
+ (TimeDuration fromPicoseconds:100000000) microseconds
+ (TimeDuration fromPicoseconds:100000000000) picoseconds
+ (TimeDuration fromPicoseconds:100000000000) nanoseconds
+ (TimeDuration fromPicoseconds:100000000000) microseconds
+ (TimeDuration fromPicoseconds:100000000000) milliseconds
"
!
@@ -737,17 +759,23 @@
!AbstractTime methodsFor:'arithmetic'!
+ aNumberOrTimeDuration
- "Add aNumber numberOfSeconds or, if it's a timeDuration, add it's value"
+ "Add aNumber (numberOfSeconds) or, if it's a timeDuration, add it's value"
^ aNumberOrTimeDuration sumFromTimestamp:self.
-"/ ^ self speciesNew
-"/ setMilliseconds:(self getMilliseconds + (aNumberOrTimeDuration * 1000) asInteger)
-
"
Timestamp now to:(Timestamp now + 30) by:2 do:[:time|
Transcript showCR:time.
].
+ Timestamp now to:(Timestamp now + 30) by:2 seconds do:[:time|
+ Transcript showCR:time.
+ ].
+ (Timestamp now + 30 seconds) to:(Timestamp now) by:-2 seconds do:[:time|
+ Transcript showCR:time.
+ ].
+ (Timestamp now + 30 seconds) to:(Timestamp now) by:-2 do:[:time|
+ Transcript showCR:time.
+ ].
(Timestamp now + 20) - Timestamp now
(Timestamp now + 0.5) - Timestamp now
@@ -758,17 +786,22 @@
"Modified (comment): / 13-02-2017 / 19:55:04 / cg"
!
-- aTimeOrNumberOfSeconds
+- aTimeOrTimeDurationOrNumberOfSeconds
"return the delta in seconds between 2 times or subtract a number of seconds."
- ^ aTimeOrNumberOfSeconds differenceFromTimestamp:self.
+ ^ aTimeOrTimeDurationOrNumberOfSeconds differenceFromTimestamp:self.
"
- Timestamp now - 3600.
- Time now - 3600.
- (Time now addSeconds:10) - Time now
- (TimeDuration fromString:'1.5hr') - 3600.
- (TimeDuration fromString:'1.5hr') - (TimeDuration fromString:'1hr')
+ Timestamp now - 3600. -> 2018-05-09 15:37:57.485
+ Timestamp now - 3600 seconds. -> 2018-05-09 15:38:04.665
+ (Timestamp now addSeconds:10) - Timestamp now -> 10s
+
+ Time now - 3600. -> 03:38:23 PM
+ Time now - 3600 seconds. -> 03:38:35 PM
+ (Time now addSeconds:10) - Time now -> 10s
+
+ (TimeDuration fromString:'1.5hr') - 3600. -> 30m
+ (TimeDuration fromString:'1.5hr') - (TimeDuration fromString:'1hr') -> 30m
|t1 t2|
@@ -1214,12 +1247,18 @@
%(milli) milliseconds unpadded - alias for %I for convenience
%(milli1) milliseconds, truncated to 1/10th of a second 0..9
%(milli2) milliseconds, truncated to 1/100th of a second 00..99 0-padded to length 2
- %(milli3) milliseconds, same as %i for convenience
+ %(milli3) milliseconds, padded to 3 (same as %i for convenience)
%(micro) microseconds unpadded - alias for %J for convenience
- %(micro6) microseconds, same as %j for convenience
+ %(micro6) microseconds, padded to 6 (same as %j for convenience)
+
+ %(nano) nanoseconds unpadded
+ %(nano9) nanoseconds, padded to 9
- %(fract) fraction part - alias for %F for convenience
+ %(pico) picoseconds unpadded
+ %(pico12) picoseconds, padded to 12
+
+ %(fract) fraction part - as many as needed alias for %F for convenience
Timestamp only:
%(Day) - day - unpadded
@@ -1281,7 +1320,7 @@
"
- |time hours minutes seconds millis micros picos
+ |time hours minutes seconds millis micros nanos picos
millisZ3 picosZ9 fract012 fract s t|
time := self asTime.
@@ -1290,6 +1329,7 @@
seconds := time seconds.
millis := self milliseconds.
micros := self microseconds.
+ nanos := self nanoseconds.
picos := self picoseconds.
aDictionary at:$H put:(s := hours printString).
@@ -1314,6 +1354,12 @@
aDictionary at:$j put:(t := s leftPaddedTo:6 with:$0).
aDictionary at:#micro6 put:t.
+ aDictionary at:#nano put:(s := nanos printString).
+ aDictionary at:#nano9 put:(s leftPaddedTo:9 with:$0).
+
+ aDictionary at:#pico put:(s := picos printString).
+ aDictionary at:#pico12 put:(s leftPaddedTo:12 with:$0).
+
picosZ9 := self picoseconds printString leftPaddedTo:9 with:$0.
fract012 := millisZ3,picosZ9.
fract := fract012 copyTo:(fract012 findLast:[:ch | ch ~~ $0] ifNone:12).