Expand description
PHP/Laravel-style date() formatting - not a general date-parsing or
date-arithmetic library, just enough to format an already-known
chrono::DateTime<Utc> using PHP’s own format-character vocabulary
(Y, m, d, F, j, S, …), so a converted Blade date('Y-m-d')
call reads the same as the Laravel source it came from.
Exists specifically as the target of larust-convert’s Blade
expression translator (larust_convert::blade::expr::translate’s
"date" function-call arm) - that translator only ever emits a call
here after checking every character in the format string against the
same recognized set [format] below implements (kept in sync by
hand, documented on both sides, since the two live in separate crates
with no shared table to enforce it structurally).
strtotime is deliberately not a port of PHP’s real
strtotime() - that function accepts an enormous range of natural-
language and relative date expressions (“next monday”, “+3 days”),
genuinely fuzzy parsing this framework’s conversion tooling won’t
silently guess at. What’s here only recognizes the common machine-
readable timestamp shapes an Eloquent created_at/updated_at
column actually serializes as - the one real, observed use this exists
for (strtotime($model['updated_at'])) - and falls back to the
current instant rather than failing when the string doesn’t match one
of them, a deliberate best-effort choice for this specific helper
(unlike the converter’s own convert-time refusals, which are about
what’s safe to auto-generate, not what’s safe to run).
Functions§
- format
- Formats
whenusing a PHPdate()-style format string: each character is either one of the recognized format codes below or a literal passed through unchanged (PHP’s own punctuation/whitespace convention -date('Y-m-d')’s-characters are literal, not format codes). Deliberately not a complete port of PHP’sdate()- only the common codes real Blade templates use; anything else is simply emitted literally, which is safe here only becauselarust-convert’s own converter-time check already rejects any format string containing a character outside this exact set before it ever generates a call to this function - nothing reaches this function at runtime that wasn’t already vetted at convert time. - now
- The current instant -
larust_support::date::now(), Laravel’s ownnow()helper (rust-laravel.md’s “helpers worth preserving” list). - strtotime
- See this module’s own doc comment for exactly what this does and
doesn’t cover. Tried in order: RFC 3339 (
2026-08-17T12:00:00Z), MySQL/Eloquent’s owncreated_at/updated_atformat (2026-08-17 12:00:00), then a bare date (2026-08-17) - falls back tonowif none match.