From c03bd9f9787fb9f383c57b4ebb0fa9d49abbfaa1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 3 Jan 2021 07:48:12 -0400 Subject: Place the "program:" macro of "lux/control/parser/cli" in its own module. --- .../program/aedifex/artifact/time_stamp/date.lux | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 stdlib/source/program/aedifex/artifact/time_stamp/date.lux (limited to 'stdlib/source/program/aedifex/artifact/time_stamp/date.lux') 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 (.exactly 4 .decimal)) + year (<>.lift (year.year (.int year))) + month (<>.codec n.decimal (.exactly 2 .decimal)) + month (<>.lift (month.by_number month)) + day_of_month (<>.codec n.decimal (.exactly 2 .decimal))] + (<>.lift (date.date year month day_of_month)))) -- cgit v1.2.3