Rust

datetime

Module

Date and time: date()/DateTime::format, DateTime parsing and timezones, strtotime, microtime.

Every function here is checked against the real PHP function by bin/compat fuzz php-std (operations datetime.*).

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:

PHPRust
new DateTime($s, $tz) / DateTimeImmutableDateTime::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 < $bPartialOrd / 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).

Contents

8 submodules, and what the module defines itself.

use php_std::datetime::DateTime;
Rust
pub struct DateTime

A DateTime (or DateTimeImmutable): a timelib time with its zone.

== and < compare instants, as PHP's do (timelib_time_compare): the same moment in two zones is equal.

Also implements PartialEq, PartialOrd.
use php_std::datetime::Error;
Rust
pub struct Error

Why a date/time operation failed: Error::php_class names the PHP exception, Error::message_bytes is its message byte for byte (PHP quotes the input verbatim, which need not be UTF-8).

Also implements Display.
use php_std::datetime::Interval;
Rust
pub struct Interval(RelTime)

A DateInterval made by DateInterval::createFromDateString().

use php_std::datetime::Modifier;
Rust
pub struct Modifier(Time)

A modifier string parsed once, to apply to many dates: what DateTimeImmutable::modify($modifier) does, without parsing the string again each time.

Rust
use php_std::datetime::{DateTime, Modifier, Timestamp, TzInfo};

let next_day = Modifier::parse(b"+1 day")?;
let at = DateTime::parse(b"2026-03-28 12:00", Some(&php_std::datetime::TimeZone::new("Europe/Paris")?), &TzInfo::utc(), Timestamp { sec: 0, usec: 0 })?;
assert_eq!(at.modified_by(&next_day).format(b"Y-m-d H:i T"), b"2026-03-29 12:00 CEST");
assert_eq!(at.modified_by(&next_day), at.modified(b"+1 day")?);
use php_std::datetime::ParsedDate;
Rust
pub struct ParsedDate

What date_parse() returns.

use php_std::datetime::Timestamp;
Rust
pub struct Timestamp

A point in time, as gettimeofday reports it.

use php_std::datetime::ErrorKind;
Rust
pub enum ErrorKind

The PHP exception (or error) a date/time operation raises.

use php_std::datetime::TimeZone;
Rust
pub enum TimeZone

A timezone, as DateTimeZone holds it.

use php_std::datetime::date;
Rust
pub fn date(format: &[u8], timestamp: i64, default: &TzInfo) -> Vec<u8>

date($format, $timestamp) in the default zone.

use php_std::datetime::date_parse;
Rust
pub fn date_parse(datetime: &[u8]) -> ParsedDate

date_parse($datetime).

use php_std::datetime::gmdate;
Rust
pub fn gmdate(format: &[u8], timestamp: i64) -> Vec<u8>

gmdate($format, $timestamp).

use php_std::datetime::microtime;
Rust
pub fn microtime() -> String

microtime(): "0.12345600 1700000000" (%.8F %ld of the fraction and the seconds).

use php_std::datetime::microtime_float;
Rust
pub fn microtime_float() -> f64

microtime(true): seconds since the epoch as a float.

use php_std::datetime::strtotime;
Rust
pub fn strtotime(datetime: &[u8], base: i64, default: &TzInfo) -> Option<i64>

strtotime($datetime, $baseTimestamp) in the default zone: None where PHP returns false.

use php_std::datetime::time;
Rust
pub fn time() -> i64

time().

datetime::abbreviations

Own page

Generated by data/timezonedb.py from timelib's timezonemap.h and fallbackmap.h: do not edit.

Rust
pub type Row = (&'static str, i32, i32, Option<&'static str>)

An abbreviation row: name, DST flag, UTC offset in seconds, zone identifier.

datetime::format

Own page

date_format() of php_date.c: the formatter behind date(), gmdate() and DateTimeInterface::format().

use php_std::datetime::format::date_format;
Rust
pub fn date_format(format: &[u8], t: &Time, localtime: bool) -> Vec<u8>

date_format(format, t, localtime): PHP's output, byte for byte.

datetime::from_format

Own page

timelib_parse_from_format with PHP's default format map: the parser behind DateTime::createFromFormat() and date_parse_from_format().

use php_std::datetime::from_format::parse_from_format;
Rust
pub fn parse_from_format(format: &[u8], string: &[u8]) -> (Time, Messages)

timelib_parse_from_format.

datetime::parse

Own page

timelib_strtotime (parse_date.re): PHP's free-form date/time parser, used by strtotime(), date_parse(), new DateTime(), DateTime::modify() and DateInterval::createFromDateString().

use php_std::datetime::parse::Message;
Rust
pub struct Message

One error or warning: where (byte offset in the trimmed input), the byte there, and the message.

use php_std::datetime::parse::Messages;
Rust
pub struct Messages

