aboutsummaryrefslogtreecommitdiff
path: root/lib/models/snowflake.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/snowflake.ml')
-rw-r--r--lib/models/snowflake.ml32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml
index 6b52ec6..0122da8 100644
--- a/lib/models/snowflake.ml
+++ b/lib/models/snowflake.ml
@@ -1,16 +1,22 @@
-module Make(Http : S.Http) = struct
- open Core
+open Core
- type t = Snowflake_t.t
+type t = Int.t [@@deriving sexp]
- let timestamp snowflake =
- let offset = (snowflake lsr 22) / 1000 in
- 1_420_070_400 + offset
+let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int.of_string
- let timestamp_iso snowflake =
- let t = timestamp snowflake in
- Date.(
- of_time ~zone:Time.Zone.utc
- Time.(of_span_since_epoch @@ Span.of_int_sec t)
- |> format) "%FT%T+00:00"
-end \ No newline at end of file
+let of_yojson d =
+ try of_yojson_exn d |> Ok
+ with Yojson.Safe.Util.Type_error (why,_) -> Error why
+
+let to_yojson s : Yojson.Safe.json = `String (Int.to_string s)
+
+let timestamp snowflake =
+ let offset = (snowflake lsr 22) / 1000 in
+ 1_420_070_400 + offset
+
+let timestamp_iso snowflake =
+ let t = timestamp snowflake in
+ Date.(
+ of_time ~zone:Time.Zone.utc
+ Time.(of_span_since_epoch @@ Span.of_int_sec t)
+ |> format) "%FT%T+00:00" \ No newline at end of file