aboutsummaryrefslogtreecommitdiff
path: root/bin/main.ml
blob: eb70a26c9f55ffca8ae35e476b9dd080c6777816 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 ()