Skip to content

calendar

Imported from yugajs/extension/calendar.

The format of each bucket: lastDay (yesterday), sameDay, nextDay, nextWeek (2 to 6 days ahead), lastWeek (2 to 6 days back) and sameElse (anything farther).

Property Type
lastDay? CalendarFormat
lastWeek? CalendarFormat
nextDay? CalendarFormat
nextWeek? CalendarFormat
sameDay? CalendarFormat
sameElse? CalendarFormat
type CalendarFormat = string | ((this, now) => string);

A format of a bucket: a template, or a function that gets now and has the instance as this and returns the text.

const calendar: yuga.Extension<void>;

Adds calendar(referenceTime?, formats?), Day.js’s calendar plugin.

  • en has Day.js’s templates exactly, with no need for localized formats.
  • A locale with a calendar object uses it (a missing or empty format is English’s, the same as Day.js). Any other locale is built from Intl: “today”, “tomorrow” and “yesterday” from Intl.RelativeTimeFormat (numeric: "auto", capitalized), the weekday name for the days around, each followed by the locale’s LT, and L for anything farther. It reads less naturally than Day.js’s hand-written locale files, Intl has no “at” or “Last”. The LT and L templates are the ones of yugajs/extension/localized-format, which needn’t be installed.
import { calendar } from "yugajs/extension/calendar";
yuga.extend(calendar);
yuga("2024-05-15T10:20").calendar("2024-05-14"); // "Tomorrow at 10:20 AM"