From 41f2e0c5dc17e939a73686ea3f54a251b6362141 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 23 Jul 2017 01:27:35 -0400 Subject: - Added module for time (Codec has currently been tested only for time after epoch). --- stdlib/source/lux/time.lux | 295 ++++++++++++++++++++++++++++++++++++++++++ stdlib/test/test/lux/time.lux | 86 ++++++++++++ stdlib/test/tests.lux | 1 + 3 files changed, 382 insertions(+) create mode 100644 stdlib/source/lux/time.lux create mode 100644 stdlib/test/test/lux/time.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/time.lux b/stdlib/source/lux/time.lux new file mode 100644 index 000000000..89c01b0ea --- /dev/null +++ b/stdlib/source/lux/time.lux @@ -0,0 +1,295 @@ +(;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