SystemClock: support explicit DateTimeZone in constructor #3
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
SystemClock::now()usesnew \DateTimeImmutable()which picks up the PHP/system default timezone. Code that needs to work in a specific timezone (e.g. always UTC in background jobs) must either set the global default or wrap the result — both are error-prone.Proposed API
When a
DateTimeZoneis provided,now()returnsnew \DateTimeImmutable('now', $timezone).Benefits
date_default_timezone_set()side effectsAcceptance criteria
__construct(?\DateTimeZone $timezone = null)now()uses provided timezone when setnow()falls back to system default whennull