diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2024-03-14 08:26:58 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2024-03-14 08:26:58 +0100 |
commit | 6b377719c10d5ab3343fd5221f99a4a21008e25a (patch) | |
tree | a7c1e9a820d339a2f161af3e09cf9e3161286796 /lib/sql/year.ml |
Initial commitmain
Diffstat (limited to 'lib/sql/year.ml')
-rw-r--r-- | lib/sql/year.ml | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/sql/year.ml b/lib/sql/year.ml new file mode 100644 index 0000000..1e9c599 --- /dev/null +++ b/lib/sql/year.ml @@ -0,0 +1,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 |