fix(datetime): ensure year-only values are not affected by timezone when parsing (#21309)

This commit is contained in:
Liam DeBeasi
2020-05-15 11:36:01 -04:00
committed by GitHub
parent 16a03d58ec
commit 3937101e5c
2 changed files with 6 additions and 5 deletions

View File

@ -262,13 +262,14 @@ export const getDateTime = (dateString: any = '', timeZone: any = ''): Date => {
/** /**
* Ensures that YYYY-MM-DD, YYYY-MM, * Ensures that YYYY-MM-DD, YYYY-MM,
* YYYY-DD, etc does not get affected * YYYY-DD, YYYY, etc does not get affected
* by timezones and stays on the day/month * by timezones and stays on the day/month
* that the user provided * that the user provided
*/ */
if ( if (
dateString.length === 10 || dateString.length === 10 ||
dateString.length === 7 dateString.length === 7 ||
dateString.length === 4
) { ) {
dateString += ' '; dateString += ' ';
} }

View File

@ -64,7 +64,7 @@
<ion-item> <ion-item>
<ion-label>YYYY</ion-label> <ion-label>YYYY</ion-label>
<ion-datetime id="customPickerOptions" placeholder="Custom Options" display-format="YYYY" min="1981" max="2002"></ion-datetime> <ion-datetime id="customPickerOptions" placeholder="Custom Options" display-format="YYYY" min="1981" max="2002" value="2000"></ion-datetime>
</ion-item> </ion-item>
<ion-item> <ion-item>
@ -242,10 +242,10 @@
var selectedLang = "en"; var selectedLang = "en";
var customDayShortNames = document.getElementById('customMonthShortNames'); var customDayShortNames = document.getElementById('customMonthShortNames');
customDayShortNames.monthShortNames = monthShortNamesEnglish; customDayShortNames.monthShortNames = monthShortNamesEnglish;
function toggleLanguage() { function toggleLanguage() {
selectedLang = selectedLang === 'en' ? 'fr' : 'en'; selectedLang = selectedLang === 'en' ? 'fr' : 'en';
var customMonthShortNames = document.getElementById('customMonthShortNames'); var customMonthShortNames = document.getElementById('customMonthShortNames');
var el = document.getElementById('selectedLang'); var el = document.getElementById('selectedLang');