Skip to content

Conversation

dfdez
Copy link
Contributor

@dfdez dfdez commented Jan 30, 2025

Summary

Fix the issue described on #7319

Problem

When formatting dates, we currently use the format 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' by default. This format always includes a literal 'Z' timezone indicator (due to the escaped [Z]) regardless of the user's actual timezone setting.

This is a problem because:

  1. Users who haven't explicitly set utc format see their local timezone in the widget but the data is actually stored in UTC (due to the forced 'Z' suffix)
  2. This mismatch between display and storage timezone can lead to unexpected behavior and data inconsistencies

Solution

Modified the default date formatting to only append the escaped UTC indicator ('[Z]') when picker_utc is explicitly set to true. This ensures that:

  • Dates are stored with the correct timezone information based on user settings
  • The widget's display accurately reflects how the date will be stored
  • DayJS can properly handle timezone conversions based on actual user preferences

Technical Details

  • Previous format (always): 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'
  • New format:
    • When picker_utc: true: 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'
    • When picker_utc: false: 'YYYY-MM-DDTHH:mm:ss.SSSZ' (preserves local timezone)

Test plan

Added tests to check the date widget works as expected.

To run the tests:

NODE_ENV=test npx jest --no-cache packages/decap-cms-widget-datetime/src/__tests__/DateTimeControl.spec.js

Checklist

Please add a x inside each checkbox:

@martinjagodic
Copy link
Member

@dfdez can you please run npm run format?

@demshy demshy merged commit 7893f47 into decaporg:main Jul 14, 2025
7 checks passed
@percula
Copy link

percula commented Jul 23, 2025

This PR broke sorting by date for my site.

@martinjagodic
Copy link
Member

@percula please open an issue with steps to reproduce the sorting bug.

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.

4 participants