Framework Docs Date & Time

Date & Time

The Date class provides locale-aware date and time formatting via the PHP IntlDateFormatter extension. It reads the active locale and timezone from the Core settings, so the output automatically matches the configured language.

Namespace: Wojo\Core\Date

Formatting

Method Signature Description
doDate() static doDate(string $format, string $date): string|false Format a date string. Built-in format names: 'long_date', 'short_date', 'calendar'. Pass any ICU pattern for custom formats.
doTime() static doTime(string $time): string|false Format a time string using the configured time format
doHoursTime() static doHoursTime(string $time): string|false Format as 24-hour HH:mm:ss
today() static today(string $date = '', bool $format = false): string Return current or given date in Y-m-d H:i:s (or custom format)
PHP
// Using a named format (configured in Core settings)
echo Date::doDate('long_date', '2026-06-18');   // e.g. "June 18, 2026 12:00 AM"
echo Date::doDate('short_date', '2026-06-18');  // e.g. "06-18-2026"

// Custom ICU pattern
echo Date::doDate('EEEE, MMMM d, yyyy', '2026-06-18');  // "Wednesday, June 18, 2026"

// Time
echo Date::doTime('2026-06-18 14:30:00');  // e.g. "02:30 PM"

Relative & Human-Readable

Method Signature Description
timeSince() static timeSince(string $date): string Return a human-readable "X minutes ago" string (translated)
formatSecondsToHuman() static formatSecondsToHuman(float|string|null $seconds, bool $short = true): string Convert a second count to "2 min and 15 sec"
numberOfDays() static numberOfDays(string $days, bool $format = false): string Add a relative offset (e.g. '+30 days') to today's date
compareDates() static compareDates(string|int $left, string|int $right): int Compare two dates: returns -1, 0, or 1
isWeekend() static isWeekend(string $date): bool Return true if the given date falls on Saturday or Sunday
dateLabels() static dateLabels(string $date): string Return 'primary' (today), 'positive' (future), or 'negative' (past)

Form Helpers

These methods return HTML <option> strings for use inside <select> elements, or plain arrays.

Method Description
getShortDate(string|false $selected) Dropdown of short-date format options
getLongDate(string|false $selected) Dropdown of long-date format options
getCalendarDate(string|false $selected) Dropdown of calendar date format options
getTimeFormat(string|false $selected) Dropdown: 12-hour vs. 24-hour
weekList(bool $list, string $format, string|false $selected) Locale-aware day-of-week list (long/medium/short names)
monthList(bool $list, bool $long) Locale-aware month list (full or abbreviated names)
getTimezones() Full timezone dropdown for settings forms
getPeriod(string) / getPeriodReadable(string) Translate a period code ('day', 'week', 'month', 'year') to a localized label