Normalize to UTC on write vs keep locale-local with Zend_Date for cross-region dates
0 reputation · 14 Jun 2022, 12:56 UTC
0 reputation · 14 Jun 2022, 12:56 UTC
Goal is to store and display dates for users in multiple regional time zones using Zend Framework 1 Zend_Date with locale-aware parsing and formatting.
Zend_Date supports explicit timezone via setTimezone() and locale patterns via PHP Intl, and parsing falls back to Zend_Date::setDefaultTimezone() or php.ini when no timezone is supplied. The component inherits PHP DateTime's timezone database, so conversion results can vary with tzdata and PHP version across environments. Zend_Date is deprecated in ZF2+ and removed in Laminas.
For persistence, one documented approach is normalizing to UTC on write and converting on display; the alternative is storing locale-local values and converting on read. The unresolved behavior is how ambiguous or skipped local times during DST transitions in regional zones should be handled, as Zend_Date does not define a canonical policy.
Which approach provides more deterministic round-tripping for cross-region users given implicit default timezone fallback? How should ambiguous DST times be resolved when Zend_Date offers no defined policy? Is UTC normalization worth the per-request conversion cost versus locale-local storage risk?
35275 reputation · 14 Jun 2022, 18:43 UTC
Confirmed facts:
php.ini date.timezone setting, so the same absolute moment is retrieved regardless of where the code runs.Zend_Date::setDefaultTimezone('UTC'); or explicitly set the timezone on each instance before storing.$local = new Zend_Date($userInput, $localePattern, $userLocale);
$local->setTimezone('UTC');
$utcString = $local->toString(Zend_Date::ISO_8601); // store this
$utcString (e.g., as an ISO‑8601 string or Unix timestamp) in your database.$utc = new Zend_Date($storedUtcString, Zend_Date::ISO_8601);
$utc->setTimezone($userTimezone); // e.g., 'America/New_York'
$display = $utc->toString($displayPattern, $userLocale);
DateTimeZone::getTransitions and choose a policy (e.g., prefer the earlier offset) before creating the Zend_Date instance.Please confirm the server’s default timezone setting (date.timezone in php.ini or the system timezone) to verify whether the implicit fallback could already be UTC; if it is not, the recommendation to normalize to UTC remains unchanged.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.