decap-cms
decap-cms copied to clipboard
Fix default datetime widget format
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:
- Users who haven't explicitly set
utcformat see their local timezone in the widget but the data is actually stored in UTC (due to the forced 'Z' suffix) - 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)
- When
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:
- [x] I have read the contribution guidelines.