timelib_error_container.

use php_std::datetime::parse::RelUnit;
Rust
pub struct RelUnit

A relative time word: its name, unit and multiplier (timelib_relunit).

use php_std::datetime::parse::Unit;
Rust
pub enum Unit

The unit of a relative time word (timelib_relunit).

use php_std::datetime::parse::is_c_space;
Rust
pub fn is_c_space(c: u8) -> bool

C isspace in the C locale.

use php_std::datetime::parse::strtotime;
Rust
pub fn strtotime(input: &[u8]) -> (Time, Messages)

timelib_strtotime: the parsed (unnormalized) time and the errors and warnings, positions relative to the input with surrounding whitespace removed.

datetime::scanner

Own page

The matching engine for timelib's re2c scanner: a Thompson NFA built from the rule definitions of parse_date.re, simulated to find what the re2c DFA finds: the longest match over all rules, the earliest rule on a tie.

The simulation is cached as a lazily built DFA (each set of NFA states seen becomes a DFA state, each transition is computed once), so a format seen before is scanned at one table lookup per byte.

use php_std::datetime::scanner::ByteSet;
Rust
pub struct ByteSet([u64; 4])

A set of bytes.

use php_std::datetime::scanner::Lazy;
Rust
pub struct Lazy(OnceLock<Nfa>, fn() -> Vec<P>)

A lazily built NFA.

use php_std::datetime::scanner::Nfa;
Rust
pub struct Nfa

All rules compiled into one NFA.

use php_std::datetime::scanner::P;
Rust
pub enum P

A pattern (a re2c regular expression).

use php_std::datetime::scanner::alt;
Rust
pub fn alt(ps: Vec<P>) -> P

A pattern matching any one of ps.

use php_std::datetime::scanner::ci;
Rust
pub fn ci(s: &str) -> P

'...': an ASCII case-insensitive literal.

use php_std::datetime::scanner::digit;
Rust
pub fn digit() -> P

A pattern matching one ASCII digit.

use php_std::datetime::scanner::lit;
Rust
pub fn lit(s: &str) -> P

"...": a case-sensitive literal.

use php_std::datetime::scanner::opt;
Rust
pub fn opt(p: P) -> P

A pattern matching p or nothing.

use php_std::datetime::scanner::plus;
Rust
pub fn plus(p: P) -> P

A pattern matching p one or more times.

use php_std::datetime::scanner::range;
Rust
pub fn range(a: u8, b: u8) -> P

[a-b].

use php_std::datetime::scanner::ranges;
Rust
pub fn ranges(rs: &[(u8, u8)]) -> P

A union of byte ranges.

use php_std::datetime::scanner::rep;
Rust
pub fn rep(p: P, min: u32, max: u32) -> P

A pattern matching p from min to max times.

use php_std::datetime::scanner::seq;
Rust
pub fn seq(ps: Vec<P>) -> P

A pattern matching each of ps in turn.

use php_std::datetime::scanner::set;
Rust
pub fn set(chars: &str) -> P

[...] of the listed bytes.

use php_std::datetime::scanner::star;
Rust
pub fn star(p: P) -> P

A pattern matching p zero or more times.

datetime::timelib

Own page

timelib's broken-down time and its arithmetic: timelib_time, timelib_rel_time, tm2unixtime.c, unixtime2tm.c, dow.c, interval.c (timelib_add).

