diff options
| author | Matias Goldfeld <[email protected]> | 2021-01-29 13:40:29 -0500 |
|---|---|---|
| committer | Matias Goldfeld <[email protected]> | 2021-01-29 13:40:29 -0500 |
| commit | 7ad203a0249bd9db50dfb1df4adb9b7483406e30 (patch) | |
| tree | 52696cb3e1c16a84513fb90fe50c3738ce4539cb /lib/models/snowflake.ml | |
| parent | Started conversion to ppx_yojson_conv (diff) | |
| download | disml-7ad203a0249bd9db50dfb1df4adb9b7483406e30.tar.xz disml-7ad203a0249bd9db50dfb1df4adb9b7483406e30.zip | |
Revert "Started conversion to ppx_yojson_conv"
This reverts commit c937240fdd2036edd493debb76117165e4084e8b.
Diffstat (limited to 'lib/models/snowflake.ml')
| -rw-r--r-- | lib/models/snowflake.ml | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml index 92d94fa..868b2b9 100644 --- a/lib/models/snowflake.ml +++ b/lib/models/snowflake.ml @@ -1,6 +1,14 @@ open Core
-type t = int64 [@@deriving sexp, yojson]
+type t = int64 [@@deriving sexp]
+
+let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int64.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 (Int64.to_string s)
let timestamp snowflake = Int64.((snowflake lsr 22) + 1_420_070_400_000L)
|