Skip to content

Commit

Permalink
Revert "Now the date passed to DateTimeFormat is always in UTC"
Browse files Browse the repository at this point in the history
This reverts commit b5a9b7c.
  • Loading branch information
oliviertassinari committed Jun 7, 2017
1 parent 1f477a3 commit 3d841bd
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const DatePickerExampleInternational = () => (
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'UTC',
}).format}
/>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/DatePicker/CalendarToolbar.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 (
<div style={styles.root}>
Expand Down
3 changes: 1 addition & 2 deletions src/DatePicker/CalendarYear.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
<YearButton
Expand Down
7 changes: 2 additions & 5 deletions src/DatePicker/DateDisplay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {dateUTC} from './dateUtils';
import transitions from '../styles/transitions';
import SlideInTransitionGroup from '../internal/SlideIn';

Expand Down Expand Up @@ -142,15 +141,13 @@ class DateDisplay extends Component {

const year = new DateTimeFormat(locale, {
year: 'numeric',
timeZone: 'UTC',
}).format(dateUTC(selectedDate));
}).format(selectedDate);

const dateTime = new DateTimeFormat(locale, {
month: 'short',
weekday: 'short',
day: '2-digit',
timeZone: 'UTC',
}).format(dateUTC(selectedDate));
}).format(selectedDate);

return (
<div {...other} style={prepareStyles(styles.root, style)}>
Expand Down
7 changes: 3 additions & 4 deletions src/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) : ''}
/>
<DatePickerDialog
DateTimeFormat={DateTimeFormat}
Expand Down
5 changes: 2 additions & 3 deletions src/DatePicker/DayButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import Transition from '../styles/transitions';
import {isEqualDate, dateUTC} from './dateUtils';
import {isEqualDate} from './dateUtils';
import EnhancedButton from '../internal/EnhancedButton';

function getStyles(props, context, state) {
Expand Down Expand Up @@ -129,8 +129,7 @@ class DayButton extends Component {
<span style={prepareStyles(styles.label)}>
{new DateTimeFormat(locale, {
day: 'numeric',
timeZone: 'UTC',
}).format(dateUTC(date))}
}).format(date)}
</span>
</EnhancedButton>
) : (
Expand Down
9 changes: 2 additions & 7 deletions src/DatePicker/dateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -181,5 +177,4 @@ export const defaultUtils = {
getFirstDayOfMonth,
getWeekArray,
monthDiff,
dateUTC,
};

0 comments on commit 3d841bd

Please sign in to comment.