Skip to main content

php_dates/
lib.rs

1//! PHP date patterns for Rust.
2//!
3//! [`PhpDatePattern`] formats like `DateTime::format()` and parses like `DateTime::createFromFormat()`, in English,
4//! with [`PhpDateTime`] and [`Zone`] for time zones. [`formats`] resolves which pattern applies from a
5//! [`DateConfig`] and exports patterns to Day.js.
6//!
7//! ```
8//! use php_dates::{PhpDatePattern, PhpDateTime, Zone};
9//!
10//! let pattern = PhpDatePattern::compile("d/m/Y H:i T")?;
11//! let madrid = Zone::parse("Europe/Madrid").ok_or("unknown zone")?;
12//! let date = PhpDateTime::new(jiff::civil::date(2026, 7, 1).at(8, 30, 0, 0), madrid)?;
13//! assert_eq!(pattern.format(&date), "01/07/2026 08:30 CEST");
14//! # Ok::<(), Box<dyn std::error::Error>>(())
15//! ```
16//!
17//! [`jiff`] is re-exported: its types are part of this crate's API. The `tzdb-bundle` feature builds the time zone
18//! database into the binary, for systems without one.
19
20#![warn(missing_docs)]
21
22mod config;
23mod error;
24mod format;
25pub mod formats;
26mod names;
27mod parse;
28mod pattern;
29mod zone;
30
31pub use config::{DateConfig, DatePatterns};
32pub use error::{Error, Result};
33pub use formats::{Kind, Purpose};
34/// The date library whose types this crate takes and returns.
35pub use jiff;
36pub use parse::ParseError;
37pub use pattern::PhpDatePattern;
38pub use zone::{PhpDateTime, Zone};
39
40/// The examples of the README are compiled and run as tests.
41#[cfg(doctest)]
42#[doc = include_str!("../README.md")]
43struct ReadmeDoctests;