Index

Date

MMO.core · 1 symbol · generated 30 Sep 2026

class

Date

Date.js:88
class MMO.core.Date extends Date
Namespace
MMO.core
Extends
Date

Index

constructor()
From(date, format) staticBuild a date from whatever the server or a form hands over.
Format(date, format, lang) staticShorthand for From(date).format(format, lang).
DayLabels(firstDayOfWeek, long, lang) staticThe seven day names, rotated so the week starts where you want it to.
hasTime()NOTE: a date landing exactly on midnight reports false, which is what makes a plain date render without its time.
setFormat(format)Remember the format toString should use.
hasFormat()
toString()
toHTML()Render for display, dropping the time when there is none to show.
toJSON()
compare(date, operator)Compare this date with another one.
diff(date, unit)The signed distance from another date, in whole units.
isWithin(start, end)Test whether this date falls in a closed interval, bounds included.
isSameDay(date)Compare the calendar day only, ignoring the time.
modify(number, unit)Shift this date IN PLACE by a number of units, positive or negative.
get(unit)Read one calendar field by name.
isLeap()Check if year is leap (29 days in february)
getDayOfYear()Get the day of the year (1st January = 1, 31st december = 365|366)
getWeek()
setWeek(value)Move this date IN PLACE to the same weekday of another week of the same year.
startOfMonth()
endOfMonth()
startOfWeek(firstDayOfWeek)
endOfWeek(firstDayOfWeek)Get the last day of this date's week, at 23:59:59.999
startOfDay()
endOfDay()
format(format, lang)Format date with a php like format

Methods27

From(date, format)

staticDate.js:107

Build a date from whatever the server or a form hands over.

static From(date, format = null)- a number: a UNIX timestamp, in SECONDS - 'YYYY-MM-DD': a date - 'YYYY-MM-DDTHH:MM':a datetime - 'HH:MM[:SS]': a time, flagged with `isTime` - 10 digits: a UNIX timestamp - '', null, 'now': the current instant
datestring | number | Date | null
format = null?stringa default format for toString MMO.core.Date#setFormat
returnsMMO.core.Date
throwsMMO.TypeErrorwhen the value cannot be read as a date

Format(date, format, lang)

staticDate.js:143

Shorthand for From(date).format(format, lang).

static Format(date, format = null, lang = null)
datestring | number | Date | null
format = null?stringMMO.core.Date#format
lang = null?stringthe locale for the month and day names
returnsstring

DayLabels(firstDayOfWeek, long, lang)

staticDate.js:154

The seven day names, rotated so the week starts where you want it to.

static DayLabels(firstDayOfWeek = 1, long = true, lang = null)
firstDayOfWeek = 1number0 = sunday, 1 = monday (the default)
long = truebooleanfull names rather than three letter ones
lang = null?stringthe locale
returnsArray<string>

hasTime()

Date.js:167

NOTE: a date landing exactly on midnight reports false, which is what makes a plain date render without its time.

hasTime()
returnsbooleantrue when the date carries a time of day

setFormat(format)

Date.js:175

Remember the format toString should use. Pass null to forget it.

setFormat(format = null)
format = null?stringMMO.core.Date#format

hasFormat()

Date.js:183
hasFormat()
returnsbooleantrue when a format was set on this instance

toString()

Date.js:190
toString()
returnsstringthe date in its own format, or 'D d M Y H:i'

toHTML()

Date.js:198

Render for display, dropping the time when there is none to show.

toHTML()
returnsstring

toJSON()

Date.js:205
toJSON()
returnsstringthe RFC3339-ish form the server expects MMO.core.Date#format

compare(date, operator)

Date.js:221

Compare this date with another one.

compare(date, operator = null)WARNING: the comparison reads `{date} {operator} {this}`, NOT `{this} {operator} {date}`. `a.compare(b, '<')` is true when **b** is before **a**. The returned code follows the same order: 1 when `date` is after `this`, -1 when it is before.
See
MMO.core.Date#isWithin for the intended usage.
dateDate | string | numberthe date to compare with
operator = null?stringone of '<', '<=', '=', '>=', '>', '!='. null returns the raw -1|0|1 code
returnsnumber | booleanthe code when operator is null, the test's result otherwise

diff(date, unit)

Date.js:250

The signed distance from another date, in whole units.

diff(date, unit = 'day')NOTE: 'year', 'month' and 'week' compare the CALENDAR field, not the elapsed time: `diff` in years between 2023-12-31 and 2024-01-01 is 1, not 0. The other units are computed from the timestamps.
dateDate | string | number
unit = 'day'stringyear|month|week|day|hour|min|sec
returnsnumberpositive when this date is the later one
throwsMMO.TypeErroron an unknown unit

isWithin(start, end)

Date.js:270

Test whether this date falls in a closed interval, bounds included.

isWithin(start, end)
startDate | string | number
endDate | string | number
returnsboolean

isSameDay(date)

Date.js:279

Compare the calendar day only, ignoring the time.

isSameDay(date)
dateDate | string | number
returnsboolean

modify(number, unit)

Date.js:292

Shift this date IN PLACE by a number of units, positive or negative.

modify(number, unit)
numbernumber
unitstringyear|month|week|day|hour|min|sec
returnsnumberthe new timestamp
throwsMMO.TypeErroron an unknown unit

get(unit)

Date.js:311

Read one calendar field by name.

get(unit)
unitstringyear|month|week|day|hour|min|sec ('month' is 0 based)
returnsnumber
throwsMMO.TypeErroron an unknown unit

isLeap()

Date.js:328

Check if year is leap (29 days in february)

isLeap()
returnsBoolean

getDayOfYear()

Date.js:337

Get the day of the year (1st January = 1, 31st december = 365|366)

getDayOfYear()
returns

getWeek()

Date.js:350
getWeek()
See
http://perso.univ-lemans.fr/~hainry/articles/semaine.html

setWeek(value)

Date.js:361

Move this date IN PLACE to the same weekday of another week of the same year.

setWeek(value)
valuenumberthe week number MMO.core.Date#getWeek
returnsnumberthe new timestamp

startOfWeek(firstDayOfWeek)

Date.js:385
startOfWeek(firstDayOfWeek = 1)
firstDayOfWeek = 1number0 = sunday, 1 = monday (the default)
returnsMMO.core.Datea NEW date on the first day of this week, at 00:00:00.000

endOfWeek(firstDayOfWeek)

Date.js:398

Get the last day of this date's week, at 23:59:59.999

endOfWeek(firstDayOfWeek = 1)
firstDayOfWeek = 1number0 = sunday, 1 = monday (the default), ...
returnsMMO.core.Date

format(format, lang)

Date.js:430

Format date with a php like format

format(format = null, lang = null)
format = null?stringhttps://www.php.net/manual/en/datetime.format.php
lang = null
returnsstring