From ef5ff031dab99f73468c32835e2d94311967e09c Mon Sep 17 00:00:00 2001 From: Nick Holden Date: Wed, 13 May 2020 01:44:01 -0700 Subject: [PATCH] feat: add pickerUtc option to datetime widget (#3721) I have a field that I would like to contain just a date (with no specific time). When I configure the datetime widget with sensible options for a date-only field, dates are stored properly in the saved markdown, but when I load those dates in the UI, I see the date before. This is happening because the DateTime component from the react-datetime library uses local timezones. It loads the date as the start of day UTC and then converts to the local timezone, which is going to be the previous day in any timezone with a negative UTC offset, including all of the Americas. This change adds a pickerUtc option to the datetime widget so that users can specify when they would like the datetime picker to display times in UTC rather than in the local timezone. By setting this new option to true on date-only fields, users can ensure that everyone sees the same date in the picker regardless of local timezones. --- .../netlify-cms-widget-datetime/src/DateTimeControl.js | 8 ++++++++ website/content/docs/widgets/datetime.md | 2 ++ 2 files changed, 10 insertions(+) diff --git a/packages/netlify-cms-widget-datetime/src/DateTimeControl.js b/packages/netlify-cms-widget-datetime/src/DateTimeControl.js index 0b8ffebb..a06f83f9 100644 --- a/packages/netlify-cms-widget-datetime/src/DateTimeControl.js +++ b/packages/netlify-cms-widget-datetime/src/DateTimeControl.js @@ -44,8 +44,15 @@ export default class DateTimeControl extends React.Component { return defaultValue; } + getPickerUtc() { + const { field } = this.props; + const pickerUtc = field.get('pickerUtc'); + return pickerUtc; + } + formats = this.getFormats(); defaultValue = this.getDefaultValue(); + pickerUtc = this.getPickerUtc(); componentDidMount() { const { value } = this.props; @@ -125,6 +132,7 @@ export default class DateTimeControl extends React.Component { onFocus={setActiveStyle} onBlur={this.onBlur} inputProps={{ className: classNameWrapper, id: forID }} + utc={this.pickerUtc} />