fix(datetime): default to local date (#17706)

This commit is contained in:
Liam DeBeasi
2019-03-11 10:46:17 -04:00
committed by Adam Bradley
parent eb5494e932
commit bab56e8947
3 changed files with 75 additions and 3 deletions

View File

@ -307,6 +307,19 @@ export class Datetime implements ComponentInterface {
text: this.doneText,
handler: (data: any) => {
this.updateDatetimeValue(data);
/**
* Prevent convertDataToISO from doing any
* kind of transformation based on timezone
* This cancels out any change it attempts to make
*
* Important: Take the timezone offset based on
* the date that is currently selected, otherwise
* there can be 1 hr difference when dealing w/ DST
*/
const date = new Date(convertDataToISO(this.datetimeValue));
this.datetimeValue.tzOffset = date.getTimezoneOffset() * -1;
this.value = convertDataToISO(this.datetimeValue);
}
}
@ -360,6 +373,7 @@ export class Datetime implements ComponentInterface {
// cool, we've loaded up the columns with options
// preselect the option for this column
const optValue = getDateValue(this.datetimeValue, format);
const selectedIndex = colOptions.findIndex(opt => opt.value === optValue);
return {
@ -527,6 +541,7 @@ export class Datetime implements ComponentInterface {
private getText() {
// create the text of the formatted data
const template = this.displayFormat || this.pickerFormat || DEFAULT_FORMAT;
return renderDatetime(template, this.datetimeValue, this.locale);
}