calendar
Imported from yugajs/extension/calendar.
Interfaces
Section titled “Interfaces”CalendarFormats
Section titled “CalendarFormats”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).
Properties
Section titled “Properties”| Property | Type |
|---|---|
lastDay? |
CalendarFormat |
lastWeek? |
CalendarFormat |
nextDay? |
CalendarFormat |
nextWeek? |
CalendarFormat |
sameDay? |
CalendarFormat |
sameElse? |
CalendarFormat |
Type Aliases
Section titled “Type Aliases”CalendarFormat
Section titled “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.
Variables
Section titled “Variables”calendar
Section titled “calendar”const calendar: yuga.Extension<void>;Adds calendar(referenceTime?, formats?), Day.js’s calendar plugin.
enhas Day.js’s templates exactly, with no need for localized formats.- A locale with a
calendarobject uses it (a missing or empty format is English’s, the same as Day.js). Any other locale is built fromIntl: “today”, “tomorrow” and “yesterday” fromIntl.RelativeTimeFormat(numeric: "auto", capitalized), the weekday name for the days around, each followed by the locale’sLT, andLfor anything farther. It reads less naturally than Day.js’s hand-written locale files,Intlhas no “at” or “Last”. TheLTandLtemplates are the ones ofyugajs/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"