Skip to content

isBefore/isAfter have their arguments reversed #33

Open
@Anahkiasen

Description

@Anahkiasen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions