diff --git a/__tests__/moment_spec.re b/__tests__/moment_spec.re index cbed257..504414f 100644 --- a/__tests__/moment_spec.re +++ b/__tests__/moment_spec.re @@ -2,260 +2,243 @@ open Jest; open MomentRe; -let isJsDateValid: Js.Date.t => bool = [%bs.raw {| +let isJsDateValid: Js.Date.t => bool = [%bs.raw + {| function(date) { return (date instanceof Date && !isNaN(date.valueOf())) ? 1 : 0; } -|}]; +|} +]; /* note that this is an interops test, not tests for moment.js itself, i.e. test comprehensiveness is not the goal */ let () = - describe - "moment" + describe( + "moment", ExpectJs.( - fun () => { - test - "#clone" - (fun () => expect (moment "2017-01-01" |> Moment.clone |> Moment.isValid) |> toBe true); - test - "#mutableAdd" - ( - fun () => - expect ( - Moment.isSame - (moment "2017-01-04") - { - let original = moment "2017-01-01"; - Moment.mutableAdd original (duration 3 `days); - original - } - ) |> - toBe true - ); - test - "#add" - ( - fun () => - expect ( - Moment.isSame - (moment "2017-01-04") - ( - moment "2017-01-01" |> Moment.add duration::(duration 1 `days) |> - Moment.add duration::(duration 2 `days) - ) - ) |> - toBe true - ); - test "#isValid" (fun () => expect (moment "2017-01-01" |> Moment.isValid) |> toBe true); - test "not #isValid" (fun () => expect (moment "" |> Moment.isValid) |> toBe false); - test - "#isDST" (fun () => expect (moment "2016-01-01T00:00:00" |> Moment.isDST) |> toBe false); - test - "leap year" (fun () => expect (moment "2016-01-01" |> Moment.isLeapYear) |> toBe true); - test - "not leap year" - (fun () => expect (moment "1900-01-01" |> Moment.isLeapYear) |> toBe false); - test - "instantiation" - ( - fun () => - expect (Moment.isSame (moment "2017-04-01") (moment "2017-04-01")) |> toBe true - ); - test - "instantiation with format" - ( - fun () => - expect (Moment.isSame (moment "2017-04-01") (moment "2017-04-01")) |> toBe true - ); - test - "instantiation with date" - ( - fun () => - expect (Moment.isSame (momentWithDate (Js.Date.fromString "6 Mar 2017 21:22:23 GMT")) (moment "6 Mar 2017 21:22:23 GMT")) |> toBe true - ); - test - "instantiation momentWithTimestampMS (float)" - ( - fun () => - expect ( - Moment.isSame - (moment "2017-06-12T18:30:00+02:00") - (momentWithTimestampMS (Int64.of_string "1497285000000" |> Int64.to_float)) - ) |> - 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" - ( - fun () => - expect (Moment.isSame (moment "2016-01-01") (moment "2016-01-01")) |> toBe true - ); - test - "#isBefore" - ( - fun () => - expect (Moment.isBefore (moment "2016-01-01") (moment "2016-01-02")) |> toBe true - ); - test - "#isSameOrBefore" - ( - fun () => - expect (Moment.isSameOrBefore (moment "2016-01-01") (moment "2016-01-02")) |> - toBe true - ); - test - "#isAfter" - ( - fun () => - expect (Moment.isAfter (moment "2016-01-02") (moment "2016-01-01")) |> toBe true - ); - test - "#isSameOrAfter" - ( - fun () => - expect (Moment.isSameOrAfter (moment "2016-01-02") (moment "2016-01-01")) |> - toBe true - ); - test - "#isBetween" - ( - fun () => - expect ( - Moment.isBetween (moment "2016-01-02") (moment "2016-01-01") (moment "2016-01-03") - ) |> - toBe true - ); - test - "#format" - ( - fun () => - expect (moment "2016-01-01" |> Moment.format "YYYY-MM-DD") |> toBe "2016-01-01" - ); - test /* TODO: test this time-zone independently */ - "#defaultFormat" - ( - fun () => - expect (moment "2016-01-01" |> Moment.defaultFormat) |> toContainString "2016-01-01" - ); - test - "#valueOf" /* TODO: float? */ - ( - fun () => - expect (moment "2016-01-01 00:00:00Z" |> Moment.valueOf) |> - toBeCloseTo 1451606400000. - ); - test - "#toJSON" - (fun () => expect (moment "2016-01-01" |> Moment.toJSON) |> toContainString "000Z"); - 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); - test - "#second" - (fun () => expect (moment "2017-01-02 03:04:05.678" |> Moment.second) |> toBe 5); - test - "#minute" - (fun () => expect (moment "2017-01-02 03:04:05.678" |> Moment.minute) |> toBe 4); - test - "#hour" (fun () => expect (moment "2017-01-02 03:04:05.678" |> Moment.hour) |> toBe 3); - test "#day" (fun () => expect (moment "2017-01-02 03:04:05.678" |> Moment.day) |> toBe 1); - test - "#week" (fun () => expect (moment "2017-01-02 03:04:05.678" |> Moment.week) |> toBe 1); - test - "#month" (fun () => expect (moment "2017-01-02 03:04:05.678" |> Moment.month) |> toBe 0); - test - "#year" (fun () => expect (moment "2017-01-02 03:04:05.678" |> Moment.year) |> toBe 2017) + () => { + test( + "#clone", + () => expect(moment("2017-01-01") |> Moment.clone |> Moment.isValid) |> toBe(true) + ); + test( + "#mutableAdd", + () => + expect( + Moment.isSame( + moment("2017-01-04"), + { + let original = moment("2017-01-01"); + Moment.mutableAdd(original, duration(3, `days)); + original + } + ) + ) + |> toBe(true) + ); + test( + "#add", + () => + expect( + Moment.isSame( + moment("2017-01-04"), + moment("2017-01-01") + |> Moment.add(~duration=duration(1, `days)) + |> Moment.add(~duration=duration(2, `days)) + ) + ) + |> toBe(true) + ); + test("#isValid", () => expect(moment("2017-01-01") |> Moment.isValid) |> toBe(true)); + test("not #isValid", () => expect(moment("") |> Moment.isValid) |> toBe(false)); + test("#isDST", () => expect(moment("2016-01-01T00:00:00") |> Moment.isDST) |> toBe(false)); + test("leap year", () => expect(moment("2016-01-01") |> Moment.isLeapYear) |> toBe(true)); + test( + "not leap year", + () => expect(moment("1900-01-01") |> Moment.isLeapYear) |> toBe(false) + ); + test( + "instantiation", + () => expect(Moment.isSame(moment("2017-04-01"), moment("2017-04-01"))) |> toBe(true) + ); + test( + "instantiation with format", + () => expect(Moment.isSame(moment("2017-04-01"), moment("2017-04-01"))) |> toBe(true) + ); + test( + "instantiation with date", + () => + expect( + Moment.isSame( + momentWithDate(Js.Date.fromString("6 Mar 2017 21:22:23 GMT")), + moment("6 Mar 2017 21:22:23 GMT") + ) + ) + |> toBe(true) + ); + test( + "instantiation momentWithTimestampMS (float)", + () => + expect( + Moment.isSame( + moment("2017-06-12T18:30:00+02:00"), + momentWithTimestampMS(Int64.of_string("1497285000000") |> Int64.to_float) + ) + ) + |> toBe(true) + ); + test( + "instantiation momentWithUnix (int)", + () => + expect(Moment.isSame(moment("6 Mar 2017 21:22:23 GMT"), momentWithUnix(1488835343))) + |> toBe(true) + ); + test(".now", () => expect(momentNow() |> Moment.isValid) |> toBe(true)); + test( + "#isSame", + () => expect(Moment.isSame(moment("2016-01-01"), moment("2016-01-01"))) |> toBe(true) + ); + test( + "#isBefore", + () => expect(Moment.isBefore(moment("2016-01-01"), moment("2016-01-02"))) |> toBe(true) + ); + test( + "#isSameOrBefore", + () => + expect(Moment.isSameOrBefore(moment("2016-01-01"), moment("2016-01-02"))) |> toBe(true) + ); + test( + "#isAfter", + () => expect(Moment.isAfter(moment("2016-01-02"), moment("2016-01-01"))) |> toBe(true) + ); + test( + "#isSameOrAfter", + () => + expect(Moment.isSameOrAfter(moment("2016-01-02"), moment("2016-01-01"))) |> toBe(true) + ); + test( + "#isBetween", + () => + expect( + Moment.isBetween(moment("2016-01-02"), moment("2016-01-01"), moment("2016-01-03")) + ) + |> toBe(true) + ); + test( + "#format", + () => expect(moment("2016-01-01") |> Moment.format("YYYY-MM-DD")) |> toBe("2016-01-01") + ); + test /* TODO: test this time-zone independently */( + "#defaultFormat", + () => + expect(moment("2016-01-01") |> Moment.defaultFormat) |> toContainString("2016-01-01") + ); + test( + "#valueOf", /* TODO: float? */ + () => + expect(moment("2016-01-01 00:00:00Z") |> Moment.valueOf) |> toBeCloseTo(1451606400000.) + ); + test( + "#toJSON", + () => expect(moment("2016-01-01") |> Moment.toJSON) |> toContainString("000Z") + ); + test( + "#toDate", + () => expect(isJsDateValid(moment("2016-01-01") |> Moment.toDate)) |> toBe(true) + ); + test( + "#toUnix", + () => expect(moment("6 Mar 2017 21:22:23 GMT") |> Moment.toUnix) |> toBe(1488835343) + ); + test( + "#get", + () => expect(moment("2017-01-02 03:04:05.678") |> Moment.get(`day)) |> toBe(1) + ); + test( + "#second", + () => expect(moment("2017-01-02 03:04:05.678") |> Moment.second) |> toBe(5) + ); + test( + "#minute", + () => expect(moment("2017-01-02 03:04:05.678") |> Moment.minute) |> toBe(4) + ); + test("#hour", () => expect(moment("2017-01-02 03:04:05.678") |> Moment.hour) |> toBe(3)); + test("#day", () => expect(moment("2017-01-02 03:04:05.678") |> Moment.day) |> toBe(1)); + test("#week", () => expect(moment("2017-01-02 03:04:05.678") |> Moment.week) |> toBe(1)); + test("#month", () => expect(moment("2017-01-02 03:04:05.678") |> Moment.month) |> toBe(0)); + test("#year", () => expect(moment("2017-01-02 03:04:05.678") |> Moment.year) |> toBe(2017)) } - ); + ) + ); let () = - describe - "moment duration" + describe( + "moment duration", ExpectJs.( - fun () => { - test "get duration" (fun () => expect (duration 2 `days) |> toBeTruthy); - test "get duration millis" (fun () => expect (durationMillis 2) |> toBeTruthy); - test - "get duration format" - (fun () => expect (durationFormat "P2D" |> Duration.toJSON) |> toBe "P2D"); - test - "#milliseconds" - (fun () => expect (duration 2 `milliseconds |> Duration.milliseconds) |> toBe 2); - test "#seconds" (fun () => expect (duration 2 `seconds |> Duration.seconds) |> toBe 2); - test - "#asSeconds" (fun () => expect (duration 2 `seconds |> Duration.asSeconds) |> toBe 2.); - test "#minutes" (fun () => expect (duration 2 `minutes |> Duration.minutes) |> toBe 2); - test - "#asMinutes" (fun () => expect (duration 2 `minutes |> Duration.asMinutes) |> toBe 2.); - test "#hours" (fun () => expect (duration 2 `hours |> Duration.hours) |> toBe 2); - test "#asHours" (fun () => expect (duration 2 `hours |> Duration.asHours) |> toBe 2.); - test "#days" (fun () => expect (duration 2 `days |> Duration.days) |> toBe 2); - test "#asDays" (fun () => expect (duration 2 `days |> Duration.asDays) |> toBe 2.); - test "#weeks" (fun () => expect (duration 2 `weeks |> Duration.weeks) |> toBe 2); - test "#asWeeks" (fun () => expect (duration 2 `weeks |> Duration.asWeeks) |> toBe 2.); - test "#months" (fun () => expect (duration 2 `months |> Duration.months) |> toBe 2); - test "#asMonths" (fun () => expect (duration 2 `months |> Duration.asMonths) |> toBe 2.); - test "#years" (fun () => expect (duration 2 `years |> Duration.years) |> toBe 2); - test "#asYears" (fun () => expect (duration 2 `years |> Duration.asYears) |> toBe 2.); - test "#as" (fun () => expect (duration 2 `days |> Duration.asUnitOfTime `days) |> toBe 2.); - test "#toJSON" (fun () => expect (duration 2 `days |> Duration.toJSON) |> toBe "P2D"); - test - "#humanize" (fun () => expect (duration 2 `days |> Duration.humanize) |> toBe "2 days") + () => { + test("get duration", () => expect(duration(2, `days)) |> toBeTruthy); + test("get duration millis", () => expect(durationMillis(2)) |> toBeTruthy); + test( + "get duration format", + () => expect(durationFormat("P2D") |> Duration.toJSON) |> toBe("P2D") + ); + test( + "#milliseconds", + () => expect(duration(2, `milliseconds) |> Duration.milliseconds) |> toBe(2) + ); + test("#seconds", () => expect(duration(2, `seconds) |> Duration.seconds) |> toBe(2)); + test("#asSeconds", () => expect(duration(2, `seconds) |> Duration.asSeconds) |> toBe(2.)); + test("#minutes", () => expect(duration(2, `minutes) |> Duration.minutes) |> toBe(2)); + test("#asMinutes", () => expect(duration(2, `minutes) |> Duration.asMinutes) |> toBe(2.)); + test("#hours", () => expect(duration(2, `hours) |> Duration.hours) |> toBe(2)); + test("#asHours", () => expect(duration(2, `hours) |> Duration.asHours) |> toBe(2.)); + test("#days", () => expect(duration(2, `days) |> Duration.days) |> toBe(2)); + test("#asDays", () => expect(duration(2, `days) |> Duration.asDays) |> toBe(2.)); + test("#weeks", () => expect(duration(2, `weeks) |> Duration.weeks) |> toBe(2)); + test("#asWeeks", () => expect(duration(2, `weeks) |> Duration.asWeeks) |> toBe(2.)); + test("#months", () => expect(duration(2, `months) |> Duration.months) |> toBe(2)); + test("#asMonths", () => expect(duration(2, `months) |> Duration.asMonths) |> toBe(2.)); + test("#years", () => expect(duration(2, `years) |> Duration.years) |> toBe(2)); + test("#asYears", () => expect(duration(2, `years) |> Duration.asYears) |> toBe(2.)); + test("#as", () => expect(duration(2, `days) |> Duration.asUnitOfTime(`days)) |> toBe(2.)); + test("#toJSON", () => expect(duration(2, `days) |> Duration.toJSON) |> toBe("P2D")); + test("#humanize", () => expect(duration(2, `days) |> Duration.humanize) |> toBe("2 days")) } - ); + ) + ); let () = - describe - "moment diff" + describe( + "moment diff", ExpectJs.( - fun () => { - test - "should return correct difference of moments in days" - (fun () => expect (diff (moment "2017-01-02") (moment "2017-01-01") `days) |> toBe 1.); - test - "should return correct difference of moments in hours" - ( - fun () => - expect ( - diff (moment "2017-01-01 02:00:00.000") (moment "2017-01-01 00:00:00.000") `hours - ) |> - toBe 2. - ); - test - "should be able to handle negative difference of moments" - ( - fun () => - expect ( - diff (moment "2017-01-01 00:00:00.000") (moment "2017-01-01 02:00:00.000") `hours - ) |> - toBe (-2.) - ); - test - "should return correct difference of moments in hours" - ( - fun () => - expect ( - diff (moment "2017-01-01 00:25:05.000") (moment "2017-01-01 00:00:00.000") `minutes - ) |> - toBe 25. - ) + () => { + test( + "should return correct difference of moments in days", + () => expect(diff(moment("2017-01-02"), moment("2017-01-01"), `days)) |> toBe(1.) + ); + test( + "should return correct difference of moments in hours", + () => + expect( + diff(moment("2017-01-01 02:00:00.000"), moment("2017-01-01 00:00:00.000"), `hours) + ) + |> toBe(2.) + ); + test( + "should be able to handle negative difference of moments", + () => + expect( + diff(moment("2017-01-01 00:00:00.000"), moment("2017-01-01 02:00:00.000"), `hours) + ) + |> toBe((-2.)) + ); + test( + "should return correct difference of moments in hours", + () => + expect( + diff(moment("2017-01-01 00:25:05.000"), moment("2017-01-01 00:00:00.000"), `minutes) + ) + |> toBe(25.) + ) } - ); + ) + ); diff --git a/bsconfig.json b/bsconfig.json index cc9caf4..e7f587b 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -12,5 +12,6 @@ ], "bs-dev-dependencies": [ "bs-jest" - ] + ], + "refmt": 3 } diff --git a/package.json b/package.json index cc55664..a945082 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "devDependencies": { "bs-jest": "^0.1.0", - "bs-platform": "^1.9.2", + "bs-platform": "^2.0.0", "husky": "^0.13.3", "jest": "^19.0.2", "moment": "^2.18.1" diff --git a/src/MomentRe.re b/src/MomentRe.re index f95fef2..a6d0880 100644 --- a/src/MomentRe.re +++ b/src/MomentRe.re @@ -1,25 +1,28 @@ /* duration */ module Duration = { type t; - external humanize : t => string = "" [@@bs.send]; - external milliseconds : t => int = "" [@@bs.send]; - external asMilliseconds : t => float = "" [@@bs.send]; - external seconds : t => int = "" [@@bs.send]; - external asSeconds : t => float = "" [@@bs.send]; - external minutes : t => int = "" [@@bs.send]; - external asMinutes : t => float = "" [@@bs.send]; - external hours : t => int = "" [@@bs.send]; - external asHours : t => float = "" [@@bs.send]; - external days : t => int = "" [@@bs.send]; - external asDays : t => float = "" [@@bs.send]; - external weeks : t => int = "" [@@bs.send]; - external asWeeks : t => float = "" [@@bs.send]; - external months : t => int = "" [@@bs.send]; - external asMonths : t => float = "" [@@bs.send]; - external years : t => int = "" [@@bs.send]; - external asYears : t => float = "" [@@bs.send]; - external toJSON : t => string = "" [@@bs.send]; + [@bs.send] external humanize : t => string = ""; + [@bs.send] external milliseconds : t => int = ""; + [@bs.send] external asMilliseconds : t => float = ""; + [@bs.send] external seconds : t => int = ""; + [@bs.send] external asSeconds : t => float = ""; + [@bs.send] external minutes : t => int = ""; + [@bs.send] external asMinutes : t => float = ""; + [@bs.send] external hours : t => int = ""; + [@bs.send] external asHours : t => float = ""; + [@bs.send] external days : t => int = ""; + [@bs.send] external asDays : t => float = ""; + [@bs.send] external weeks : t => int = ""; + [@bs.send] external asWeeks : t => float = ""; + [@bs.send] external months : t => int = ""; + [@bs.send] external asMonths : t => float = ""; + [@bs.send] external years : t => int = ""; + [@bs.send] external asYears : t => float = ""; + [@bs.send] external toJSON : t => string = ""; + [@bs.send.pipe : t] external asUnitOfTime : + ( + [@bs.string] [ | `years | `quarters @@ -31,122 +34,157 @@ module Duration = { | `seconds | `milliseconds ] - [@bs.string] => + ) => float = - "as" [@@bs.send.pipe : t]; + "as"; }; +[@bs.module "moment"] external duration : - int => - [ | `years | `quarters | `months | `weeks | `days | `hours | `minutes | `seconds | `milliseconds] - [@bs.string] => + ( + int, + [@bs.string] + [ + | `years + | `quarters + | `months + | `weeks + | `days + | `hours + | `minutes + | `seconds + | `milliseconds + ] + ) => Duration.t = - "" [@@bs.module "moment"]; + ""; -external durationMillis : int => Duration.t = "duration" [@@bs.module "moment"]; +[@bs.module "moment"] external durationMillis : int => Duration.t = "duration"; -external durationFormat : string => Duration.t = "duration" [@@bs.module "moment"]; +[@bs.module "moment"] external durationFormat : string => Duration.t = "duration"; module Moment = { type t; - external clone : t = "" [@@bs.send.pipe : t]; - external mutableAdd : t => Duration.t => unit = "add" [@@bs.send]; - let add ::duration moment => { - let clone = clone moment; - mutableAdd clone duration; + [@bs.send.pipe : t] external clone : t = ""; + [@bs.send] external mutableAdd : (t, Duration.t) => unit = "add"; + let add = (~duration, moment) => { + let clone = clone(moment); + mutableAdd(clone, duration); clone }; - external mutableSubtract : t => Duration.t => unit = "subtract" [@@bs.send]; - let subtract ::duration moment => { - let clone = clone moment; - mutableSubtract clone duration; + [@bs.send] external mutableSubtract : (t, Duration.t) => unit = "subtract"; + let subtract = (~duration, moment) => { + let clone = clone(moment); + mutableSubtract(clone, duration); clone }; + [@bs.send] external mutableStartOf : - t => - [ | `year | `quarter | `month | `week | `day | `hour | `minute | `second | `millisecond] - [@bs.string] => + ( + t, + [@bs.string] + [ | `year | `quarter | `month | `week | `day | `hour | `minute | `second | `millisecond] + ) => unit = - "startOf" [@@bs.send]; - let startOf timeUnit moment => { - let clone = clone moment; - mutableStartOf clone timeUnit; + "startOf"; + let startOf = (timeUnit, moment) => { + let clone = clone(moment); + mutableStartOf(clone, timeUnit); clone }; + [@bs.send] external mutableEndOf : - t => - [ | `year | `quarter | `month | `week | `day | `hour | `minute | `second | `millisecond] - [@bs.string] => + ( + t, + [@bs.string] + [ | `year | `quarter | `month | `week | `day | `hour | `minute | `second | `millisecond] + ) => unit = - "endOf" [@@bs.send]; - let endOf timeUnit moment => { - let clone = clone moment; - mutableEndOf clone timeUnit; + "endOf"; + let endOf = (timeUnit, moment) => { + let clone = clone(moment); + mutableEndOf(clone, timeUnit); clone }; + [@bs.send.pipe : t] external get : + ( + [@bs.string] [ | `year | `quarter | `month | `week | `day | `hour | `minute | `second | `millisecond] - [@bs.string] => + ) => int = - "" [@@bs.send.pipe : t]; - external millisecond : int = "" [@@bs.send.pipe : t]; - external second : int = "" [@@bs.send.pipe : t]; - external minute : int = "" [@@bs.send.pipe : t]; - external hour : int = "" [@@bs.send.pipe : t]; - external day : int = "" [@@bs.send.pipe : t]; - external week : int = "" [@@bs.send.pipe : t]; - external month : int = "" [@@bs.send.pipe : t]; - external year : int = "" [@@bs.send.pipe : t]; - external isValid : t => bool = "" [@@bs.send]; - external isBefore : t => t => bool = "" [@@bs.send]; - external isAfter : t => t => bool = "" [@@bs.send]; - external isSame : t => t => bool = "" [@@bs.send]; - external isSameOrBefore : t => t => bool = "" [@@bs.send]; - external isSameOrAfter : t => t => bool = "" [@@bs.send]; - external isBetween : t => t => t => bool = "" [@@bs.send]; - external isDST : t => bool = "" [@@bs.send]; - external isLeapYear : t => bool = "" [@@bs.send]; + ""; + [@bs.send.pipe : t] external millisecond : int = ""; + [@bs.send.pipe : t] external second : int = ""; + [@bs.send.pipe : t] external minute : int = ""; + [@bs.send.pipe : t] external hour : int = ""; + [@bs.send.pipe : t] external day : int = ""; + [@bs.send.pipe : t] external week : int = ""; + [@bs.send.pipe : t] external month : int = ""; + [@bs.send.pipe : t] external year : int = ""; + [@bs.send] external isValid : t => bool = ""; + [@bs.send] external isBefore : (t, t) => bool = ""; + [@bs.send] external isAfter : (t, t) => bool = ""; + [@bs.send] external isSame : (t, t) => bool = ""; + [@bs.send] external isSameOrBefore : (t, t) => bool = ""; + [@bs.send] external isSameOrAfter : (t, t) => bool = ""; + [@bs.send] external isBetween : (t, t, t) => bool = ""; + [@bs.send] external isDST : t => bool = ""; + [@bs.send] external isLeapYear : t => bool = ""; /* display */ - external format : string => string = "" [@@bs.send.pipe : t]; - external defaultFormat : string = "format" [@@bs.send.pipe : t]; - external fromNow : t => withoutSuffix::option bool => string = "" [@@bs.send]; - external fromMoment : t => other::t => format::option string => string = "from" [@@bs.send]; - external toNow : t => withoutSuffix::option bool => string = "" [@@bs.send]; - external toMoment : t => other::t => format::string => string = "to" [@@bs.send]; - external valueOf : t => float = "" [@@bs.send]; - 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]; + [@bs.send.pipe : t] external format : string => string = ""; + [@bs.send.pipe : t] external defaultFormat : string = "format"; + [@bs.send] external fromNow : (t, ~withoutSuffix: option(bool)) => string = ""; + [@bs.send] external fromMoment : (t, ~other: t, ~format: option(string)) => string = "from"; + [@bs.send] external toNow : (t, ~withoutSuffix: option(bool)) => string = ""; + [@bs.send] external toMoment : (t, ~other: t, ~format: string) => string = "to"; + [@bs.send] external valueOf : t => float = ""; + [@bs.send] 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"; }; /* parse */ -external momentNow : unit => Moment.t = "moment" [@@bs.module]; +[@bs.module] external momentNow : unit => Moment.t = "moment"; -external momentDefaultFormat : string => Moment.t = "moment" [@@bs.module]; +[@bs.module] external momentDefaultFormat : string => Moment.t = "moment"; -external momentWithFormat : string => string => Moment.t = "moment" [@@bs.module]; +[@bs.module] external momentWithFormat : (string, string) => Moment.t = "moment"; -external momentWithDate : Js.Date.t => Moment.t = "moment" [@@bs.module]; +[@bs.module] external momentWithDate : Js.Date.t => Moment.t = "moment"; -external momentWithFormats : string => list string => Moment.t = "moment" [@@bs.module]; +[@bs.module] external momentWithFormats : (string, list(string)) => Moment.t = "moment"; -external momentWithTimestampMS : float => Moment.t = "moment" [@@bs.module]; +[@bs.module] external momentWithTimestampMS : float => Moment.t = "moment"; -external momentWithComponents : list int => Moment.t = "moment" [@@bs.module]; +[@bs.module] external momentWithComponents : list(int) => Moment.t = "moment"; -let momentWithUnix (timestamp: int) => momentWithTimestampMS(float_of_int timestamp *. 1000.0); +let momentWithUnix = (timestamp: int) => momentWithTimestampMS(float_of_int(timestamp) *. 1000.0); +[@bs.send] external diff : - Moment.t => - Moment.t => - [ | `years | `quarters | `months | `weeks | `days | `hours | `minutes | `seconds | `milliseconds] - [@bs.string] => + ( + Moment.t, + Moment.t, + [@bs.string] + [ + | `years + | `quarters + | `months + | `weeks + | `days + | `hours + | `minutes + | `seconds + | `milliseconds + ] + ) => float = - "" [@@bs.send]; + ""; -let moment ::format=? value => +let moment = (~format=?, value) => switch format { - | Some f => momentWithFormats value f - | None => momentDefaultFormat value + | Some(f) => momentWithFormats(value, f) + | None => momentDefaultFormat(value) }; diff --git a/yarn.lock b/yarn.lock index c9e3c32..cf52239 100644 --- a/yarn.lock +++ b/yarn.lock @@ -315,9 +315,9 @@ bs-jest@^0.1.0: dependencies: jest "^19.0.2" -bs-platform@^1.9.2: - version "1.9.3" - resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-1.9.3.tgz#8c28976ea206165183f0e8bb2c3cfd8a04120a8a" +bs-platform@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-2.0.0.tgz#17ee607fa829f67b8b920438ebca5ec1deab3276" bser@1.0.2: version "1.0.2"