diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/time/duration.lux | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 9c5d70d71..aa2aeda01 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -23,11 +23,11 @@ {#.doc "Durations have a resolution of milli-seconds."} - (def: #export from-millis + (def: #export from_millis (-> Int Duration) (|>> :abstraction)) - (def: #export to-millis + (def: #export to_millis (-> Duration Int) (|>> :representation)) @@ -45,8 +45,8 @@ (-> Nat Duration Duration) (|>> :representation (<op> (.int scalar)) :abstraction))] - [i.* scale-up] - [i./ scale-down] + [i.* scale_up] + [i./ scale_down] ) (def: #export inverse @@ -86,26 +86,26 @@ ) (def: #export empty - (..from-millis +0)) + (..from_millis +0)) -(def: #export milli-second - (..from-millis +1)) +(def: #export milli_second + (..from_millis +1)) (template [<name> <scale> <base>] [(def: #export <name> - (..scale-up <scale> <base>))] + (..scale_up <scale> <base>))] - [second 1,000 milli-second] + [second 1,000 milli_second] [minute 60 second] [hour 60 minute] [day 24 hour] [week 7 day] - [normal-year 365 day] + [normal_year 365 day] ) -(def: #export leap-year - (..merge ..day ..normal-year)) +(def: #export leap_year + (..merge ..day ..normal_year)) (structure: #export monoid (Monoid Duration) @@ -116,68 +116,68 @@ (template [<value> <definition>] [(def: <definition> <value>)] - ["D" day-suffix] - ["h" hour-suffix] - ["m" minute-suffix] - ["s" second-suffix] - ["ms" milli-second-suffix] + ["D" day_suffix] + ["h" hour_suffix] + ["m" minute_suffix] + ["s" second_suffix] + ["ms" milli_second_suffix] - ["+" positive-sign] - ["-" negative-sign] + ["+" positive_sign] + ["-" negative_sign] ) (def: (encode duration) (if (\ ..equivalence = ..empty duration) ($_ text\compose - ..positive-sign + ..positive_sign (nat\encode 0) - ..milli-second-suffix) + ..milli_second_suffix) (let [signed? (negative? duration) - [days time-left] [(query day duration) (frame day duration)] + [days time_left] [(query day duration) (frame day duration)] days (if signed? (i.abs days) days) - time-left (if signed? - (..inverse time-left) - time-left) - [hours time-left] [(query hour time-left) (frame hour time-left)] - [minutes time-left] [(query minute time-left) (frame minute time-left)] - [seconds time-left] [(query second time-left) (frame second time-left)] - millis (to-millis time-left)] + time_left (if signed? + (..inverse time_left) + time_left) + [hours time_left] [(query hour time_left) (frame hour time_left)] + [minutes time_left] [(query minute time_left) (frame minute time_left)] + [seconds time_left] [(query second time_left) (frame second time_left)] + millis (to_millis time_left)] ($_ text\compose - (if signed? ..negative-sign ..positive-sign) - (if (i.= +0 days) "" (text\compose (nat\encode (.nat days)) ..day-suffix)) - (if (i.= +0 hours) "" (text\compose (nat\encode (.nat hours)) ..hour-suffix)) - (if (i.= +0 minutes) "" (text\compose (nat\encode (.nat minutes)) ..minute-suffix)) - (if (i.= +0 seconds) "" (text\compose (nat\encode (.nat seconds)) ..second-suffix)) - (if (i.= +0 millis) "" (text\compose (nat\encode (.nat millis)) ..milli-second-suffix)) + (if signed? ..negative_sign ..positive_sign) + (if (i.= +0 days) "" (text\compose (nat\encode (.nat days)) ..day_suffix)) + (if (i.= +0 hours) "" (text\compose (nat\encode (.nat hours)) ..hour_suffix)) + (if (i.= +0 minutes) "" (text\compose (nat\encode (.nat minutes)) ..minute_suffix)) + (if (i.= +0 seconds) "" (text\compose (nat\encode (.nat seconds)) ..second_suffix)) + (if (i.= +0 millis) "" (text\compose (nat\encode (.nat millis)) ..milli_second_suffix)) )))) (def: parser (Parser Duration) (let [section (: (-> Text Text (Parser Nat)) - (function (_ suffix false-suffix) + (function (_ suffix false_suffix) (|> (<t>.many <t>.decimal) (<>.codec nat.decimal) - (<>.before (case false-suffix + (<>.before (case false_suffix "" (<t>.this suffix) - _ (<>.after (<>.not (<t>.this false-suffix)) + _ (<>.after (<>.not (<t>.this false_suffix)) (<t>.this suffix)))) (<>.default 0))))] (do <>.monad - [sign (<>.or (<t>.this ..negative-sign) - (<t>.this ..positive-sign)) - days (section ..day-suffix "") - hours (section hour-suffix "") - minutes (section ..minute-suffix ..milli-second-suffix) - seconds (section ..second-suffix "") - millis (section ..milli-second-suffix "") + [sign (<>.or (<t>.this ..negative_sign) + (<t>.this ..positive_sign)) + days (section ..day_suffix "") + hours (section hour_suffix "") + minutes (section ..minute_suffix ..milli_second_suffix) + seconds (section ..second_suffix "") + millis (section ..milli_second_suffix "") #let [span (|> ..empty - (..merge (..scale-up days ..day)) - (..merge (..scale-up hours ..hour)) - (..merge (..scale-up minutes ..minute)) - (..merge (..scale-up seconds ..second)) - (..merge (..scale-up millis ..milli-second)) + (..merge (..scale_up days ..day)) + (..merge (..scale_up hours ..hour)) + (..merge (..scale_up minutes ..minute)) + (..merge (..scale_up seconds ..second)) + (..merge (..scale_up millis ..milli_second)) )]] (wrap (case sign (#.Left _) (..inverse span) |