Field names and semantics follow timelib (C's 64-bit arithmetic wraps where timelib's would, so extreme inputs give PHP's results too).

use php_std::datetime::timelib::Broken;
Rust
pub struct Broken

The date and time fields timelib_unixtime2gmt derives from a timestamp.

use php_std::datetime::timelib::RelTime;
Rust
pub struct RelTime

timelib_rel_time.

use php_std::datetime::timelib::Time;
Rust
pub struct Time

timelib_time.

Also implements Default.
use php_std::datetime::timelib::date_from_epoch_days;
Rust
pub fn date_from_epoch_days(epoch_days: i64) -> (i64, i64, i64)

timelib_date_from_epoch_days.

use php_std::datetime::timelib::day_of_week;
Rust
pub fn day_of_week(y: i64, m: i64, d: i64) -> i64

timelib_day_of_week: 0 (Sunday) to 6.

use php_std::datetime::timelib::day_of_year;
Rust
pub fn day_of_year(y: i64, m: i64, d: i64) -> i64

timelib_day_of_year: 0-based.

use php_std::datetime::timelib::daynr_from_weeknr;
Rust
pub fn daynr_from_weeknr(iy: i64, iw: i64, id: i64) -> i64

timelib_daynr_from_weeknr.

use php_std::datetime::timelib::days_in_month;
Rust
pub fn days_in_month(y: i64, m: i64) -> i64

timelib_days_in_month.

use php_std::datetime::timelib::epoch_days_from_time;
Rust
pub fn epoch_days_from_time(y: i64, m: i64, d: i64) -> i64

timelib_epoch_days_from_time.

use php_std::datetime::timelib::hms_to_seconds;
Rust
pub fn hms_to_seconds(h: i64, m: i64, s: i64) -> i64

timelib_hms_to_seconds.

use php_std::datetime::timelib::is_leap;
Rust
pub fn is_leap(y: i64) -> bool

timelib_is_leap (C remainder semantics).

use php_std::datetime::timelib::iso_day_of_week;
Rust
pub fn iso_day_of_week(y: i64, m: i64, d: i64) -> i64

timelib_iso_day_of_week: 1 (Monday) to 7.

use php_std::datetime::timelib::isoweek_from_date;
Rust
pub fn isoweek_from_date(y: i64, m: i64, d: i64) -> (i64, i64)

timelib_isoweek_from_date: ISO week and ISO year.

use php_std::datetime::timelib::unixtime2gmt;
Rust
pub fn unixtime2gmt(ts: i64) -> Broken

timelib_unixtime2gmt (the computation only).

use php_std::datetime::timelib::valid_date;
Rust
pub fn valid_date(y: i64, m: i64, d: i64) -> bool

timelib_valid_date.

use php_std::datetime::timelib::valid_time;
Rust
pub fn valid_time(h: i64, i: i64, s: i64) -> bool

timelib_valid_time.

Rust
pub const FIRST_DAY_OF_MONTH: i32 = 1

TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH: first day of.

Rust
pub const LAST_DAY_OF_MONTH: i32 = 2

TIMELIB_SPECIAL_LAST_DAY_OF_MONTH: last day of.

Rust
pub const SPECIAL_DAY_OF_WEEK_IN_MONTH: u32 = 2

TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH: first monday of.

Rust
pub const SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH: u32 = 3

TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH: last monday of.

Rust
pub const SPECIAL_WEEKDAY: u32 = 1

TIMELIB_SPECIAL_WEEKDAY: +N weekdays.

Rust
pub const UNSET: i64 = -9999999

TIMELIB_UNSET: a field the parser did not set.

Rust
pub const ZONETYPE_ABBR: u32 = 2

TIMELIB_ZONETYPE_ABBR: an abbreviation (EST).

Rust
pub const ZONETYPE_ID: u32 = 3

TIMELIB_ZONETYPE_ID: an identifier (Europe/Paris).

Rust
pub const ZONETYPE_NONE: u32 = 0

TIMELIB_ZONETYPE_NONE: no zone.

Rust
pub const ZONETYPE_OFFSET: u32 = 1

TIMELIB_ZONETYPE_OFFSET: a UTC offset (+05:30).

datetime::tz

Own page

PHP's bundled timezone database and timelib's lookups over it (parse_tz.c, parse_posix.c, the abbreviation search of parse_date.re).

The data is PHP's own (data/timezonedb.bin, extracted from the timezonedb.h of the PHP version under test by data/timezonedb.py), so zone names, transitions and abbreviations are PHP's, not the system's.

use php_std::datetime::tz::Abbreviation;
Rust
pub struct Abbreviation

A row of timelib's abbreviation tables.

use php_std::datetime::tz::Offset;
Rust
pub struct Offset

What timelib_get_time_zone_info reports for an instant.

use php_std::datetime::tz::TzInfo;
Rust
pub struct TzInfo

A timezone identifier resolved against PHP's database.

The name is kept as it was requested (europe/paris stays lowercase), as timelib does.

Also implements Debug, PartialEq.
use php_std::datetime::tz::ZoneData;
Rust
pub struct ZoneData

The data of one zone (timelib_tzinfo without its name).

use php_std::datetime::tz::abbreviations;
Rust
pub fn abbreviations() -> impl Iterator<Item = Abbreviation>

The rows of timezonemap.h (DateTimeZone::listAbbreviations() data).

use php_std::datetime::tz::identifiers;
Rust
pub fn identifiers() -> impl Iterator<Item = &'static str>

timezone_identifiers_list() order: every identifier PHP knows, aliases included.

use php_std::datetime::tz::is_valid_id;
Rust
pub fn is_valid_id(name: &str) -> bool

timelib_timezone_id_is_valid.

use php_std::datetime::tz::strcasecmp;
Rust
pub fn strcasecmp(a: &[u8], b: &[u8]) -> i32

timelib_strcasecmp: ASCII case-insensitive, byte-wise, then by length.

use php_std::datetime::tz::version;
Rust
pub fn version() -> &'static str

timezone_version_get(): the version of the bundled database.

datetime::tzindex

Own page

Generated by data/timezonedb.py from PHP's timezonedb.h: do not edit.

Rust
pub const VERSION: &str = "2026.3"

timezone_version_get().