diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/time/day.lux | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/stdlib/source/lux/time/day.lux b/stdlib/source/lux/time/day.lux index 6d9b7f4a5..94b1dcabd 100644 --- a/stdlib/source/lux/time/day.lux +++ b/stdlib/source/lux/time/day.lux @@ -3,7 +3,13 @@ [abstract [equivalence (#+ Equivalence)] [order (#+ Order)] - [enum (#+ Enum)]] + [enum (#+ Enum)] + [codec (#+ Codec)]] + [control + ["." try] + ["." exception (#+ exception:)]] + [data + ["." text]] [math [number ["n" nat]]]]) @@ -79,3 +85,30 @@ #Friday #Thursday #Saturday #Friday #Sunday #Saturday))) + +(exception: #export (not_a_day_of_the_week {value Text}) + (exception.report + ["Value" (text.format value)])) + +(structure: #export codec + (Codec Text Day) + + (def: (encode value) + (case value + #Monday "Monday" + #Tuesday "Tuesday" + #Wednesday "Wednesday" + #Thursday "Thursday" + #Friday "Friday" + #Saturday "Saturday" + #Sunday "Sunday")) + (def: (decode value) + (case value + "Monday" (#try.Success #..Monday) + "Tuesday" (#try.Success #..Tuesday) + "Wednesday" (#try.Success #..Wednesday) + "Thursday" (#try.Success #..Thursday) + "Friday" (#try.Success #..Friday) + "Saturday" (#try.Success #..Saturday) + "Sunday" (#try.Success #..Sunday) + _ (exception.throw ..not_a_day_of_the_week [value])))) |