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

isBefore/isAfter have their arguments reversed #33

Open
Anahkiasen opened this issue Nov 25, 2018 · 0 comments
Open

isBefore/isAfter have their arguments reversed #33

Anahkiasen opened this issue Nov 25, 2018 · 0 comments

Comments

@Anahkiasen
Copy link

Anahkiasen commented Nov 25, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant