diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/time/instant.lux | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux index 70890ce4b..08029405a 100644 --- a/stdlib/source/lux/time/instant.lux +++ b/stdlib/source/lux/time/instant.lux @@ -102,7 +102,7 @@ (if (i/= +0 (duration.query year time-left)) [reference time-left] (if (duration/>= duration.empty time-left) - (recur (inc reference) (duration.merge (duration.scale-up -1 year) time-left)) + (recur (inc reference) (duration.merge (duration.inverse year) time-left)) (recur (dec reference) (duration.merge year time-left))) )))) @@ -121,14 +121,14 @@ (-> (Row Nat) duration.Duration [Nat duration.Duration]) (if (duration/>= duration.empty time) (row/fold (function (_ month-days [current-month time-left]) - (let [month-duration (duration.scale-up (.int month-days) duration.day)] + (let [month-duration (duration.scale-up month-days duration.day)] (if (i/= +0 (duration.query month-duration time-left)) [current-month time-left] - [(inc current-month) (duration.merge (duration.scale-up -1 month-duration) time-left)]))) + [(inc current-month) (duration.merge (duration.inverse month-duration) time-left)]))) [0 time] months) (row/fold (function (_ month-days [current-month time-left]) - (let [month-duration (duration.scale-up (.int month-days) duration.day)] + (let [month-duration (duration.scale-up month-days duration.day)] (if (i/= +0 (duration.query month-duration time-left)) [current-month time-left] [(dec current-month) (duration.merge month-duration time-left)]))) @@ -243,65 +243,65 @@ (i/+ (i// +400 year)))) ## Based on: https://stackoverflow.com/a/3309340/6823464 -(def: lex-instant - (l.Lexer Instant) - (do p.Monad<Parser> - [utc-year lex-year - _ (l.this "-") - utc-month lex-section - _ (p.assert "Invalid month." - (and (i/>= +1 utc-month) - (i/<= +12 utc-month))) - #let [months (if (leap-year? utc-year) - leap-year-months - normal-months) - month-days (|> months - (row.nth (.nat (dec utc-month))) - maybe.assume)] - _ (l.this "-") - utc-day lex-section - _ (p.assert "Invalid day." - (and (i/>= +1 utc-day) - (i/<= (.int month-days) utc-day))) - _ (l.this "T") - utc-hour lex-section - _ (p.assert "Invalid hour." - (and (i/>= +0 utc-hour) - (i/<= +23 utc-hour))) - _ (l.this ":") - utc-minute lex-section - _ (p.assert "Invalid minute." - (and (i/>= +0 utc-minute) - (i/<= +59 utc-minute))) - _ (l.this ":") - utc-second lex-section - _ (p.assert "Invalid second." - (and (i/>= +0 utc-second) - (i/<= +59 utc-second))) - utc-millis lex-millis - _ (l.this "Z") - #let [years-since-epoch (i/- epoch-year utc-year) - previous-leap-days (i/- (leap-years epoch-year) - (leap-years (dec utc-year))) - year-days-so-far (|> (i/* +365 years-since-epoch) - (i/+ previous-leap-days)) - month-days-so-far (|> months - row.to-list - (list.take (.nat (dec utc-month))) - (list/fold n/+ 0)) - total-days (|> year-days-so-far - (i/+ (.int month-days-so-far)) - (i/+ (dec utc-day)))]] - (wrap (|> epoch - (shift (duration.scale-up total-days duration.day)) - (shift (duration.scale-up utc-hour duration.hour)) - (shift (duration.scale-up utc-minute duration.minute)) - (shift (duration.scale-up utc-second duration.second)) - (shift (duration.scale-up utc-millis duration.milli)))))) - -(def: (decode input) - (-> Text (e.Error Instant)) - (l.run input lex-instant)) +## (def: lex-instant +## (l.Lexer Instant) +## (do p.Monad<Parser> +## [utc-year lex-year +## _ (l.this "-") +## utc-month lex-section +## _ (p.assert "Invalid month." +## (and (i/>= +1 utc-month) +## (i/<= +12 utc-month))) +## #let [months (if (leap-year? utc-year) +## leap-year-months +## normal-months) +## month-days (|> months +## (row.nth (.nat (dec utc-month))) +## maybe.assume)] +## _ (l.this "-") +## utc-day lex-section +## _ (p.assert "Invalid day." +## (and (i/>= +1 utc-day) +## (i/<= (.int month-days) utc-day))) +## _ (l.this "T") +## utc-hour lex-section +## _ (p.assert "Invalid hour." +## (and (i/>= +0 utc-hour) +## (i/<= +23 utc-hour))) +## _ (l.this ":") +## utc-minute lex-section +## _ (p.assert "Invalid minute." +## (and (i/>= +0 utc-minute) +## (i/<= +59 utc-minute))) +## _ (l.this ":") +## utc-second lex-section +## _ (p.assert "Invalid second." +## (and (i/>= +0 utc-second) +## (i/<= +59 utc-second))) +## utc-millis lex-millis +## _ (l.this "Z") +## #let [years-since-epoch (i/- epoch-year utc-year) +## previous-leap-days (i/- (leap-years epoch-year) +## (leap-years (dec utc-year))) +## year-days-so-far (|> (i/* +365 years-since-epoch) +## (i/+ previous-leap-days)) +## month-days-so-far (|> months +## row.to-list +## (list.take (.nat (dec utc-month))) +## (list/fold n/+ 0)) +## total-days (|> year-days-so-far +## (i/+ (.int month-days-so-far)) +## (i/+ (dec utc-day)))]] +## (wrap (|> epoch +## (shift (duration.scale-up total-days duration.day)) +## (shift (duration.scale-up utc-hour duration.hour)) +## (shift (duration.scale-up utc-minute duration.minute)) +## (shift (duration.scale-up utc-second duration.second)) +## (shift (duration.scale-up utc-millis duration.milli)))))) + +## (def: (decode input) +## (-> Text (e.Error Instant)) +## (l.run input lex-instant)) ## (structure: #export _ ## {#.doc (doc "Based on ISO 8601." |