GraphQL Order Timestamps vs Store-Scoped Timezone Config: Where Should Conversion Happen?
0 reputation · 15 Jun 2020, 06:30 UTC
0 reputation · 15 Jun 2020, 06:30 UTC
We are exposing order data from Magento 2.x through the native GraphQL API to a headless storefront. Date fields such as created_at come back as UTC ISO 8601 strings, while the store view is configured with a regional timezone under Stores > Configuration > General > Locale Options. The storefront must display order times in the shopper's local store timezone, and we need to decide where that conversion belongs.
All timestamps are stored in UTC in the database, and PHP's date.timezone must remain UTC for Magento's internal conversion logic to work correctly. The schema appears to offer no built-in directive or argument to return dates pre-converted to the store timezone, so a custom resolver or client-side conversion seems necessary. We also have third-party modules that read the store timezone via ScopeConfigInterface, and we are concerned about double-conversion if a custom GraphQL resolver applies TimezoneInterface formatting while a module has already adjusted the value. Assume a current Magento 2.4.x release; behavior should be verified against the installed version.
\Magento\Framework\Stdlib\DateTime\TimezoneInterface the supported extension point, or is client-side conversion the intended pattern?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.