Added comparison operators for TimeInfo and TimeInterval, cmp for TimeInfo.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
path = "."
|
||||
hints = off
|
||||
linedir = off
|
||||
linedir = on
|
||||
debuginfo
|
||||
stacktrace = on
|
||||
linetrace = on
|
||||
|
@ -3,6 +3,58 @@ import times, timeutils, unittest
|
||||
suite "timeutils":
|
||||
test "format TimeInterval":
|
||||
let interval = seconds(70)
|
||||
check interval.format("ss's'") == "10s"
|
||||
check interval.format("mm'm' ss's'") == "01m 10s"
|
||||
check interval.format("mm:ss") == "01:10"
|
||||
check:
|
||||
interval.format("ss's'") == "10s"
|
||||
interval.format("mm'm' ss's'") == "01m 10s"
|
||||
interval.format("mm:ss") == "01:10"
|
||||
|
||||
test "TimeInfo difference":
|
||||
let t1 = getLocalTime(getTime())
|
||||
let t2 = t1 + 30.seconds
|
||||
|
||||
check t2 - t1 == 30.seconds
|
||||
|
||||
test "TimeInfo comparisons":
|
||||
let t1 = getLocalTime(getTime())
|
||||
|
||||
check:
|
||||
t1 < t1 + 10.seconds
|
||||
not (t1 + 10.seconds < t1)
|
||||
not (t1 > t1)
|
||||
|
||||
t1 + 10.seconds > t1
|
||||
not (t1 > t1 + 10.seconds)
|
||||
not (t1 < t1)
|
||||
|
||||
t1 + 10.seconds >= t1
|
||||
t1 >= t1
|
||||
not (t1 >= t1 + 10.seconds)
|
||||
|
||||
t1 <= t1 + 10.seconds
|
||||
t1 <= t1
|
||||
not (t1 + 10.seconds <= t1)
|
||||
|
||||
test "TimeInterval comparisons":
|
||||
check:
|
||||
30.seconds > 10.seconds
|
||||
not (10.seconds > 30.seconds)
|
||||
not (10.seconds > 10.seconds)
|
||||
|
||||
10.minutes < 1.hours
|
||||
not (1.hours < 10.minutes)
|
||||
not (1.hours < 1.hours)
|
||||
|
||||
60.seconds >= 1.minutes
|
||||
60.seconds >= 1.minutes
|
||||
not (60.seconds >= 2.minutes)
|
||||
|
||||
60.seconds <= 1.minutes
|
||||
60.seconds <= 2.minutes
|
||||
not (2.minutes <= 60.seconds)
|
||||
|
||||
test "TimeInfo cmp":
|
||||
let t1 = getLocalTime(getTime())
|
||||
|
||||
check cmp(t1, t1) == 0
|
||||
check cmp(t1, t1 + 10.seconds) == -1
|
||||
check cmp(t1 + 10.seconds, t1) == 1
|
||||
|
Reference in New Issue
Block a user