Skip to content

fix(date): parse d/m/Y format and avoid mangling ISO offset strings in toDate - #2668

Merged
paales merged 1 commit into
graphcommerce-org:canaryfrom
hsngdz:fix/todate
Aug 11, 2026
Merged

fix(date): parse d/m/Y format and avoid mangling ISO offset strings in toDate#2668
paales merged 1 commit into
graphcommerce-org:canaryfrom
hsngdz:fix/todate

Conversation

@hsngdz

@hsngdz hsngdz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What

Fixes two parsing bugs in toDate.

Why

  • ISO datetime strings with a timezone offset (e.g. 2024-01-15T10:30:00-05:00) were silently corrupted into Invalid Date. The original code ran replace(/-/g, '/') on every string, not just plain YYYY-MM-DD dates, so the offset's hyphen got mangled too.
  • Strings in Magento's DATETIME_SLASH_PHP_FORMAT (d/m/Y H:i:s) were misparsed by the native Date constructor, which assumes MM/DD/YYYY for slash-separated strings. This produced either the wrong date (for ambiguous values like 01/02/2024) or undefined (for unambiguous ones like 15/01/2024).

Changes

  • Replaced the replace(/-/g, '/') string-hack entirely with explicit regex parsing + numeric Date construction (fromComponents) for both YYYY-MM-DD and d/m/Y H:i:s formats
  • d/m/Y H:i:s parsing matches Magento's confirmed day-first format (DATETIME_SLASH_PHP_FORMAT)
  • fromComponents also round-trips the constructed date against its inputs, so out-of-range values (e.g. 31/02/2026) are correctly rejected instead of being silently normalized by JS into a different, valid-looking date

Test plan

  • Added unit tests covering: null/undefined, Date instances (valid/invalid), numeric timestamps, YYYY-MM-DD, ISO with offset (regression case), d/m/Y H:i:s with/without time, ambiguous d/m/Y values, invalid strings, and invalid calendar dates

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b822462

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 87 packages
Name Type
@graphcommerce/next-ui Patch
@graphcommerce/framer-next-pages-example Patch
@graphcommerce/framer-scroller-example Patch
@graphcommerce/magento-graphcms Patch
@graphcommerce/magento-open-source Patch
@graphcommerce/magento-storyblok Patch
@graphcommerce/docs Patch
@graphcommerce/browserslist-config-pwa Patch
@graphcommerce/changeset-changelog Patch
@graphcommerce/eslint-config-pwa Patch
@graphcommerce/graphql-codegen-markdown-docs Patch
@graphcommerce/graphql-codegen-near-operation-file Patch
@graphcommerce/graphql-codegen-relay-optimizer-plugin Patch
@graphcommerce/misc Patch
@graphcommerce/next-config Patch
@graphcommerce/prettier-config-pwa Patch
@graphcommerce/typescript-config-pwa Patch
@graphcommerce/address-autocomplete Patch
@graphcommerce/address-fields-nl Patch
@graphcommerce/algolia-categories Patch
@graphcommerce/algolia-insights Patch
@graphcommerce/algolia-personalization Patch
@graphcommerce/algolia-products Patch
@graphcommerce/algolia-recommend Patch
@graphcommerce/algolia-search Patch
@graphcommerce/cli Patch
@graphcommerce/demo-magento-graphcommerce Patch
@graphcommerce/ecommerce-ui Patch
@graphcommerce/framer-next-pages Patch
@graphcommerce/framer-scroller Patch
@graphcommerce/framer-utils Patch
@graphcommerce/google-datalayer Patch
@graphcommerce/google-playstore Patch
@graphcommerce/googleanalytics Patch
@graphcommerce/googlerecaptcha Patch
@graphcommerce/googletagmanager Patch
@graphcommerce/graphcms-ui Patch
@graphcommerce/graphql-mesh Patch
@graphcommerce/graphql Patch
@graphcommerce/hygraph-cli Patch
@graphcommerce/hygraph-dynamic-rows-ui Patch
@graphcommerce/hygraph-dynamic-rows Patch
@graphcommerce/hygraph-ui Patch
@graphcommerce/image Patch
@graphcommerce/lingui-next Patch
@graphcommerce/magento-cart-checkout Patch
@graphcommerce/magento-cart-coupon Patch
@graphcommerce/magento-cart-email Patch
@graphcommerce/magento-cart-items Patch
@graphcommerce/magento-cart-payment-method Patch
@graphcommerce/magento-cart-pickup Patch
@graphcommerce/magento-cart-shipping-address Patch
@graphcommerce/magento-cart-shipping-method Patch
@graphcommerce/magento-cart Patch
@graphcommerce/magento-category Patch
@graphcommerce/magento-cms Patch
@graphcommerce/magento-compare Patch
@graphcommerce/magento-customer Patch
@graphcommerce/magento-graphql-rest Patch
@graphcommerce/magento-graphql Patch
@graphcommerce/magento-newsletter Patch
@graphcommerce/magento-payment-adyen Patch
@graphcommerce/magento-payment-afterpay Patch
@graphcommerce/magento-payment-braintree Patch
@graphcommerce/magento-payment-included Patch
@graphcommerce/magento-payment-klarna Patch
@graphcommerce/magento-payment-multisafepay Patch
@graphcommerce/magento-payment-paypal Patch
@graphcommerce/magento-payment-tokens Patch
@graphcommerce/magento-product-bundle Patch
@graphcommerce/magento-product-configurable Patch
@graphcommerce/magento-product-downloadable Patch
@graphcommerce/magento-product-grouped Patch
@graphcommerce/magento-product-simple Patch
@graphcommerce/magento-product-virtual Patch
@graphcommerce/magento-product Patch
@graphcommerce/magento-recently-viewed-products Patch
@graphcommerce/magento-review Patch
@graphcommerce/magento-search-overlay Patch
@graphcommerce/magento-search Patch
@graphcommerce/magento-store Patch
@graphcommerce/magento-wishlist Patch
@graphcommerce/mollie-magento-payment Patch
@graphcommerce/react-hook-form Patch
@graphcommerce/service-worker Patch
@graphcommerce/storyblok-ui Patch
@graphcommerce/image-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

@hsngdz is attempting to deploy a commit to the Reach Digital Team on Vercel.

A member of the Team first needs to authorize it.

@paales

paales commented Aug 10, 2026

Copy link
Copy Markdown
Member

Nice!

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
graphcommerce-247 Ready Ready Preview Aug 11, 2026 8:13am

Request Review

@paales
paales merged commit 1981787 into graphcommerce-org:canary Aug 11, 2026
3 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants