php-dates 0.1.0

PHP date() patterns for Rust: strict createFromFormat-style parsing, a pattern resolution contract and a Day.js export, with no framework dependency
Documentation

php-dates

PHP date patterns and the shared PHP/Day.js date format contract of reynotech/laravel-query-builder-custom, as a crate with no framework or database dependency. The Rust port of reynotech/laravel-query-builder-custom uses it for its date filters.

use php_dates::{DateConfig, PhpDatePattern, formats::{self, Kind, Purpose}};

let config = DateConfig::default();
let pattern = PhpDatePattern::compile(&formats::format(&config, Kind::Date, Purpose::Filter, None)?)?;
let date = pattern.parse("10/02/2026").unwrap();
assert_eq!(pattern.format(&date), "10/02/2026");

let dayjs = formats::to_dayjs("d/m/Y h:i A")?; // "DD/MM/YYYY hh:mm A"

Patterns

Supported tokens: d j m n Y y H G h g i s a A, \x escapes and any non-letter literal. Other letters are rejected instead of being read differently. Parsing is strict: the text must read back to exactly the same text, so 2/2026 is not m/Y and 31/02/2026 is not a date.

Resolution order

formats::format picks the pattern for a kind (Date, DateTime, Month) and a purpose (Display, Value, Filter): value.<kind> or filter.<kind> for the purpose, then <kind>, then the legacy date_format_solo (date) or date_format (date-time), then the fallback the caller passes, then the default (d/m/Y, d/m/Y h:i a, m/Y).

License

MIT. See LICENSE.md.