bs-moment icon indicating copy to clipboard operation
bs-moment copied to clipboard

isBefore/isAfter have their arguments reversed

Open Anahkiasen opened this issue 5 years ago • 0 comments

This is something that becomes quite obvious when you chain multiple method calls as the isBefore/isAfter stand out like a sore thumb:

let before = momentNow() |> Moment.subtract(~duration=duration(1, `days));
let date = momentNow() |> Moment.add(~duration=duration(1, `days));

date |> Moment.isAfter(before); /* false */
date -> Moment.isAfter(before); /* true */

It seems that in the current API, the Moment instance is always passed last. However, in isAfter/isBefore, it seems the order of expected arguments is the opposite which results in having to use fast pipes to get the expected result.

This seems to be on purpose as the tests show but seems counterintuitive to me:

test("#isAfter", () =>
expect(
  Moment.isAfter(moment("2016-01-02"), moment("2016-01-01")),
)
|> toBe(true)
);

To me if the current instance is always passed last, then I would expect moment(2018) |> Moment.isAfter(2016) to return true

Anahkiasen avatar Nov 25 '18 11:11 Anahkiasen