pegasystems / react-sdk-components

The React SDK Components repo is used to create the @pega/react-sdk-components and @pega/react-sdk-overrides npm packages used by the Pega Constellation React SDK. These packages provide the initial set of components used by the React SDK to render DX Components with a design system other than Pega Constellation design system.
https://community.pega.com/marketplace/components/react-sdk
Apache License 2.0
2 stars 4 forks source link

Bug in parsing date-strings #378

Open wimbarelds opened 1 month ago

wimbarelds commented 1 month ago

Describe the bug https://github.com/pegasystems/react-sdk-components/blob/e4b31d449f0d9e36afc0058b5ee5bd905ffc5365/packages/react-sdk-components/src/components/helpers/formatters/index.ts#L12

The getDateObject function in @pega/react-sdk-components/src/components/helpers/formatters/index.ts interprets DateTime strings (such as "20240814T080200.000 GMT") in the local user timezone, despite the value provided clearly being in GMT.

To Reproduce Steps to reproduce the behavior:

import { format } from '@pega/react-sdk-components/lib/components/helpers/formatters';

console.log(format('20240814T080200.000 GMT', 'DateTime', {timezone: 'Europe/Amsterdam'}));

// The expected output (in Europe/Amsterdam timezone) would be:
// "Aug 14, 2024 10:02 AM"
// The actual result is
// "Aug 14, 2024 12:02 PM"

Note that, the "actual result" will differ if you run this code from a different timezone, because the input string is parsed in your local timezone regardless of all other things.

Expected behavior See above

Screenshots Not applicable

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context I will create a pull request to fix this

wimbarelds commented 1 month ago

Pull request with fix: https://github.com/pegasystems/react-sdk-components/pull/379