Index

MMO\core\dates

MMO\core\dates · 19 symbols · generated 30 Sep 2026

function

dateTime

dates.php:202

The framework's all-purpose date parser: turns a timestamp, a DateTimeInterface, or a string into a DateTime/DateTimeImmutable, trying (in order) an explicit $format, an ISO-8601 duration (a string starting with 'P', relative to now), then PHP's own lenient string parser -- with one adjustment: for a non-MDY $language (isMDYFormat()), a dd/mm/yyyy-shaped string has its / swapped to - first, since PHP's native parser otherwise always reads slash-separated dates as month/day/year regardless of locale.

function dateTime( DateTimeInterface|string|int $dateTime = 'now', ?string $format = null, ?bool $immutable = null, string $language = MMO\core\dates\LANGUAGE ): DateTimeInterface
Namespace
MMO\core\dates
$dateTime = 'now'DateTimeInterface | string | inta unix timestamp, an existing date, 'now', an ISO-8601 duration ('P...'), or any string PHP's DateTime understands
$format = nullnull | stringan explicit \DateTime::createFromFormat()-compatible format to try first
$immutable = nullnull | booltrue/false to force DateTime/DateTimeImmutable; null keeps $dateTime's own type if it's already a DateTimeInterface, else defaults to mutable DateTime
$language = MMO\core\dates\LANGUAGEstringused only to decide the / day/month disambiguation above
returnsDateTimeInterface
dateTime('2024-01-01'); // DateTime for 2024-01-01 00:00:00 dateTime(1704067200); // DateTime from a unix timestamp dateTime('01/02/2024', language: 'fr_FR'); // 2024-02-01 (day/month/year, not the US month/day/year) dateTime('now', null, true); // a DateTimeImmutable
Call graph
function

dateTimeFromInterval

dates.php:246

Apply an interval/modifier to a date, always returning a DateTimeImmutable.

function dateTimeFromInterval( DateInterval|string $interval, DateTimeInterface|string|int $dateTime = 'now' ): DateTimeImmutable
Namespace
MMO\core\dates
$intervalDateInterval | stringcan be : - a DateInterval instance, added to $dateTime - a date interval format (starting with 'P'), added to $dateTime (ISO-8601) - a date time modifier applied to $dateTime (PHP relative formats)
$dateTime = 'now'DateTimeInterface | string | intthe base date (dateTime())
returnsDateTimeImmutable
throwsif $interval is a string that is neither an ISO-8601 duration nor a valid date/time modifier
dateTimeFromInterval('P1D', '2024-01-01'); // 2024-01-02 dateTimeFromInterval('+1 day', '2024-01-01'); // 2024-01-02 dateTimeFromInterval(new DateInterval('P1D')); // tomorrow, relative to now
Call graph

Uses (1)

Used by (1)

function

format

dates.php:269

Format a date, then translate its month/day names to $lang (translateDate()).

