cDatePeriod
MMO\core\helpers · 1 symbol · generated 30 Sep 2026
cDatePeriod
cDatePeriod.php:15A calendar period granularity (day, week, month, ...), with helpers to compute its boundaries around a given date, the difference between two dates in that unit, and to shift a date by N periods.
- Namespace
MMO\core\helpers
Index
| Day | ||
| Hour | ||
| Minute | ||
| Month | ||
| Second | ||
| Semester | ||
| Trimester | ||
| Week | ||
| Year | ||
| name readonly | ||
| value readonly | ||
| boundaries($date, $count) | Get the boundaries of a period, using a date as a reference. | |
| BoundariesFromString($period, $date) static | Parse $period (FromString) then compute its boundaries. | |
| cases() static | ||
| diff($date2, $date1) | Compute the difference between first argument and second arguments (date2 - date1) | |
| from($value) static | ||
| FromString($period) static | Convert a text like 3y to [cDatePeriod::Year, 3] | |
| modify($date, $count) | Shift $date by $count periods (via DateTime::modify's relative-format string). | |
| tryFrom($value) static |
Constants9
Day
Hour
Minute
Month
Second
Semester
Trimester
Week
Year
Properties2
name
readonly- Type
- string
value
readonly- Type
- string
Methods8
boundaries($date, $count)
cDatePeriod.php:116Get the boundaries of a period, using a date as a reference.
| $date = null | DateTimeInterface | string | null | null uses the current time; if string MUST be of the format: Y(year) | Y-m (month, trimester, semester) | Y-m-d (week, day) | any format dateTime accepts (hour, minute, second) |
| $count = 1 | int | the number of periods (can be negative) |
| returns | array | \DateTimeImmutable} [start, end] |
BoundariesFromString($period, $date)
staticcDatePeriod.php:46Parse $period (FromString) then compute its boundaries.
| $period | string | e.g. '3y' |
| $date = null | DateTimeInterface | string | null | |
| returns | array | \DateTimeImmutable} [start, end] |
cases()
static| returns | array |
diff($date2, $date1)
cDatePeriod.php:58Compute the difference between first argument and second arguments (date2 - date1)
| $date2 | DateTimeInterface | string | int | |
| $date1 | DateTimeInterface | string | int | |
| returns | int |
from($value)
staticFromString($period)
staticcDatePeriod.php:36Convert a text like 3y to [cDatePeriod::Year, 3]
| $period | string | a count followed by one of the enum's value letters ('d','w','m','T','S','y','h','i','s'); the count defaults to 1 if omitted (e.g. 'd' alone means 1 day) |
| returns | array | [cDatePeriod, int] |
modify($date, $count)
cDatePeriod.php:83Shift $date by $count periods (via DateTime::modify's relative-format string).
| $date | DateTimeInterface | string | int | |
| $count = 1 | int | negative to go backward |
| returns | DateTimeInterface | a new instance if $date was int/string or already immutable; the SAME instance, modified in place, if $date is a mutable \DateTime |