Documentations › mmo.client › js › core Date MMO.core · 1 symbol · generated 30 Sep 2026
class MMO.core.Date extends Date Namespace MMO.coreExtends DateIndex constructor() From(date, format) static Build a date from whatever the server or a form hands over. Format(date, format, lang) static Shorthand for From(date).format(format, lang). DayLabels(firstDayOfWeek, long, lang) static The 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 constructor() 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 date string | number | Date | nullformat = null ?stringa default format for toString MMO.core.Date#setFormat returns MMO.core.Date throws MMO.TypeErrorwhen the value cannot be read as a date
Shorthand for From(date).format(format, lang).
static Format(date, format = null, lang = null) date string | number | Date | nullformat = null ?stringMMO.core.Date#formatlang = null ?stringthe locale for the month and day names returns string
The seven day names, rotated so the week starts where you want it to.
static DayLabels(firstDayOfWeek = 1, long = true, lang = null) firstDayOfWeek = 1 number0 = sunday, 1 = monday (the default) long = true booleanfull names rather than three letter ones lang = null ?stringthe locale returns Array<string>
NOTE: a date landing exactly on midnight reports false, which is what makes a plain date render without its time.
hasTime() returns booleantrue when the date carries a time of day
Remember the format toString should use. Pass null to forget it.
setFormat(format = null) format = null ?stringMMO.core.Date#format
hasFormat() returns booleantrue when a format was set on this instance
toString() returns stringthe date in its own format, or 'D d M Y H:i'
Render for display, dropping the time when there is none to show.
toHTML() toJSON() returns stringthe RFC3339-ish form the server expects MMO.core.Date#format
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.date Date | string | numberthe date to compare with operator = null ?stringone of '<', '<=', '=', '>=', '>', '!='. null returns the raw -1|0|1 code returns number | booleanthe code when operator is null, the test's result otherwise
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. date Date | string | numberunit = 'day' stringyear|month|week|day|hour|min|sec returns numberpositive when this date is the later one throws MMO.TypeErroron an unknown unit
Test whether this date falls in a closed interval, bounds included.
isWithin(start, end) start Date | string | numberend Date | string | numberreturns boolean
Compare the calendar day only, ignoring the time.
isSameDay(date) date Date | string | numberreturns boolean
Shift this date IN PLACE by a number of units, positive or negative.
modify(number, unit) number numberunit stringyear|month|week|day|hour|min|sec returns numberthe new timestamp throws MMO.TypeErroron an unknown unit
Read one calendar field by name.
get(unit) unit stringyear|month|week|day|hour|min|sec ('month' is 0 based) returns numberthrows MMO.TypeErroron an unknown unit
Check if year is leap (29 days in february)
isLeap() Get the day of the year (1st January = 1, 31st december = 365|366)
getDayOfYear() getWeek() See http://perso.univ-lemans.fr/~hainry/articles/semaine.htmlMove this date IN PLACE to the same weekday of another week of the same year.
setWeek(value) value numberthe week number MMO.core.Date#getWeek returns numberthe new timestamp
startOfMonth() returns MMO.core.Date a NEW date on the 1st of this month, at 00:00:00.000
endOfMonth() returns MMO.core.Date a NEW date on the last day of this month, at 23:59:59.999
startOfWeek(firstDayOfWeek = 1) firstDayOfWeek = 1 number0 = sunday, 1 = monday (the default) returns MMO.core.Date a NEW date on the first day of this week, at 00:00:00.000
Get the last day of this date's week, at 23:59:59.999
endOfWeek(firstDayOfWeek = 1) firstDayOfWeek = 1 number0 = sunday, 1 = monday (the default), ... returns MMO.core.Date
startOfDay() endOfDay() Format date with a php like format
format(format = null, lang = null) format = null ?stringhttps://www.php.net/manual/en/datetime.format.phplang = null returns string