Expand description
Date and time: date()/DateTime::format, DateTime parsing and timezones, strtotime, microtime.
This is a port of timelib (the library inside ext/date) and of the
parts of php_date.c around it, so that dates parse, normalise, convert
between zones and format exactly as PHP 8.5 does, quirks included:
| PHP | Rust |
|---|---|
new DateTime($s, $tz) / DateTimeImmutable | DateTime::parse (explicit “now”), DateTime::new (system clock) |
DateTime::createFromFormat($f, $s, $tz) | DateTime::from_format |
->format($f), date($f, $ts), gmdate($f, $ts) | DateTime::format, date, gmdate |
->modify($s) | DateTime::modify (DateTime), DateTime::modified (DateTimeImmutable) |
->setDate($y, $m, $d) | DateTime::set_date (DateTime), DateTime::with_date (DateTimeImmutable) |
->setTime($h, $i, $s, $us) | DateTime::set_time (DateTime), DateTime::with_time (DateTimeImmutable) |
->setTimezone($tz), ->getTimezone() | DateTime::set_timezone, DateTime::timezone |
->getTimestamp(), ->getOffset(), ->getMicrosecond() | DateTime::timestamp, DateTime::offset, DateTime::microsecond |
->add(DateInterval::createFromDateString($s)) | DateTime::add, Interval::from_date_string |
$a < $b | PartialOrd / Ord on DateTime |
new DateTimeZone($name), ->getName(), ->getOffset($dt) | TimeZone::new, TimeZone::name, TimeZone::offset_at |
strtotime($s, $base) | strtotime |
date_parse($s) | date_parse (ParsedDate::to_php) |
time(), microtime(true), microtime() | time, microtime_float, microtime |
timezone_version_get(), timezone_identifiers_list() | version, identifiers |
PHP keeps a default timezone in a global (date.timezone, UTC in
Appwrite). Here it is an argument: functions that use it take a
default TzInfo (TzInfo::utc for Appwrite).
Timezone data is PHP’s own bundled database (version version), not
the system’s, so results do not depend on the host.
Not modelled: DatePeriod, DateTime::diff(), DateTime::sub(),
intervals created from ISO 8601 durations, setISODate, idate,
mktime, strftime, getdate, sunrise/sunset functions;
date_default_timezone_set (pass the zone instead).
Structs§
- Abbreviation
- A row of timelib’s abbreviation tables.
- Date
Time - A
DateTime(orDateTimeImmutable): a timelib time with its zone. - Error
- Why a date/time operation failed:
Error::php_classnames the PHP exception,Error::message_bytesis its message byte for byte (PHP quotes the input verbatim, which need not be UTF-8). - Interval
- A
DateIntervalmade byDateInterval::createFromDateString(). - Message
- One error or warning: where (byte offset in the trimmed input), the byte there, and the message.
- Messages
timelib_error_container.- Modifier
- A modifier string parsed once, to apply to many dates: what
DateTimeImmutable::modify($modifier)does, without parsing the string again each time. - Parsed
Date - What
date_parse()returns. - Timestamp
- A point in time, as
gettimeofdayreports it. - TzInfo
- A timezone identifier resolved against PHP’s database.
Enums§
- Error
Kind - The PHP exception (or error) a date/time operation raises.
- Time
Zone - A timezone, as
DateTimeZoneholds it.
Functions§
- abbreviation_
list - The rows of
timezonemap.h(DateTimeZone::listAbbreviations()data). - date
date($format, $timestamp)in the default zone.- date_
parse date_parse($datetime).- gmdate
gmdate($format, $timestamp).- identifiers
timezone_identifiers_list()order: every identifier PHP knows, aliases included.- is_
valid_ id timelib_timezone_id_is_valid.- microtime
microtime():"0.12345600 1700000000"(%.8F %ldof the fraction and the seconds).- microtime_
float microtime(true): seconds since the epoch as a float.- strtotime
strtotime($datetime, $baseTimestamp)in the default zone:Nonewhere PHP returnsfalse.- time
time().- version
timezone_version_get(): the version of the bundled database.