diff options
| author | Adelyn Breedlove <[email protected]> | 2019-01-13 23:52:45 +0000 |
|---|---|---|
| committer | Adelyn Breedlove <[email protected]> | 2019-01-13 23:52:45 +0000 |
| commit | d95f0342f9cf2280b5d9794ab638c16a59c02a69 (patch) | |
| tree | 191164d198c07cf388d9aae8a54013e5613c272c /lib/models/snowflake.ml | |
| parent | Merge branch 'dev' into 'master' (diff) | |
| parent | Add deriving sexp to models (diff) | |
| download | disml-d95f0342f9cf2280b5d9794ab638c16a59c02a69.tar.xz disml-d95f0342f9cf2280b5d9794ab638c16a59c02a69.zip | |
Merge branch 'switch-to-deriving_yojson' into 'master'
Switch to deriving yojson
See merge request Mishio595/disml!12
Diffstat (limited to 'lib/models/snowflake.ml')
| -rw-r--r-- | lib/models/snowflake.ml | 32 |
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 |