Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default datetime widget format #7386

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Fix default datetime widget format #7386

wants to merge 4 commits into from

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:

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