aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/artifact/time_stamp
diff options
context:
space:
mode:
authorEduardo Julian2021-01-03 07:48:12 -0400
committerEduardo Julian2021-01-03 07:48:12 -0400
commitc03bd9f9787fb9f383c57b4ebb0fa9d49abbfaa1 (patch)
tree68a7f2f043eff00492ffe2b5e442bae98167a873 /stdlib/source/program/aedifex/artifact/time_stamp
parent02d27daeacac74785c2b0f4d1ce03d432377a36e (diff)
Place the "program:" macro of "lux/control/parser/cli" in its own module.
Diffstat (limited to '')
-rw-r--r--stdlib/source/program/aedifex/artifact/time_stamp.lux35
-rw-r--r--stdlib/source/program/aedifex/artifact/time_stamp/date.lux39
-rw-r--r--stdlib/source/program/aedifex/artifact/time_stamp/time.lux35
3 files changed, 109 insertions, 0 deletions
diff --git a/stdlib/source/program/aedifex/artifact/time_stamp.lux b/stdlib/source/program/aedifex/artifact/time_stamp.lux
new file mode 100644
index 000000000..0eab45a14
--- /dev/null
+++ b/stdlib/source/program/aedifex/artifact/time_stamp.lux
@@ -0,0 +1,35 @@
+(.module:
+ [lux #*
+ [abstract
+ [monad (#+ do)]]
+ [control
+ ["<>" parser
+ ["<.>" text (#+ Parser)]]]
+ [data
+ [text
+ ["%" format]]]
+ [time
+ ["." instant (#+ Instant)]]]
+ ["." / #_
+ ["#." date]
+ ["#." time]])
+
+(type: #export Time_Stamp
+ Instant)
+
+(def: #export separator
+ ".")
+
+(def: #export (format value)
+ (%.Format Time_Stamp)
+ (%.format (/date.format (instant.date value))
+ ..separator
+ (/time.format (instant.time value))))
+
+(def: #export parser
+ (Parser Time_Stamp)
+ (do <>.monad
+ [date /date.parser
+ _ (<text>.this ..separator)
+ time /time.parser]
+ (wrap (instant.from_date_time date time))))
diff --git a/stdlib/source/program/aedifex/artifact/time_stamp/date.lux b/stdlib/source/program/aedifex/artifact/time_stamp/date.lux
new file mode 100644
index 000000000..18df2900b
--- /dev/null
+++ b/stdlib/source/program/aedifex/artifact/time_stamp/date.lux
@@ -0,0 +1,39 @@
+(.module:
+ [lux #*
+ [abstract
+ [monad (#+ do)]]
+ [control
+ ["<>" parser
+ ["<.>" text (#+ Parser)]]]
+ [data
+ [text
+ ["%" format]]]
+ [math
+ [number
+ ["n" nat]]]
+ [time
+ ["." date (#+ Date)]
+ ["." year]
+ ["." month]]])
+
+(def: #export (pad value)
+ (-> Nat Text)
+ (if (n.< 10 value)
+ (%.format "0" (%.nat value))
+ (%.nat value)))
+
+(def: #export (format value)
+ (%.Format Date)
+ (%.format (|> value date.year year.value .nat %.nat)
+ (|> value date.month month.number ..pad)
+ (|> value date.day_of_month ..pad)))
+
+(def: #export parser
+ (Parser Date)
+ (do <>.monad
+ [year (<>.codec n.decimal (<text>.exactly 4 <text>.decimal))
+ year (<>.lift (year.year (.int year)))
+ month (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))
+ month (<>.lift (month.by_number month))
+ day_of_month (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))]
+ (<>.lift (date.date year month day_of_month))))
diff --git a/stdlib/source/program/aedifex/artifact/time_stamp/time.lux b/stdlib/source/program/aedifex/artifact/time_stamp/time.lux
new file mode 100644
index 000000000..d14f0a435
--- /dev/null
+++ b/stdlib/source/program/aedifex/artifact/time_stamp/time.lux
@@ -0,0 +1,35 @@
+(.module:
+ [lux #*
+ ["." time (#+ Time)]
+ [abstract
+ [monad (#+ do)]]
+ [control
+ ["<>" parser
+ ["<.>" text (#+ Parser)]]]
+ [data
+ [text
+ ["%" format]]]
+ [math
+ [number
+ ["n" nat]]]]
+ ["." // #_
+ ["#" date]])
+
+(def: #export (format value)
+ (%.Format Time)
+ (let [(^slots [#time.hour #time.minute #time.second]) (time.clock value)]
+ (%.format (//.pad hour)
+ (//.pad minute)
+ (//.pad second))))
+
+(def: #export parser
+ (<text>.Parser Time)
+ (do <>.monad
+ [hour (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))
+ minute (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))
+ second (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))]
+ (<>.lift (time.time
+ {#time.hour hour
+ #time.minute minute
+ #time.second second
+ #time.milli_second 0}))))