From 3d841bd1443c375c32d7ff696011dc9f131d4d13 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Wed, 7 Jun 2017 23:22:11 +0200 Subject: [PATCH] Revert "Now the date passed to DateTimeFormat is always in UTC" This reverts commit b5a9b7c8f8ed00259f441eb1ac212a244df2ffdb. --- .../pages/components/DatePicker/ExampleInternational.js | 1 - src/DatePicker/CalendarToolbar.js | 4 +--- src/DatePicker/CalendarYear.js | 3 +-- src/DatePicker/DateDisplay.js | 7 ++----- src/DatePicker/DatePicker.js | 7 +++---- src/DatePicker/DayButton.js | 5 ++--- src/DatePicker/dateUtils.js | 9 ++------- 7 files changed, 11 insertions(+), 25 deletions(-) diff --git a/docs/src/app/components/pages/components/DatePicker/ExampleInternational.js b/docs/src/app/components/pages/components/DatePicker/ExampleInternational.js index 57dcff6c644d2b..d634a8f619d98b 100644 --- a/docs/src/app/components/pages/components/DatePicker/ExampleInternational.js +++ b/docs/src/app/components/pages/components/DatePicker/ExampleInternational.js @@ -57,7 +57,6 @@ const DatePickerExampleInternational = () => ( day: 'numeric', month: 'long', year: 'numeric', - timeZone: 'UTC', }).format} /> diff --git a/src/DatePicker/CalendarToolbar.js b/src/DatePicker/CalendarToolbar.js index 43e0ad0062efb8..62b0bf05ab1cd7 100644 --- a/src/DatePicker/CalendarToolbar.js +++ b/src/DatePicker/CalendarToolbar.js @@ -1,6 +1,5 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -import {dateUTC} from './dateUtils'; import IconButton from '../IconButton'; import NavigationChevronLeft from '../svg-icons/navigation/chevron-left'; import NavigationChevronRight from '../svg-icons/navigation/chevron-right'; @@ -71,8 +70,7 @@ class CalendarToolbar extends Component { const dateTimeFormatted = new DateTimeFormat(locale, { month: 'long', year: 'numeric', - timeZone: 'UTC', - }).format(dateUTC(displayDate)); + }).format(displayDate); return (
diff --git a/src/DatePicker/CalendarYear.js b/src/DatePicker/CalendarYear.js index e7c241afe29dd6..fc8e24cb4d20b0 100644 --- a/src/DatePicker/CalendarYear.js +++ b/src/DatePicker/CalendarYear.js @@ -50,8 +50,7 @@ class CalendarYear extends Component { const yearFormated = new DateTimeFormat(locale, { year: 'numeric', - timeZone: 'UTC', - }).format(utils.dateUTC(utils.setYear(selectedDate, year))); + }).format(utils.setYear(selectedDate, year)); const yearButton = ( diff --git a/src/DatePicker/DatePicker.js b/src/DatePicker/DatePicker.js index 46708826821af2..58e9031c0f5417 100644 --- a/src/DatePicker/DatePicker.js +++ b/src/DatePicker/DatePicker.js @@ -1,6 +1,6 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -import {dateTimeFormat, formatIso, isEqualDate, dateUTC} from './dateUtils'; +import {dateTimeFormat, formatIso, isEqualDate} from './dateUtils'; import DatePickerDialog from './DatePickerDialog'; import TextField from '../TextField'; @@ -262,8 +262,7 @@ class DatePicker extends Component { day: 'numeric', month: 'numeric', year: 'numeric', - timeZone: 'UTC', - }).format(dateUTC(date)); + }).format(date); } else { return formatIso(date); } @@ -309,7 +308,7 @@ class DatePicker extends Component { onTouchTap={this.handleTouchTap} ref="input" style={textFieldStyle} - value={this.state.date ? formatDate(dateUTC(this.state.date)) : ''} + value={this.state.date ? formatDate(this.state.date) : ''} /> {new DateTimeFormat(locale, { day: 'numeric', - timeZone: 'UTC', - }).format(dateUTC(date))} + }).format(date)} ) : ( diff --git a/src/DatePicker/dateUtils.js b/src/DatePicker/dateUtils.js index f03a65cac73f0a..71169222818d19 100644 --- a/src/DatePicker/dateUtils.js +++ b/src/DatePicker/dateUtils.js @@ -119,10 +119,10 @@ export function getWeekArray(d, firstDayOfWeek) { } export function localizedWeekday(DateTimeFormat, locale, day, firstDayOfWeek) { - const weekdayFormatter = new DateTimeFormat(locale, {weekday: 'narrow', timeZone: 'UTC'}); + const weekdayFormatter = new DateTimeFormat(locale, {weekday: 'narrow'}); const firstDayDate = getFirstDayOfWeek(); - return weekdayFormatter.format(dateUTC(addDays(firstDayDate, day + firstDayOfWeek))); + return weekdayFormatter.format(addDays(firstDayDate, day + firstDayOfWeek)); } // Convert date to ISO 8601 (YYYY-MM-DD) date string, accounting for current timezone @@ -168,10 +168,6 @@ export function yearDiff(d1, d2) { return ~~(monthDiff(d1, d2) / 12); } -export function dateUTC(date) { - return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())); -} - export const defaultUtils = { getYear, setYear, @@ -181,5 +177,4 @@ export const defaultUtils = { getFirstDayOfMonth, getWeekArray, monthDiff, - dateUTC, };