Skip to content

Does Calendar can use function in format as possible value #806

@scorsi

Description

@scorsi

Hello,

It could be a good idea to add callbacks as possible values to Calendar format.
Like momentjs does since 2.14.0 : look here.

Exemple:
With arrow function:

dayjs("2020-02-26").calendar(null, {
  sameElse: (now, self) => {
    const d = self.diff(now);
    if (d > 0) return "After";
    else return "Before";
  }
});

With classic function:

dayjs("2020-02-26").calendar(null, {
  sameElse: function (now) {
    const d = this.diff(now);
    if (d > 0) return "After";
    else return "Before";
  }
});

We can pass a function which take as parameter the date given to calendar call (here null so now) and to be fully compatible with momentjs we can use this instead of the second parameter to access the base instance (here dayjs("2020-02-26")).

Thanks ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions