mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 00:27:41 +08:00
fix(datetime): default to local date (#17706)
This commit is contained in:
committed by
Adam Bradley
parent
eb5494e932
commit
bab56e8947
@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user