Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unix methods #14

Merged
merged 4 commits into from
Oct 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions __tests__/moment_spec.re
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ let () =
) |>
toBe true
);
test
"instantiation momentWithUnix (int)"
(
fun () =>
expect (
Moment.isSame
(moment "6 Mar 2017 21:22:23 GMT")
(momentWithUnix 1488835343)
) |>
toBe true
);
test ".now" (fun () => expect (momentNow () |> Moment.isValid) |> toBe true);
test
"#isSame"
Expand Down Expand Up @@ -145,6 +156,9 @@ let () =
test
"#toDate"
(fun () => expect (isJsDateValid (moment "2016-01-01" |> Moment.toDate)) |> toBe true);
test
"#toUnix"
(fun () => expect (moment "6 Mar 2017 21:22:23 GMT" |> Moment.toUnix) |> toBe 1488835343);
test
"#get"
(fun () => expect (moment "2017-01-02 03:04:05.678" |> Moment.get `day) |> toBe 1);
Expand Down
3 changes: 3 additions & 0 deletions src/MomentRe.re
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ module Moment = {
external daysInMonth : t => int = "" [@@bs.send];
external toJSON : t => string = "" [@@bs.send];
external toDate : t => Js.Date.t = "" [@@bs.send];
external toUnix : t => int = "unix" [@@bs.send];
};

/* parse */
Expand All @@ -132,6 +133,8 @@ external momentWithTimestampMS : float => Moment.t = "moment" [@@bs.module];

external momentWithComponents : list int => Moment.t = "moment" [@@bs.module];

let momentWithUnix (timestamp: int) => momentWithTimestampMS(float_of_int timestamp *. 1000.0);

external diff :
Moment.t =>
Moment.t =>
Expand Down