diff options
| -rw-r--r-- | test/01-native.janet | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/test/01-native.janet b/test/01-native.janet index 442a651..ac04364 100644 --- a/test/01-native.janet +++ b/test/01-native.janet @@ -1,17 +1,39 @@ (use date/native) -# you always start with this +(defn platform [& ps] (some (partial = (os/which)) ps)) + +# you generally start with this # `time` returns the time in UTC (def now (time)) -# if you want to modify the time, you should use localtime, like so -(def lt (:localtime now)) -(update lt :sec |(+ $ 2000)) -(update lt :year |(- $ 10)) +# you can convert a `time` object into a `tm` object which represents a date +# using :localtime or :gmtime, where gmtime interprets the time as UTC +(def loc (:localtime now)) + +# you can modify `tm` objects like an associative array +# this means that put, update, keys, values, etc all work +# let's make another `tm` object, but remove one second from it +(def loc* (:localtime now)) +(update loc* :sec dec) + +# if the second count was at 0, it would now be at -1, which is out of range +# that's not a problem though, you can actually already perform comparisons +(assert (< loc* loc)) + +# :localtime, :localtime!, :gmtime, :gmtime!, :mktime, and :mktime! +# all "renormalize" the object +# :mktime returns a `time` object +# :mktime! does that, and normalizes the `tm` object in place by mutating it +(assert (= (:mktime loc) now)) +(assert (< (:mktime loc*) now)) + +# :gmtime(!) is equivalent to (:gmtime (:mktime(!) tm)), ditto for localtime +(def loc* (:localtime! loc*)) +(assert (< loc* loc)) -(def gt (:gmtime now)) -(put gt :sec 13) +# macos has a bug in its libc that makes it misinterpret gmtime outputs +# as localtime under certain conditions, so the gmtime tests are skipped +# TODO: UTC tests +(unless (platform :macos)) -(pp now) -(pp lt) -(pp gt) +# TODO: building a UTC datetime |
