blob: 896a6bd0004154a768f832b1b6239c677e377cbe (
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
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 temporal_report y =
let jan1 = match D.make ~year:y ~month:1 ~day:1 with
| Ok t -> t
| Error e -> failwith e
in
let dec31 = match D.make ~year:y ~month:12 ~day:31 with
| Ok t -> t
| Error e -> failwith e
in
(* [week] is "" for roughly 30 days a year (outside any numbered week);
printed as-is, that collapses two of the seven space-separated fields
into a double space, so naive field-position parsing (e.g. awk '{print
$4}') silently reads the wrong column on those days. Emit "-" instead,
so every line always has exactly seven single-space-separated fields. *)
let field s = if s = "" then "-" else s in
let d = ref jan1 in
while D.compare !d dec31 <= 0 do
let t = Rite_ef.Temporal_ef.temporal !d in
let r =
Colitur_kernel.Record.of_temporal ~rite:Rite_ef.Temporal_ef.id
Rite_ef.Vocab_ef.vocab !d t
in
Printf.printf "%s %s %s %s %s %s %s\n" r.Colitur_kernel.Record.date
r.Colitur_kernel.Record.weekday r.Colitur_kernel.Record.season
(field r.Colitur_kernel.Record.week) r.Colitur_kernel.Record.slug
r.Colitur_kernel.Record.rank r.Colitur_kernel.Record.colour;
d := D.add_days !d 1
done
let usage () =
prerr_endline "colitur: usage: colitur easter <year> | colitur temporal <year>";
exit 2
let with_year ys f =
match int_of_string_opt ys with
| Some y when y >= 1583 && y <= 9999 -> f y
| Some y ->
Printf.eprintf "colitur: year %d out of range 1583..9999\n" y;
exit 2
| None -> usage ()
let () =
match Sys.argv with
| [| _; "easter"; ys |] -> with_year ys easter_report
| [| _; "temporal"; ys |] -> with_year ys temporal_report
| _ -> usage ()
|