diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/main.ml | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/bin/main.ml b/bin/main.ml index 761f68e..eb70a26 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,2 +1,28 @@ -(* colitur CLI — scaffold stub; the real `easter` subcommand arrives in Task 4. *) -let () = () +module D = Colitur_kernel.Date +module C = Colitur_kernel.Computus + +let fmt d = Printf.sprintf "%04d-%02d-%02d" (D.year d) (D.month d) (D.day d) + +let easter_report y = + [ ("easter", C.gregorian_easter y); + ("ash-wednesday", C.ash_wednesday y); + ("palm-sunday", C.palm_sunday y); + ("ascension", C.ascension y); + ("pentecost", C.pentecost y); + ("corpus-christi", C.corpus_christi y) ] + |> List.iter (fun (name, d) -> Printf.printf "%s %s\n" name (fmt d)) + +let usage () = + prerr_endline "colitur: usage: colitur easter <year>"; + exit 2 + +let () = + match Sys.argv with + | [| _; "easter"; ys |] -> ( + match int_of_string_opt ys with + | Some y when y >= 1583 && y <= 9999 -> easter_report y + | Some y -> + Printf.eprintf "colitur: year %d out of range 1583..9999\n" y; + exit 2 + | None -> usage ()) + | _ -> usage () |
