From 8987a4e2689b48ef746625c5c190def0a80e9205 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 2 Apr 2018 14:24:40 -0500 Subject: [PATCH] Changes to support Nim 0.18 (with new times implementation). --- {test => tests}/nim.cfg | 0 {test => tests}/ttimeutils.nim | 13 +++++++------ timeutils.nim | 13 ++++++++----- timeutils.nimble | 4 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) rename {test => tests}/nim.cfg (100%) rename {test => tests}/ttimeutils.nim (93%) diff --git a/test/nim.cfg b/tests/nim.cfg similarity index 100% rename from test/nim.cfg rename to tests/nim.cfg diff --git a/test/ttimeutils.nim b/tests/ttimeutils.nim similarity index 93% rename from test/ttimeutils.nim rename to tests/ttimeutils.nim index 29ebdd0..7448f25 100644 --- a/test/ttimeutils.nim +++ b/tests/ttimeutils.nim @@ -1,4 +1,5 @@ -import times, timeutils, unittest +import times, unittest +import "../timeutils" let dtFormat = "yyyy-MM-dd HH:mm:ss" @@ -10,19 +11,19 @@ suite "timeutils": interval.format("mm'm' ss's'") == "01m 10s" interval.format("mm:ss") == "01:10" - test "TimeInfo difference": + test "DateTime difference": var t1 = getLocalTime(getTime()) var t2 = t1 + 30.seconds check t2 - t1 == 30.seconds 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 t2 - t1 == 1.days + check t2 - t1 == seconds(24 * 60 * 60) t2 = parse("2016-10-11 10:00:00", "yyyy-MM-dd HH:mm:ss") - check t2 - t1 == (1.days + 15.minutes) + check t2 - t1 == seconds((24 * 60 + 15) * 60) - test "TimeInfo comparisons": + test "DateTime comparisons": let t1 = getLocalTime(getTime()) check: @@ -60,7 +61,7 @@ suite "timeutils": 60.seconds <= 2.minutes not (2.minutes <= 60.seconds) - test "TimeInfo cmp": + test "DateTime cmp": let t1 = getLocalTime(getTime()) check cmp(t1, t1) == 0 diff --git a/timeutils.nim b/timeutils.nim index 4fd1cd1..64ff97e 100644 --- a/timeutils.nim +++ b/timeutils.nim @@ -6,9 +6,11 @@ proc format*(ti: TimeInterval, fmt: string): string = let info = getGMTime(fromSeconds(0) + ti) return info.format(fmt) -proc `-`*(a, b: TimeInfo): TimeInterval = +proc `-`*(a, b: DateTime): TimeInterval = return seconds(cast[int](a.toTime - b.toTime)) +#[ +# Deprecated as it exists in the standard times module now. proc `>`*(a, b: TimeInfo): bool = return a.toTime > b.toTime @@ -20,6 +22,7 @@ proc `>=`*(a, b: TimeInfo): bool = proc `<=`*(a, b: TimeInfo): bool = return a.toTime <= b.toTime +]# proc `>`*(a, b: TimeInterval): bool = return (zeroTime + a) > (zeroTime + b) @@ -33,18 +36,18 @@ proc `>=`*(a, b: TimeInterval): bool = proc `<=`*(a, b: TimeInterval): bool = return (zeroTime + a) <= (zeroTime + b) -proc cmp*(a, b: TimeInfo): int = +proc cmp*(a, b: DateTime): int = if b == a: return 0 elif a > b: return 1 else: return -1 -proc startOfDay*(ti: TimeInfo): TimeInfo = +proc startOfDay*(ti: DateTime): DateTime = result = ti result.hour = 0 result.minute = 0 result.second = 0 -proc startOfWeek*(ti: TimeInfo, startDay = dMon): TimeInfo = +proc startOfWeek*(ti: DateTime, startDay = dMon): DateTime = var diff = (ti.weekday.ord - startDay.ord) if diff < 0: diff += 7 return (ti - diff.days).startOfDay @@ -52,4 +55,4 @@ proc startOfWeek*(ti: TimeInfo, startDay = dMon): TimeInfo = # This is a workaround needed due a bug in Nim's times.parse procedure. # see: https://github.com/nim-lang/Nim/issues/4922 {.deprecated.} -template fixedParse*(value, format: string): TimeInfo = parse(value, format) +template fixedParse*(value, format: string): DateTime = parse(value, format) diff --git a/timeutils.nimble b/timeutils.nimble index ab64565..be741a6 100644 --- a/timeutils.nimble +++ b/timeutils.nimble @@ -1,11 +1,11 @@ # Package -version = "0.2.1" +version = "0.2.2" author = "Jonathan Bernard" description = "Utility methods to fill in the lacking time support in Nim\'s stdlib. This is holding me over until I can write a proper time module for the stdlib and submit it." license = "BSD3" # Dependencies -requires "nim >= 0.15.0" +requires "nim >= 0.18.1"