diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/time.lux | 130 |
1 files changed, 64 insertions, 66 deletions
diff --git a/stdlib/source/library/lux/time.lux b/stdlib/source/library/lux/time.lux index 6e0c41380..1cb95dc1f 100644 --- a/stdlib/source/library/lux/time.lux +++ b/stdlib/source/library/lux/time.lux @@ -77,74 +77,72 @@ ) (abstract: .public Time - {} - Nat - (def: .public midnight - Time - (:abstraction 0)) - - (def: .public (of_millis milli_seconds) - (-> Nat (Try Time)) - (if (n.< ..limit milli_seconds) - (#try.Success (:abstraction milli_seconds)) - (exception.except ..time_exceeds_a_day [milli_seconds]))) - - (def: .public millis - (-> Time Nat) - (|>> :representation)) - - (implementation: .public equivalence - (Equivalence Time) - - (def: (= param subject) - (n.= (:representation param) (:representation subject)))) - - (implementation: .public order - (Order Time) - - (def: &equivalence ..equivalence) - - (def: (< param subject) - (n.< (:representation param) (:representation subject)))) - - (`` (implementation: .public enum - (Enum Time) - - (def: &order ..order) - - (def: succ - (|>> :representation ++ (n.% ..limit) :abstraction)) - - (def: pred - (|>> :representation - (case> 0 ..limit - millis millis) - -- - :abstraction)))) - - (def: .public parser - (Parser Time) - (let [millis (: (-> Duration Nat) - (|>> duration.millis .nat)) - hour (millis duration.hour) - minute (millis duration.minute) - second (millis duration.second) - millis (millis duration.milli_second)] - (do [! <>.monad] - [utc_hour ..hour_parser - _ (<text>.this ..separator) - utc_minute ..minute_parser - _ (<text>.this ..separator) - utc_second ..second_parser - utc_millis ..millis_parser] - (in (:abstraction - ($_ n.+ - (n.* utc_hour hour) - (n.* utc_minute minute) - (n.* utc_second second) - (n.* utc_millis millis))))))) + [(def: .public midnight + Time + (:abstraction 0)) + + (def: .public (of_millis milli_seconds) + (-> Nat (Try Time)) + (if (n.< ..limit milli_seconds) + (#try.Success (:abstraction milli_seconds)) + (exception.except ..time_exceeds_a_day [milli_seconds]))) + + (def: .public millis + (-> Time Nat) + (|>> :representation)) + + (implementation: .public equivalence + (Equivalence Time) + + (def: (= param subject) + (n.= (:representation param) (:representation subject)))) + + (implementation: .public order + (Order Time) + + (def: &equivalence ..equivalence) + + (def: (< param subject) + (n.< (:representation param) (:representation subject)))) + + (`` (implementation: .public enum + (Enum Time) + + (def: &order ..order) + + (def: succ + (|>> :representation ++ (n.% ..limit) :abstraction)) + + (def: pred + (|>> :representation + (case> 0 ..limit + millis millis) + -- + :abstraction)))) + + (def: .public parser + (Parser Time) + (let [millis (: (-> Duration Nat) + (|>> duration.millis .nat)) + hour (millis duration.hour) + minute (millis duration.minute) + second (millis duration.second) + millis (millis duration.milli_second)] + (do [! <>.monad] + [utc_hour ..hour_parser + _ (<text>.this ..separator) + utc_minute ..minute_parser + _ (<text>.this ..separator) + utc_second ..second_parser + utc_millis ..millis_parser] + (in (:abstraction + ($_ n.+ + (n.* utc_hour hour) + (n.* utc_minute minute) + (n.* utc_second second) + (n.* utc_millis millis)))))))] ) (def: (padded value) |