decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

Fix default datetime widget format

Open dfdez opened this issue 11 months ago • 0 comments

Summary

Fix the issue described on https://github.com/decaporg/decap-cms/issues/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 avatar Jan 30 '25 21:01 dfdez