function format( string $format = 'l d F Y', DateTimeInterface|string|int $date = 'now', string $lang = MMO\core\dates\LANGUAGE )
Namespace
MMO\core\dates
Todo
replace by I18n module
NOTE: a bare `!` in $format is stripped (it has no meaning to \DateTime::format(), only to \DateTime::createFromFormat() -- [`validate()`](https://mmoframework.fr/documentation/mmo.core/php/dates.md#validate) for where that distinction matters); an escaped `\!` (meaning a literal '!' character in the output) is preserved.
$format = 'l d F Y'stringa \DateTime::format()-compatible format string
$date = 'now'DateTimeInterface | string | intdateTime()
$lang = MMO\core\dates\LANGUAGEstringa locale code passed to translateDate()
returns
format('l d F Y', '2024-01-01'); // 'Monday 01 January 2024'
Call graph
function

getDayNames

dates.php:130

Get the 7 day names for $lang, in week order (Monday first).

function getDayNames(bool $short = false, string $lang = MMO\core\dates\LANGUAGE)
Namespace
MMO\core\dates
Todo
replace by I18n module
$short = falseboolif true, return the abbreviated names
$lang = MMO\core\dates\LANGUAGEstringa locale code (e.g. 'fr_FR') -- see the same caveat as getMonthNames()
returns
throwsif $lang has no translation table
getDayNames(true, 'fr_FR')[0]; // 'Lun'
function

getFrenchBusinessDays

dates.php:447

Same as getWorkingDays(), but automatically excludes French public holidays (getFrenchHolidays()) for every year the range spans (not just $startDate's year -- a range crossing into a new year must also exclude that year's holidays, New Year's Day included).

function getFrenchBusinessDays( DateTimeInterface|int $startDate, DateTimeInterface|int $endDate, bool $alsace_moselle = false ): int
Namespace
MMO\core\dates
$startDateDateTimeInterface | int
$endDateDateTimeInterface | int
$alsace_moselle = falseboolgetFrenchHolidays()
returnsintnumbers of days
getFrenchBusinessDays(strtotime('2024-12-30'), strtotime('2025-01-02')); // 3 (excludes New Year's Day)
Call graph
function

getFrenchHolidays

dates.php:309

Get every French public holiday of a given year, as ['Y-m-d' => 'name', ...], sorted by date. Cached per year (and per $alsace_moselle) for the rest of the request.

function getFrenchHolidays(?int $year = null, bool $alsace_moselle = false)
Namespace
MMO\core\dates
$year = nullnull | intnull for the current year
$alsace_moselle = falseboolif true, also include the two holidays specific to the Alsace-Moselle region (Good Friday, Saint Stephen's Day)
returns
getFrenchHolidays(2024)['2024-12-25']; // 'Noël'
Call graph
function

getMonthNames

dates.php:116

Get the 12 month names for $lang, in calendar order (January first).

function getMonthNames(bool $short = false, string $lang = MMO\core\dates\LANGUAGE)
Namespace
MMO\core\dates
Todo
replace by I18n module
$short = falseboolif true, return the abbreviated names
$lang = MMO\core\dates\LANGUAGEstringa locale code (e.g. 'fr_FR') -- NOTE: unlike translateDate(), English is NOT a built-in special case here; only locales present in MONTHS_i18n/MONTHS_SHORT_i18n work.
returns
throwsif $lang has no translation table
getMonthNames(false, 'fr_FR')[0]; // 'Janvier'
function

getWorkingDays

dates.php:382

Compute the number of working days (Mon-Fri, minus $holidays) between two dates, both inclusive.

function getWorkingDays( DateTimeInterface|int $startDate, DateTimeInterface|int $endDate, array $holidays = [] ): int
Namespace
MMO\core\dates
$startDateDateTimeInterface | int
$endDateDateTimeInterface | int
$holidays = []arraya list of dates (anything \strtotime() accepts) to also exclude, in addition to weekends
returnsint
getWorkingDays(strtotime('2024-06-03'), strtotime('2024-06-07')); // 5 (a full Mon-Fri week) getWorkingDays(strtotime('2024-06-03'), strtotime('2024-06-07'), ['2024-06-05']); // 4 (one holiday inside)
Call graph
function

isFrenchHoliday

dates.php:363

Tells if a date is a French public holiday (getFrenchHolidays()).

function isFrenchHoliday(?DateTimeInterface $date = null, bool $alsace_moselle = false): bool
Namespace
MMO\core\dates
$date = nullnull | DateTimeInterfacenull for today
$alsace_moselle = falseboolgetFrenchHolidays()
returnsbool
isFrenchHoliday(new DateTime('2024-12-25')); // true
Call graph
function

isMDYFormat

dates.php:86
function isMDYFormat(string $language = MMO\core\dates\LANGUAGE): bool
Namespace
MMO\core\dates
$language = MMO\core\dates\LANGUAGEstring
returnsbool
Call graph

Used by (1)

function

json

dates.php:281

Format a date as ISO 8601 (c), for JSON output.

function json(mixed $date): string
Namespace
MMO\core\dates
$datemixeddateTime() (already a DateTimeInterface is used as-is)
returnsstring
json('2024-01-01'); // '2024-01-01T00:00:00+00:00'
Call graph
function

nearestWeekDay

dates.php:475

Get the closest week day (MON-FRI) to the given date: a Saturday snaps back to Friday, a Sunday snaps forward to Monday. When $allowMonthSpan is false and that snap would cross into the previous/next month, it snaps the OTHER direction instead (2 days) so the result always stays within the same month: a Saturday that's the 1st of the month jumps forward to Monday (the 3rd); a Sunday that's the last day of the month jumps backward to Friday.

function nearestWeekDay(DateTimeInterface $date, bool $allowMonthSpan = false): DateTimeImmutable
Namespace
MMO\core\dates
$dateDateTimeInterface
$allowMonthSpan = falseboolif true, the result is allowed to land in the previous/next month
returnsDateTimeImmutable
nearestWeekDay(new DateTime('2024-06-08')); // 2024-06-07 (Sat -> Fri) nearestWeekDay(new DateTime('2024-06-16')); // 2024-06-17 (Sun -> Mon) nearestWeekDay(new DateTime('2024-06-01')); // 2024-06-03 (Sat, 1st of month -> Mon, stays in June) nearestWeekDay(new DateTime('2024-06-30')); // 2024-06-28 (Sun, last of month -> Fri, stays in June) nearestWeekDay(new DateTime('2024-06-30'), true); // 2024-07-01 (month span explicitly allowed)
Call graph
function

numberOfDays

dates.php:582

Compute the total number of distinct days covered by a list of (possibly overlapping) day intervals, by merging them first (unionOfDayIntervals()) so an overlapping day is only counted once.

function numberOfDays(bool $ignoreTime = true, DateTimeInterface ...$dates): int
Namespace
MMO\core\dates
$ignoreTime = trueboolunionOfDayIntervals()
...$datesDateTimeInterface
returnsint
numberOfDays(true, new DateTime('2025-01-05'), new DateTime('2025-01-05')); // 1 numberOfDays(true, new DateTime('2025-01-05'), new DateTime('2025-01-11'), new DateTime('2025-01-06'), new DateTime('2025-01-14') ); // 10 -- the overlap is merged first (05..14), not 7+9=16
Call graph
function

RFC

dates.php:292

Format a timestamp per RFC 1123/2822 (RFC_FORMAT), as used in HTTP dates and email headers.

function RFC(?int $timestamp = null): string
Namespace
MMO\core\dates
$timestamp = nullnull | inta unix timestamp. null for the current time.
returnsstring
RFC(1704067200); // 'Mon, 1 Jan 2024 00:00:00 +0000'
Call graph
function

setTimezone

dates.php:145

Set the default timezone for the rest of the request (date_default_timezone_set()).

function setTimezone(string $timezone): void
Namespace
MMO\core\dates
$timezonestringe.g. 'Europe/Paris', 'UTC'
returnsvoid
function

timezone

dates.php:136
function timezone(): DateTimeZone
Namespace
MMO\core\dates
returnsDateTimeZonethe current default timezone (date_default_timezone_get()), as an object
Call graph

Used by (1)

function

translateDate

dates.php:91
function translateDate(string $date, string $lang = MMO\core\dates\LANGUAGE): string
Namespace
MMO\core\dates
$datestring
$lang = MMO\core\dates\LANGUAGEstring
returnsstring
Call graph

Used by (1)

function

unionOfDayIntervals

dates.php:520

Merge a list of (possibly overlapping or adjacent) day intervals into the smallest set of non-overlapping intervals that covers the same days. Intervals are passed flattened as consecutive [start, end] pairs.

function unionOfDayIntervals(bool $ignoreTime = true, DateTimeInterface ...$dates): array
Namespace
MMO\core\dates
NOTE: the pairs don't need to be given in any particular order, but within each pair start MUST be <= end.
$ignoreTime = trueboolif true (default), every date's time-of-day is normalized before merging: a start date's time becomes 00:00:00, an end date's becomes 24:00:00 (i.e. midnight at the START of the FOLLOWING day) -- so a single-day interval like 2025-01-01..2025-01-01 is treated as the full day, and the returned end date is exclusive: it is one day AFTER the last day actually covered, not the last covered day itself.
...$datesDateTimeInterface
returnsarraya flat list of merged, non-overlapping [start, end] pairs, in chronological order
unionOfDayIntervals(true, new DateTime('2025-01-05'), new DateTime('2025-01-11'), new DateTime('2025-01-06'), new DateTime('2025-01-14'), new DateTime('2025-01-06'), new DateTime('2025-01-06'), new DateTime('2025-01-16'), new DateTime('2025-01-18'), new DateTime('2025-01-17'), new DateTime('2025-01-24'), ); // 2 merged pairs, formatted 'Y-m-d': // 2025-01-05 .. 2025-01-15 (covers through the 14th; the 15th is the exclusive end) // 2025-01-16 .. 2025-01-25 (covers through the 24th; the 25th is the exclusive end)
Call graph

Used by (1)

function

validate

dates.php:167

Test if $value can be parsed by \DateTime::createFromFormat() using $format, AND round-trips back to exactly the same string when re-formatted -- i.e. it's not just loosely/partially parseable (e.g. PHP's parser is lenient about e.g. '2024-1-1' matching 'Y-m-d', but that wouldn't round-trip back to '2024-1-1').

function validate(string $value, string $format): bool
Namespace
MMO\core\dates
$valuestringthe string to validate
$formatstringa \DateTime::createFromFormat()-compatible format string. A leading !/| reset-flag (if any -- DATE_FORMATS for where this framework uses one) is stripped before the round-trip re-format: those flags are parse-only, \DateTime::format() has no notion of them and would otherwise emit them as a literal character, which could never match $value.
returnsbool
validate('2024-01-01', '!Y-m-d'); // true validate('2024-13-01', '!Y-m-d'); // false -- month 13 doesn't exist validate('not-a-date', '!Y-m-d'); // false
Call graph

Used by (1)