Skip to main content

Crate php_dates

Crate php_dates 

Source
Expand description

PHP date patterns for Rust.

PhpDatePattern formats like DateTime::format() and parses like DateTime::createFromFormat(), in English, with PhpDateTime and Zone for time zones. formats resolves which pattern applies from a DateConfig and exports patterns to Day.js.

use php_dates::{PhpDatePattern, PhpDateTime, Zone};

let pattern = PhpDatePattern::compile("d/m/Y H:i T")?;
let madrid = Zone::parse("Europe/Madrid").ok_or("unknown zone")?;
let date = PhpDateTime::new(jiff::civil::date(2026, 7, 1).at(8, 30, 0, 0), madrid)?;
assert_eq!(pattern.format(&date), "01/07/2026 08:30 CEST");

jiff is re-exported: its types are part of this crate’s API. The tzdb-bundle feature builds the time zone database into the binary, for systems without one.

Re-exports§

pub use formats::Kind;
pub use formats::Purpose;
pub use jiff;

Modules§

formats
The date format contract: PHP patterns on the server; frontend_config exports the equivalent Day.js patterns.

Structs§

DateConfig
Where the date patterns of an application are configured: one per kind, one per purpose, and two legacy settings used when nothing else is set.
DatePatterns
One pattern per kind.
ParseError
Why a value did not match a pattern.
PhpDatePattern
A compiled PHP date pattern.
PhpDateTime
A date and time with its time zone: what DateTime::format() prints and createFromFormat() returns.

Enums§

Error
A date pattern that cannot be used.
Zone
A time zone, in the three forms PHP has: an identifier, an abbreviation and a fixed offset.

Type Aliases§

Result
A date pattern that failed validation.