From b86a223c911edf2580b46d9892f344531616695d Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 24 Jul 2017 20:04:59 -0400 Subject: - Refactored Time into Instant and Duration. --- stdlib/source/lux/test.lux | 16 +- stdlib/source/lux/time.lux | 297 ----------------------------------- stdlib/source/lux/time/duration.lux | 70 +++++++++ stdlib/source/lux/time/instant.lux | 304 ++++++++++++++++++++++++++++++++++++ 4 files changed, 382 insertions(+), 305 deletions(-) delete mode 100644 stdlib/source/lux/time.lux create mode 100644 stdlib/source/lux/time/duration.lux create mode 100644 stdlib/source/lux/time/instant.lux (limited to 'stdlib/source') diff --git a/stdlib/source/lux/test.lux b/stdlib/source/lux/test.lux index eabfe9811..5d95e2f6b 100644 --- a/stdlib/source/lux/test.lux +++ b/stdlib/source/lux/test.lux @@ -14,13 +14,11 @@ text/format ["E" result]) [io #- run] + (time [instant] + [duration]) ["R" math/random])) ## [Host] -(def: now - (IO Int) - (io (_lux_proc ["io" "current-time"] []))) - (do-template [ ] [(def: #hidden (IO Bottom) (io (_lux_proc ["io" "exit"] [])))] @@ -63,10 +61,12 @@ (L/map (: (-> [Text (IO Test) Text] (Promise Counters)) (function [[module test description]] (do @ - [#let [pre (io;run now)] + [#let [pre (io;run instant;now)] [counters documentation] (io;run test) - #let [post (io;run now) - _ (log! (format "@ " module " (" (%i (i.- pre post)) "ms" ") " "\n" + #let [post (io;run instant;now) + _ (log! (format "@ " module " " + "(" (%i (duration;to-millis (instant;span pre post))) "ms" ")" + "\n" description "\n" "\n" documentation "\n"))]] (wrap counters))))) @@ -112,7 +112,7 @@ (def: #hidden (repeat ?seed times random-test) (-> (Maybe Nat) Nat (R;Random Test) Test) - (repeat' (default (int-to-nat (io;run now)) + (repeat' (default (|> (io;run instant;now) instant;to-millis int-to-nat) ?seed) (case ?seed #;None times diff --git a/stdlib/source/lux/time.lux b/stdlib/source/lux/time.lux deleted file mode 100644 index d910287f7..000000000 --- a/stdlib/source/lux/time.lux +++ /dev/null @@ -1,297 +0,0 @@ -(;module: - lux - (lux (control enum - eq - order - codec - [monad #+ do Monad] - ["p" parser]) - (data [text "text/" Monoid] - (text ["l" lexer] - format) - [number] - ["R" result] - (coll [list "L/" Fold Functor] - ["v" vector "v/" Functor Fold])))) - -(type: #export Time - {#;doc "Time is defined as milliseconds since the epoch."} - Int) - -(def: #export epoch - {#;doc "The time corresponding to 1970-01-01T00:00:00Z"} - Time - 0) - -(def: #export second Time 1_000) -(def: #export minute Time (i.* 60 second)) -(def: #export hour Time (i.* 60 minute)) -(def: #export day Time (i.* 24 hour)) -(def: #export week Time (i.* 7 day)) -(def: #export normal-year Time (i.* 365 day)) -(def: #export leap-year Time (i.+ day normal-year)) - -(do-template [ ] - [(def: #export ( param subject) - (-> Time Time ) - ( param subject))] - - [t.+ i.+ Time] - [t.- i.- Time] - [t.= i.= Bool] - [t.< i.< Bool] - [t.<= i.<= Bool] - [t.> i.> Bool] - [t.>= i.>= Bool] - ) - -(struct: #export _ (Eq Time) - (def: = t.=)) - -(struct: #export _ (Order Time) - (def: eq Eq