# rsimple_date
PHP-style `date()` formatting for Rust.
If you know `date("Y-m-d H:i:s")` from PHP, you can use the same format tokens in Rust — no need to learn Chrono’s strftime-style `%Y-%m-%d %H:%M:%S` for everyday formatting.
Chrono is used **internally** and is not part of this crate’s public API.
## Quick start
```toml
[dependencies]
rsimple_date = "0.1"
```
```rust
use rsimple_date::{date, date_with, gmdate, gmdate_with, time, DATE_ATOM};
fn main() {
// Current local time
println!("{}", date("Y-m-d H:i:s"));
// Escaped literals (same as PHP)
println!("{}", date(r"l jS \of F Y h:i:s A"));
// Fixed Unix timestamp in UTC
println!("{}", gmdate_with("Y-m-d H:i:s", 978307200)); // 2001-01-01 00:00:00
// Predefined PHP constants
println!("{}", gmdate(DATE_ATOM));
println!("{}", time());
}
```
## API
| `date(format)` | `date($format)` | Format current **local** time |
| `date_with(format, ts)` | `date($format, $ts)` | Format Unix timestamp in **local** TZ |
| `gmdate(format)` | `gmdate($format)` | Format current **UTC** time |
| `gmdate_with(format, ts)` | `gmdate($format, $ts)` | Format Unix timestamp in **UTC** |
| `time()` | `time()` | Current Unix timestamp (seconds) |
Also exports PHP-style constants such as `DATE_ATOM`, `DATE_RFC2822`, `DATE_RSS`, …
## Format tokens
Supports the common PHP [`DateTimeInterface::format`](https://www.php.net/manual/en/datetime.format.php) characters, including:
- **Date:** `Y` `y` `m` `n` `d` `j` `F` `M` `D` `l` `N` `w` `z` `W` `t` `L` `o` `S`
- **Time:** `H` `G` `h` `g` `i` `s` `a` `A` `B` `u` `v`
- **TZ:** `e` `I` `O` `P` `p` `T` `Z` (best-effort without a TZ database)
- **Full:** `c` `r` `U`
- **Escape:** `\X` prints literal `X`
Unrecognized characters are copied through as literals (PHP behavior).
## Limitations
- Chrono is an **internal** dependency; you do not import or learn Chrono to use this crate.
- Offset tokens (`O`, `P`, `p`, `Z`) reflect the real UTC offset.
- Without an IANA timezone database, `e` / `T` are best-effort (`"UTC"` or an offset string), and `I` (DST) is always `"0"`.
- Extremely out-of-range Unix timestamps are clamped to the Unix epoch so formatting never panics.
## License
Licensed under either of
- Apache License, Version 2.0
- MIT license
at your option.
## Links
- [Repository](https://github.com/praburaj0605/rsimple_date)
- [Documentation](https://docs.rs/rsimple_date)
- [crates.io](https://crates.io/crates/rsimple_date)