Skip to content

Conversation

dfdez
Copy link
Owner

@dfdez dfdez commented Jan 30, 2025

Summary

Fix the issue described on decaporg#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:

@dfdez dfdez self-assigned this Jan 30, 2025
@dfdez dfdez changed the title fix/default date format Fix default datetime widget format Jan 30, 2025
@dfdez dfdez marked this pull request as ready for review January 30, 2025 21:44
@dfdez dfdez merged commit 10feebb into main Jan 30, 2025
@dfdez dfdez deleted the fix/default-date-format branch January 30, 2025 21:45
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.

1 participant