aboutsummaryrefslogtreecommitdiff
path: root/lib/sql/year.ml
blob: 1e9c5990f003d6da4ef2775195e271b47ebc28f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(** Parse a text value into a date *)

open CalendarLib

let first_day = CalendarLib.Date.make 1899 12 30

let f : Sqlite3.Data.t -> Sqlite3.Data.t =
 fun data ->
  match data with
  | Sqlite3.Data.INT content ->
      let nb = Int64.to_int content in
      let date = Date.add first_day (Date.Period.day nb) in
      let year = CalendarLib.Date.year date in

      Sqlite3.Data.INT (Int64.of_int year)
  | _ -> data


let register : Sqlite3.db -> unit = fun db -> Sqlite3.create_fun1 db "year" f