From f4e392f9105454525425b9a75a6733f769880b09 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Sat, 17 Jul 2021 09:45:39 -0500 Subject: [PATCH] Update for Nim 1.3.1 Change `startOfDay` and `trimNanoSec` to use `initDateTime` instead of mutating the new copy via the deprecated property accessors. Updated the test suite to reflect functions that moved from this library to the standard library. We're still testing the expected functionality to make sure that the contract is maintained for users of this library. --- tests/ttimeutils.nim | 20 ++++++++++---------- timeutils.nim | 21 +++++++++++++++------ timeutils.nimble | 4 ++-- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/tests/ttimeutils.nim b/tests/ttimeutils.nim index c1af792..037c367 100644 --- a/tests/ttimeutils.nim +++ b/tests/ttimeutils.nim @@ -14,27 +14,27 @@ suite "timeutils": test "DateTime difference": var t1 = getTime().local var t2 = t1 + 30.seconds - check timeutils.`-`(t2, t1) == initDuration(seconds = 30) + check t2 - t1 == initDuration(seconds = 30) 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") - check timeutils.`-`(t2, t1) == initDuration(seconds = 24 * 60 * 60) + check t2 - t1 == initDuration(seconds = 24 * 60 * 60) t2 = parse("2016-10-11 10:00:00", "yyyy-MM-dd HH:mm:ss") - check timeutils.`-`(t2, t1) == initDuration(seconds = (24 * 60 + 15) * 60) + check t2 - t1 == initDuration(seconds = (24 * 60 + 15) * 60) test "DateTime comparisons": let t1 = getTime().local check: - timeutils.`<`(t1, t1 + 10.seconds) - not timeutils.`<`(t1 + 10.seconds, t1) - not timeutils.`<`(t1, t1) + not (t1 < t1) + t1 < t1 + 10.seconds + not (t1 + 10.seconds < t1) + + t1 <= t1 + t1 <= t1 + 10.seconds + not (t1 + 10.seconds <= t1) - timeutils.`<=`(t1, t1 + 10.seconds) - timeutils.`<=`(t1, t1) - not timeutils.`<=`(t1 + 10.seconds, t1) - t1.between(t1 - 10.seconds, t1 + 10.seconds) t1.between(t1, t1 + 10.seconds) # start is inclusive not t1.between(t1 - 10.seconds, t1) # end is exclusive diff --git a/timeutils.nim b/timeutils.nim index 9b37a7c..8442a16 100644 --- a/timeutils.nim +++ b/timeutils.nim @@ -33,15 +33,24 @@ proc cmp*(a, b: DateTime): int = else: return 1 proc startOfDay*(dt: DateTime): DateTime = - result = dt - result.hour = 0 - result.minute = 0 - result.second = 0 - result.nanosecond = 0 + result = initDateTime( + dt.monthday, + dt.month, + dt.year, + 0, 0, 0, 0, # hour, minute, second, nanosecond + dt.timezone) proc trimNanoSec*(dt: DateTime): DateTime = result = dt - result.nanosecond = 0 + result = initDateTime( + dt.monthday, + dt.month, + dt.year, + dt.hour, + dt.minute, + dt.second, + 0, + dt.timezone) proc startOfWeek*(ti: DateTime, startDay = dMon): DateTime = var diff = (ti.weekday.ord - startDay.ord) diff --git a/timeutils.nimble b/timeutils.nimble index 105ccba..de917e3 100644 --- a/timeutils.nimble +++ b/timeutils.nimble @@ -1,10 +1,10 @@ # Package -version = "0.5.2" +version = "0.5.3" author = "Jonathan Bernard" description = "Utility methods to fill in the lacking time support in Nim\'s stdlib." license = "BSD3" # Dependencies -requires "nim >= 1.0.0" +requires "nim >= 1.3.1"