aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/time/instant.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/time/instant.lux128
1 files changed, 64 insertions, 64 deletions
diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux
index 83b415024..2429d0bee 100644
--- a/stdlib/source/lux/time/instant.lux
+++ b/stdlib/source/lux/time/instant.lux
@@ -32,11 +32,11 @@
(def: #export (span from to)
(-> Instant Instant duration;Duration)
- (duration;from-millis (i.- (@repr from) (@repr to))))
+ (duration;from-millis (i/- (@repr from) (@repr to))))
(def: #export (shift duration instant)
(-> duration;Duration Instant Instant)
- (@opaque (i.+ (duration;to-millis duration) (@repr instant))))
+ (@opaque (i/+ (duration;to-millis duration) (@repr instant))))
(def: #export (relative instant)
(-> Instant duration;Duration)
@@ -77,7 +77,7 @@
## Codec::encode
(def: (divisible? factor input)
(-> Int Int Bool)
- (|> input (i.% factor) (i.= 0)))
+ (|> input (i/% factor) (i/= 0)))
(def: (leap-year? year)
(-> Int Bool)
@@ -94,11 +94,11 @@
(let [year (if (leap-year? reference)
duration;leap-year
duration;normal-year)]
- (if (i.= 0 (duration;query year time-left))
+ (if (i/= 0 (duration;query year time-left))
[reference time-left]
(if (duration/>= duration;empty time-left)
- (recur (i.inc reference) (duration;merge (duration;scale -1 year) time-left))
- (recur (i.dec reference) (duration;merge year time-left)))
+ (recur (i/inc reference) (duration;merge (duration;scale -1 year) time-left))
+ (recur (i/dec reference) (duration;merge year time-left)))
))))
(def: normal-months
@@ -110,29 +110,29 @@
(def: leap-year-months
(Sequence Nat)
- (sequence;update [+1] n.inc normal-months))
+ (sequence;update [+1] n/inc normal-months))
(def: (find-month months time)
(-> (Sequence Nat) duration;Duration [Nat duration;Duration])
(if (duration/>= duration;empty time)
(sequence/fold (function [month-days [current-month time-left]]
(let [month-duration (duration;scale (nat-to-int month-days) duration;day)]
- (if (i.= 0 (duration;query month-duration time-left))
+ (if (i/= 0 (duration;query month-duration time-left))
[current-month time-left]
- [(n.inc current-month) (duration;merge (duration;scale -1 month-duration) time-left)])))
+ [(n/inc current-month) (duration;merge (duration;scale -1 month-duration) time-left)])))
[+0 time]
months)
(sequence/fold (function [month-days [current-month time-left]]
(let [month-duration (duration;scale (nat-to-int month-days) duration;day)]
- (if (i.= 0 (duration;query month-duration time-left))
+ (if (i/= 0 (duration;query month-duration time-left))
[current-month time-left]
- [(n.dec current-month) (duration;merge month-duration time-left)])))
+ [(n/dec current-month) (duration;merge month-duration time-left)])))
[+11 time]
(sequence;reverse months))))
(def: (pad value)
(-> Int Text)
- (if (i.< 10 value)
+ (if (i/< 10 value)
(text/compose "0" (int/encode value))
(int/encode value)))
@@ -144,10 +144,10 @@
(def: (encode-millis millis)
(-> Int Text)
- (cond (i.= 0 millis) ""
- (i.< 10 millis) ($_ text/compose ".00" (int/encode millis))
- (i.< 100 millis) ($_ text/compose ".0" (int/encode millis))
- ## (i.< 1_000 millis)
+ (cond (i/= 0 millis) ""
+ (i/< 10 millis) ($_ text/compose ".00" (int/encode millis))
+ (i/< 100 millis) ($_ text/compose ".0" (int/encode millis))
+ ## (i/< 1_000 millis)
($_ text/compose "." (int/encode millis))))
(def: seconds-per-day Int (duration;query duration;second duration;day))
@@ -157,36 +157,36 @@
(-> Instant [[Int Int Int] duration;Duration])
(let [offset (relative instant)
seconds (duration;query duration;second offset)
- z (|> seconds (i./ seconds-per-day) (i.+ days-up-to-epoch))
- era (i./ 146097
- (if (i.>= 0 z)
+ z (|> seconds (i// seconds-per-day) (i/+ days-up-to-epoch))
+ era (i// 146097
+ (if (i/>= 0 z)
z
- (i.- 146096 z)))
- days-of-era (|> z (i.- (i.* 146097 era)))
+ (i/- 146096 z)))
+ days-of-era (|> z (i/- (i/* 146097 era)))
years-of-era (|> days-of-era
- (i.- (i./ 1460 days-of-era))
- (i.+ (i./ 36524 days-of-era))
- (i.- (i./ 146096 days-of-era))
- (i./ 365))
- year (|> years-of-era (i.+ (i.* 400 era)))
+ (i/- (i// 1460 days-of-era))
+ (i/+ (i// 36524 days-of-era))
+ (i/- (i// 146096 days-of-era))
+ (i// 365))
+ year (|> years-of-era (i/+ (i/* 400 era)))
days-of-year (|> days-of-era
- (i.- (|> (i.* 365 years-of-era)
- (i.+ (i./ 4 years-of-era))
- (i.- (i./ 100 years-of-era)))))
+ (i/- (|> (i/* 365 years-of-era)
+ (i/+ (i// 4 years-of-era))
+ (i/- (i// 100 years-of-era)))))
day-time (duration;frame duration;day offset)
days-of-year (if (duration/>= duration;empty day-time)
days-of-year
- (i.dec days-of-year))
- mp (|> days-of-year (i.* 5) (i.+ 2) (i./ 153))
+ (i/dec days-of-year))
+ mp (|> days-of-year (i/* 5) (i/+ 2) (i// 153))
day (|> days-of-year
- (i.- (|> mp (i.* 153) (i.+ 2) (i./ 5)))
- (i.+ 1))
+ (i/- (|> mp (i/* 153) (i/+ 2) (i// 5)))
+ (i/+ 1))
month (|> mp
- (i.+ (if (i.< 10 mp)
+ (i/+ (if (i/< 10 mp)
3
-9)))
- year (if (i.<= 2 month)
- (i.inc year)
+ year (if (i/<= 2 month)
+ (i/inc year)
year)]
[[year month day]
day-time]))
@@ -219,7 +219,7 @@
#let [signum (case sign?
#;None 1
(#;Some _) -1)]]
- (wrap (i.* signum raw-year))))
+ (wrap (i/* signum raw-year))))
(def: lex-section
(l;Lexer Int)
@@ -234,9 +234,9 @@
(def: (leap-years year)
(-> Int Int)
- (|> (i./ 4 year)
- (i.- (i./ 100 year))
- (i.+ (i./ 400 year))))
+ (|> (i// 4 year)
+ (i/- (i// 100 year))
+ (i/+ (i// 400 year))))
## Based on: https://stackoverflow.com/a/3309340/6823464
(def: lex-instant
@@ -246,48 +246,48 @@
_ (l;this "-")
utc-month lex-section
_ (p;assert "Invalid month."
- (and (i.>= 1 utc-month)
- (i.<= 12 utc-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
- (sequence;nth (int-to-nat (i.dec utc-month)))
+ (sequence;nth (int-to-nat (i/dec utc-month)))
maybe;assume)]
_ (l;this "-")
utc-day lex-section
_ (p;assert "Invalid day."
- (and (i.>= 1 utc-day)
- (i.<= (nat-to-int month-days) utc-day)))
+ (and (i/>= 1 utc-day)
+ (i/<= (nat-to-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)))
+ (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)))
+ (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)))
+ (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 (i.dec utc-year)))
- year-days-so-far (|> (i.* 365 years-since-epoch)
- (i.+ previous-leap-days))
+ #let [years-since-epoch (i/- epoch-year utc-year)
+ previous-leap-days (i/- (leap-years epoch-year)
+ (leap-years (i/dec utc-year)))
+ year-days-so-far (|> (i/* 365 years-since-epoch)
+ (i/+ previous-leap-days))
month-days-so-far (|> months
sequence;to-list
- (list;take (int-to-nat (i.dec utc-month)))
- (L/fold n.+ +0))
+ (list;take (int-to-nat (i/dec utc-month)))
+ (L/fold n/+ +0))
total-days (|> year-days-so-far
- (i.+ (nat-to-int month-days-so-far))
- (i.+ (i.dec utc-day)))]]
+ (i/+ (nat-to-int month-days-so-far))
+ (i/+ (i/dec utc-day)))]]
(wrap (|> epoch
(shift (duration;scale total-days duration;day))
(shift (duration;scale utc-hour duration;hour))
@@ -315,7 +315,7 @@
(-> Instant date;Date)
(let [[[year month day] _] (extract-date instant)]
{#date;year year
- #date;month (case (i.dec month)
+ #date;month (case (i/dec month)
0 #date;January
1 #date;February
2 #date;March
@@ -343,14 +343,14 @@
day-time (duration;frame duration;day offset)
days (if (and (duration;negative? offset)
(not (duration;neutral? day-time)))
- (i.dec days)
+ (i/dec days)
days)
## 1970/01/01 was a Thursday
y1970m0d0 4]
(case (|> y1970m0d0
- (i.+ days) (i.% 7)
+ (i/+ days) (i/% 7)
## This is done to turn negative days into positive days.
- (i.+ 7) (i.% 7))
+ (i/+ 7) (i/% 7))
0 #date;Sunday
1 #date;Monday
2 #date;Tuesday