LeCodesdocs

Dates

date(...) wraps a moment in time, dayjs-style: create one, chain arithmetic, finish with format or timeAgo. Both understand English and Russian and default to the current device language (device.language) when you don't pass one. Formatting is pure JS — no Intl — so output is identical on every platform.

TypeScript
date(value?: Date | number | string | DateValue): DateValue

The argument may be a Date, a millisecond timestamp (Date.now()), a parseable string, or another DateValue; with no argument it's the current time.

TypeScript
date().format('dddd, D MMMM')       // "Friday, 10 July"  ·  "пятница, 10 июля"
date(ts).format('DD.MM.YYYY HH:mm') // "10.07.2026 14:05"
date(ts).timeAgo()                  // "5 minutes ago"    ·  "5 минут назад"

The returned DateValue is immutable — every method returns a new value, so it's safe to hold and reuse. It also coerces to its epoch-ms via valueOf(), so +date(x), date(a) - date(b), and date(a) < date(b) all just work.

Formatting — .format

TypeScript
.format(pattern = 'D MMMM YYYY', locale?: 'en' | 'ru'): string

Format against a day.js-style token pattern (default: a long date).

YYYY YY year 2026, 26
MMMM MMM MM M month July, Jul, 07, 7
DD D day of month 05, 5
dddd ddd weekday Friday, Fri
HH H hour (24) 08, 8
hh h hour (12) 08, 8
mm m minute 05, 5
ss s second 09, 9
A a AM/PM PM, pm

Non-token characters (spaces, ., :, ,) are copied through verbatim.

Russian month case. Russian writes the month differently by context: genitive with a day (10 июля), nominative on its own (Июль 2026). .format picks the right one automatically by whether the pattern contains a day (D) token.

Relative time — .timeAgo

TypeScript
.timeAgo(locale?: 'en' | 'ru', now?: Date | number | DateValue): string

Human relative time vs now (default: the current time). Picks the largest fitting unit, reads as "just now" / "только что" under ~45 seconds, and handles Russian number agreement (1 минуту / 2 минуты / 5 минут).

TypeScript
date(ts).timeAgo()      // "5 minutes ago"  ·  "5 минут назад"
date(future).timeAgo()  // "in 2 days"      ·  "через 2 дня"

Arithmetic — chainable, immutable

TypeScript
.add(n, unit)      .subtract(n, unit)      // unit: 'ms'|'second'|'minute'|'hour'|'day'|'week'|'month'|'year'
.startOf(unit)     .endOf(unit)            // snap to start/end of the unit (local time)
TypeScript
date().add(3, 'day').startOf('day').format('D MMMM')   // "13 July"
date(ts).endOf('month').format('D MMMM')               // "31 July"

month/year are calendar-aware and clamp on short months (Jan 31 + 1 month → Feb 28), matching day.js.

Comparison & extraction — scalars

TypeScript
.diff(other, unit = 'ms'): number     // signed whole units, truncated toward zero
.isBefore(other) .isAfter(other) .isSame(other): boolean
.valueOf(): number   // epoch ms      .unix(): number   // epoch seconds
.year() .month() .day() .weekday() .hour() .minute() .second(): number
.toDate(): Date
TypeScript
date(a).diff(b, 'hour')   // e.g. -3
date(a).isBefore(b)       // true

.month() is 0-based and .weekday() is 0 (Sunday)–6, both matching the native Date getters.

See also

  • devicedevice.language, the default locale source