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.lux86
1 files changed, 43 insertions, 43 deletions
diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux
index 195d78e83..823db0687 100644
--- a/stdlib/source/lux/time/instant.lux
+++ b/stdlib/source/lux/time/instant.lux
@@ -33,29 +33,29 @@
{#.doc "Instant is defined as milliseconds since the epoch."}
- (def: #export from-millis
+ (def: #export from_millis
(-> Int Instant)
(|>> :abstraction))
- (def: #export to-millis
+ (def: #export to_millis
(-> Instant Int)
(|>> :representation))
(def: #export (span from to)
(-> Instant Instant Duration)
- (duration.from-millis (i.- (:representation from) (:representation to))))
+ (duration.from_millis (i.- (:representation from) (:representation to))))
(def: #export (shift duration instant)
(-> Duration Instant Instant)
- (:abstraction (i.+ (duration.to-millis duration) (:representation instant))))
+ (:abstraction (i.+ (duration.to_millis duration) (:representation instant))))
(def: #export (relative instant)
(-> Instant Duration)
- (|> instant :representation duration.from-millis))
+ (|> instant :representation duration.from_millis))
(def: #export (absolute offset)
(-> Duration Instant)
- (|> offset duration.to-millis :abstraction))
+ (|> offset duration.to_millis :abstraction))
(structure: #export equivalence
(Equivalence Instant)
@@ -85,59 +85,59 @@
(def: #export epoch
{#.doc "The instant corresponding to 1970-01-01T00:00:00Z"}
Instant
- (..from-millis +0))
+ (..from_millis +0))
-(def: millis-per-day
- (duration.query duration.milli-second duration.day))
+(def: millis_per_day
+ (duration.query duration.milli_second duration.day))
-(def: (split-date-time instant)
+(def: (split_date_time instant)
(-> Instant [Date Duration])
- (let [offset (..to-millis instant)
+ (let [offset (..to_millis instant)
bce? (i.< +0 offset)
- [days day-time] (if bce?
- (let [[days millis] (i./% ..millis-per-day offset)]
+ [days day_time] (if bce?
+ (let [[days millis] (i./% ..millis_per_day offset)]
(case millis
+0 [days millis]
- _ [(dec days) (i.+ ..millis-per-day millis)]))
- (i./% ..millis-per-day offset))]
- [(date.from-days days)
- (duration.from-millis day-time)]))
+ _ [(dec days) (i.+ ..millis_per_day millis)]))
+ (i./% ..millis_per_day offset))]
+ [(date.from_days days)
+ (duration.from_millis day_time)]))
(template [<value> <definition>]
[(def: <definition> Text <value>)]
- ["T" date-suffix]
- ["Z" time-suffix]
+ ["T" date_suffix]
+ ["Z" time_suffix]
)
-(def: (clock-time duration)
+(def: (clock_time duration)
(-> Duration Time)
(let [time (if (\ duration.order < duration.empty duration)
(duration.merge duration.day duration)
duration)]
- (|> time duration.to-millis .nat //.from-millis try.assume)))
+ (|> time duration.to_millis .nat //.from_millis try.assume)))
(def: (encode instant)
(-> Instant Text)
- (let [[date time] (..split-date-time instant)
- time (..clock-time time)]
+ (let [[date time] (..split_date_time instant)
+ time (..clock_time time)]
($_ text\compose
- (\ date.codec encode date) ..date-suffix
- (\ //.codec encode time) ..time-suffix)))
+ (\ date.codec encode date) ..date_suffix
+ (\ //.codec encode time) ..time_suffix)))
(def: parser
(Parser Instant)
(do {! <>.monad}
[days (\ ! map date.days date.parser)
- _ (<t>.this ..date-suffix)
- time (\ ! map //.to-millis //.parser)
- _ (<t>.this ..time-suffix)]
+ _ (<t>.this ..date_suffix)
+ time (\ ! map //.to_millis //.parser)
+ _ (<t>.this ..time_suffix)]
(wrap (|> (if (i.< +0 days)
(|> duration.day
- (duration.scale-up (.nat (i.* -1 days)))
+ (duration.scale_up (.nat (i.* -1 days)))
duration.inverse)
- (duration.scale-up (.nat days) duration.day))
- (duration.merge (duration.scale-up time duration.milli-second))
+ (duration.scale_up (.nat days) duration.day))
+ (duration.merge (duration.scale_up time duration.milli_second))
..absolute))))
(structure: #export codec
@@ -150,25 +150,25 @@
(def: #export now
(IO Instant)
- (io (..from-millis ("lux io current-time"))))
+ (io (..from_millis ("lux io current-time"))))
-(template [<field> <type> <post-processing>]
+(template [<field> <type> <post_processing>]
[(def: #export (<field> instant)
(-> Instant <type>)
- (let [[date time] (..split-date-time instant)]
- (|> <field> <post-processing>)))]
+ (let [[date time] (..split_date_time instant)]
+ (|> <field> <post_processing>)))]
[date Date (|>)]
- [time Time ..clock-time]
+ [time Time ..clock_time]
)
-(def: #export (day-of-week instant)
+(def: #export (day_of_week instant)
(-> Instant Day)
(let [offset (..relative instant)
days (duration.query duration.day offset)
- day-time (duration.frame duration.day offset)
+ day_time (duration.frame duration.day offset)
days (if (and (duration.negative? offset)
- (not (duration.neutral? day-time)))
+ (not (duration.neutral? day_time)))
(dec days)
days)
## 1970/01/01 was a Thursday
@@ -186,8 +186,8 @@
+6 #day.Saturday
_ (undefined))))
-(def: #export (from-date-time date time)
+(def: #export (from_date_time date time)
(-> Date Time Instant)
- (..from-millis
- (i.+ (i.* (date.days date) (duration.to-millis duration.day))
- (.int (//.to-millis time)))))
+ (..from_millis
+ (i.+ (i.* (date.days date) (duration.to_millis duration.day))
+ (.int (//.to_millis time)))))