diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/time/month.lux | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/stdlib/source/lux/time/month.lux b/stdlib/source/lux/time/month.lux index 41c85e981..f33a4e11c 100644 --- a/stdlib/source/lux/time/month.lux +++ b/stdlib/source/lux/time/month.lux @@ -4,6 +4,9 @@ [equivalence (#+ Equivalence)] [order (#+ Order)] [enum (#+ Enum)]] + [control + ["." try (#+ Try)] + ["." exception (#+ exception:)]] [data [number ["n" nat]]]]) @@ -46,21 +49,37 @@ _ false))) -(def: #export (number month) - (-> Month Nat) - (case month - #January 01 - #February 02 - #March 03 - #April 04 - #May 05 - #June 06 - #July 07 - #August 08 - #September 09 - #October 10 - #November 11 - #December 12)) +(with-expansions [<pairs> (as-is [01 #January] + [02 #February] + [03 #March] + [04 #April] + [05 #May] + [06 #June] + [07 #July] + [08 #August] + [09 #September] + [10 #October] + [11 #November] + [12 #December])] + (def: #export (number month) + (-> Month Nat) + (case month + (^template [<number> <month>] + [<month> <number>]) + (<pairs>))) + + (exception: #export (invalid-month {number Nat}) + (exception.report + ["Number" (\ n.decimal encode number)])) + + (def: #export (by-number number) + (-> Nat (Try Month)) + (case number + (^template [<number> <month>] + [<number> (#try.Success <month>)]) + (<pairs>) + _ (exception.throw ..invalid-month [number]))) + ) (structure: #export order (Order Month) |