diff options
Diffstat (limited to 'stdlib/source/lux/time/instant.lux')
-rw-r--r-- | stdlib/source/lux/time/instant.lux | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux index bd378016a..ab7fe6953 100644 --- a/stdlib/source/lux/time/instant.lux +++ b/stdlib/source/lux/time/instant.lux @@ -14,7 +14,7 @@ [data ["." maybe] [number - ["n" nat] + ["n" nat ("#@." decimal)] ["i" int ("#@." decimal)]] ["." text ("#@." monoid)] [collection @@ -56,16 +56,22 @@ (-> Duration Instant) (|> offset duration.to-millis :abstraction)) - (structure: #export equivalence (Equivalence Instant) + (structure: #export equivalence + (Equivalence Instant) + (def: (= param subject) (:: i.equivalence = (:representation param) (:representation subject)))) - (structure: #export order (Order Instant) + (structure: #export order + (Order Instant) + (def: &equivalence ..equivalence) (def: (< param subject) (:: i.order < (:representation param) (:representation subject)))) - (`` (structure: #export enum (Enum Instant) + (`` (structure: #export enum + (Enum Instant) + (def: &order ..order) (~~ (template [<name>] [(def: <name> @@ -126,10 +132,10 @@ (row.reverse months)))) (def: (pad value) - (-> Int Text) - (if (i.< +10 value) - (text@compose "0" (i@encode value)) - (i@encode value))) + (-> Nat Text) + (if (n.< 10 value) + (text@compose "0" (n@encode value)) + (n@encode value))) (def: (adjust-negative space duration) (-> Duration Duration Duration) @@ -138,12 +144,12 @@ duration)) (def: (encode-millis millis) - (-> Int Text) - (cond (i.= +0 millis) "" - (i.< +10 millis) ($_ text@compose ".00" (i@encode millis)) - (i.< +100 millis) ($_ text@compose ".0" (i@encode millis)) - ## (i.< +1,000 millis) - ($_ text@compose "." (i@encode millis)))) + (-> Nat Text) + (cond (n.= 0 millis) "" + (n.< 10 millis) ($_ text@compose ".00" (n@encode millis)) + (n.< 100 millis) ($_ text@compose ".0" (n@encode millis)) + ## (n.< 1,000 millis) + ($_ text@compose "." (n@encode millis)))) (def: seconds-per-day Int (duration.query duration.second duration.day)) (def: days-up-to-epoch Int +719468) @@ -196,11 +202,12 @@ [hours day-time] [(duration.query duration.hour day-time) (duration.frame duration.hour day-time)] [minutes day-time] [(duration.query duration.minute day-time) (duration.frame duration.minute day-time)] [seconds millis] [(duration.query duration.second day-time) (duration.frame duration.second day-time)]] - ($_ text@compose (i@encode year) "-" (pad month) "-" (pad day) "T" - (pad hours) ":" (pad minutes) ":" (pad seconds) + ($_ text@compose (i@encode year) "-" (pad (.nat month)) "-" (pad (.nat day)) "T" + (pad (.nat hours)) ":" (pad (.nat minutes)) ":" (pad (.nat seconds)) (|> millis (adjust-negative duration.second) duration.to-millis + .nat encode-millis) "Z"))) |