aboutsummaryrefslogtreecommitdiff
path: root/lib/sql/year.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sql/year.ml')
-rw-r--r--lib/sql/year.ml19
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