aboutsummaryrefslogtreecommitdiff
path: root/lib/models/snowflake.ml
diff options
context:
space:
mode:
authorMatias Goldfeld <[email protected]>2021-02-07 20:21:47 -0500
committerMatias Goldfeld <[email protected]>2021-02-07 20:21:47 -0500
commitb2f081fff12093a7d3434859ebd621608dde6c7d (patch)
tree5ea4f7d6ff82727d62b01fb2d234a4f8ab66aa2b /lib/models/snowflake.ml
parentRemoved generated version numbers (diff)
downloaddisml-origin/HEAD.tar.xz
disml-origin/HEAD.zip
Reverted earlier changes for goodHEADorigin/masterorigin/HEADmaster
Diffstat (limited to 'lib/models/snowflake.ml')
-rw-r--r--lib/models/snowflake.ml14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml
index 92d94fa..2bf2281 100644
--- a/lib/models/snowflake.ml
+++ b/lib/models/snowflake.ml
@@ -1,11 +1,19 @@
open Core
-type t = int64 [@@deriving sexp, yojson]
+type t = Int.t [@@deriving sexp]
-let timestamp snowflake = Int64.((snowflake lsr 22) + 1_420_070_400_000L)
+let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int.of_string
+
+let of_yojson d =
+ try Ok (of_yojson_exn d)
+ with Yojson.Safe.Util.Type_error (why,_) -> Error why
+
+let to_yojson s : Yojson.Safe.t = `String (Int.to_string s)
+
+let timestamp snowflake = (snowflake lsr 22) + 1_420_070_400_000
let time_of_t snowflake =
- let t = timestamp snowflake |> Int64.to_float in
+ let t = timestamp snowflake |> float_of_int in
Time.(Span.of_ms t
|> of_span_since_epoch)