From 169ac987af12c4989aef7499b65be749d928ffc0 Mon Sep 17 00:00:00 2001 From: Chloe Kudryavtsev Date: Fri, 2 Jun 2023 19:40:19 +0200 Subject: finalize api draft 1, add tests --- date/init.janet | 7 +++---- test/02-api.janet | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/02-api.janet diff --git a/date/init.janet b/date/init.janet index cd47c4f..858ef79 100644 --- a/date/init.janet +++ b/date/init.janet @@ -55,7 +55,7 @@ (:timegm! newtm)) # timegm! is slightly more efficient and we're discarding it (defn update-time* - `Variant of update-time that takes a dictionary.` + `Variant of update-time that takes a dictionary without normalizing it.` [time ds] (assert (dictionary? ds)) (update-time! time (fn [tm] @@ -73,8 +73,6 @@ it will be used as-is. Note that the resulting values need not be in any given range, as they will be normalized. - It will automatically re-determine if DST is applicable and give you back a - modified date/time object. If you need additional control over the underlying gmtime tm call, use `update-time*` or `update-time!`. @@ -94,4 +92,5 @@ :mday month-day :mon month :year year - :isdst :detect})) + # UTC only + :isdst false})) diff --git a/test/02-api.janet b/test/02-api.janet new file mode 100644 index 0000000..f759105 --- /dev/null +++ b/test/02-api.janet @@ -0,0 +1,14 @@ +(import ../date) + +(def now (date/time)) +(assert (date/time? now)) + +(def gmt (:gmtime now)) +(def loc (:localtime now)) +(assert (date/tm? gmt)) +(assert (date/tm? loc)) +(assert (= (:mktime loc) (:timegm gmt))) + +(def before (date/update-time* now {:sec -1 :min dec})) +(def after (date/update-time* now {:sec 61 :min inc})) +(assert (> after now before)) -- cgit v1.2.3