Compare commits

..

No commits in common. "main" and "0.5.2" have entirely different histories.
main ... 0.5.2

3 changed files with 18 additions and 28 deletions

View File

@ -14,26 +14,26 @@ suite "timeutils":
test "DateTime difference": test "DateTime difference":
var t1 = getTime().local var t1 = getTime().local
var t2 = t1 + 30.seconds var t2 = t1 + 30.seconds
check t2 - t1 == initDuration(seconds = 30) check timeutils.`-`(t2, t1) == initDuration(seconds = 30)
t1 = parse("2016-10-10 09:45:00", "yyyy-MM-dd HH:mm:ss") t1 = parse("2016-10-10 09:45:00", "yyyy-MM-dd HH:mm:ss")
t2 = parse("2016-10-11 09:45:00", "yyyy-MM-dd HH:mm:ss") t2 = parse("2016-10-11 09:45:00", "yyyy-MM-dd HH:mm:ss")
check t2 - t1 == initDuration(seconds = 24 * 60 * 60) check timeutils.`-`(t2, t1) == initDuration(seconds = 24 * 60 * 60)
t2 = parse("2016-10-11 10:00:00", "yyyy-MM-dd HH:mm:ss") t2 = parse("2016-10-11 10:00:00", "yyyy-MM-dd HH:mm:ss")
check t2 - t1 == initDuration(seconds = (24 * 60 + 15) * 60) check timeutils.`-`(t2, t1) == initDuration(seconds = (24 * 60 + 15) * 60)
test "DateTime comparisons": test "DateTime comparisons":
let t1 = getTime().local let t1 = getTime().local
check: check:
not (t1 < t1) timeutils.`<`(t1, t1 + 10.seconds)
t1 < t1 + 10.seconds not timeutils.`<`(t1 + 10.seconds, t1)
not (t1 + 10.seconds < t1) not timeutils.`<`(t1, t1)
t1 <= t1 timeutils.`<=`(t1, t1 + 10.seconds)
t1 <= t1 + 10.seconds timeutils.`<=`(t1, t1)
not (t1 + 10.seconds <= t1) not timeutils.`<=`(t1 + 10.seconds, t1)
t1.between(t1 - 10.seconds, t1 + 10.seconds) t1.between(t1 - 10.seconds, t1 + 10.seconds)
t1.between(t1, t1 + 10.seconds) # start is inclusive t1.between(t1, t1 + 10.seconds) # start is inclusive

View File

@ -2,7 +2,6 @@ import times
const zeroTime = fromUnix(0) const zeroTime = fromUnix(0)
const ISO_8601_FORMATS = @[ const ISO_8601_FORMATS = @[
"yyyy-MM-dd",
"yyyy-MM-dd'T'HH:mm:ssz", "yyyy-MM-dd'T'HH:mm:ssz",
"yyyy-MM-dd'T'HH:mm:sszzz", "yyyy-MM-dd'T'HH:mm:sszzz",
"yyyy-MM-dd'T'HH:mm:ss'.'fffzzz", "yyyy-MM-dd'T'HH:mm:ss'.'fffzzz",
@ -34,24 +33,15 @@ proc cmp*(a, b: DateTime): int =
else: return 1 else: return 1
proc startOfDay*(dt: DateTime): DateTime = proc startOfDay*(dt: DateTime): DateTime =
result = initDateTime( result = dt
dt.monthday, result.hour = 0
dt.month, result.minute = 0
dt.year, result.second = 0
0, 0, 0, 0, # hour, minute, second, nanosecond result.nanosecond = 0
dt.timezone)
proc trimNanoSec*(dt: DateTime): DateTime = proc trimNanoSec*(dt: DateTime): DateTime =
result = dt result = dt
result = initDateTime( result.nanosecond = 0
dt.monthday,
dt.month,
dt.year,
dt.hour,
dt.minute,
dt.second,
0,
dt.timezone)
proc startOfWeek*(ti: DateTime, startDay = dMon): DateTime = proc startOfWeek*(ti: DateTime, startDay = dMon): DateTime =
var diff = (ti.weekday.ord - startDay.ord) var diff = (ti.weekday.ord - startDay.ord)

View File

@ -1,10 +1,10 @@
# Package # Package
version = "0.5.4" version = "0.5.2"
author = "Jonathan Bernard" author = "Jonathan Bernard"
description = "Utility methods to fill in the lacking time support in Nim\'s stdlib." description = "Utility methods to fill in the lacking time support in Nim\'s stdlib."
license = "BSD3" license = "BSD3"
# Dependencies # Dependencies
requires "nim >= 1.3.1" requires "nim >= 1.0.0"