Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/components/DateTimeEditor/DateTimeEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export default class DateTimeEditor extends React.Component {
this.editorRef = React.createRef();
}

componentWillReceiveProps(props) {
this.setState({ value: props.value, text: props.value.toISOString() });
}

componentDidMount() {
document.body.addEventListener('click', this.checkExternalClick);
document.body.addEventListener('touchend', this.checkExternalClick);
Expand Down Expand Up @@ -85,9 +81,11 @@ export default class DateTimeEditor extends React.Component {
text: this.props.value.toISOString(),
});
} else {
if (this.state.text.endsWith('Z')) {
if (this.state.text.endsWith('Z') || this.state.text.endsWith('UTC')) {
// Timezone is explicit; the parsed Date is already correct.
this.setState({ value: date });
} else {
// No timezone indicator; treat input as local time.
const utc = new Date(
Date.UTC(
date.getFullYear(),
Expand Down
30 changes: 11 additions & 19 deletions src/lib/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,17 @@ export function monthsFrom(date, delta) {
}

export function dateStringUTC(date) {
let full =
String(date.getUTCDate()) +
' ' +
shortMonth(date.getUTCMonth()) +
' ' +
String(date.getUTCFullYear()) +
' at ';
const time = {
hours: String(date.getUTCHours()),
minutes: String(date.getUTCMinutes()),
seconds: String(date.getUTCSeconds()),
};
for (const k in time) {
if (time[k].length < 2) {
time[k] = '0' + time[k];
}
}
full += time.hours + ':' + time.minutes + ':' + time.seconds + ' UTC';
return full;
return date.toLocaleDateString('en-GB', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
timeZone: 'UTC',
timeZoneName: 'short',
});
}

export function monthDayStringUTC(date) {
Expand Down
Loading