package lunar

  1. Overview
  2. Docs

Source file era.ml

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
(* Copyright (c) 2026, Cargocut and the Lunar developers.
   All rights reserved.

   SPDX-License-Identifier: BSD-3-Clause *)

type t =
  | BCE
  | CE

let to_int = function
  | BCE -> 0
  | CE -> 1
;;

let equal a b = Int.equal (to_int a) (to_int b)
let compare a b = Int.compare (to_int a) (to_int b)
let from_year y = if y <= 0 then BCE else CE

let to_string = function
  | CE -> "ce"
  | BCE -> "bce"
;;

let year y =
  match from_year y with
  | BCE -> 1 - y
  | CE -> y
;;

let century y =
  let y = year y in
  ((y - 1) / 100) + 1
;;

let year_of_century y =
  let y = year y in
  ((y - 1) mod 100) + 1
;;

module CE = struct
  type nonrec t = t

  let equal = equal
  let compare = compare
end

include Util.Make_compare_helpers (CE)

module Infix = struct
  include Util.Make_equal_infix (CE)
  include Util.Make_compare_infix (CE)
end

module Map = Stdlib.Map.Make (CE)
module Set = Stdlib.Set.Make (CE)
include Infix