diff --git a/src/scripts/OSFramework/OSUI/Helper/Dates.ts b/src/scripts/OSFramework/OSUI/Helper/Dates.ts index d7788cb930..56d6997f4c 100644 --- a/src/scripts/OSFramework/OSUI/Helper/Dates.ts +++ b/src/scripts/OSFramework/OSUI/Helper/Dates.ts @@ -80,7 +80,30 @@ namespace OSFramework.OSUI.Helper { * @memberof Dates */ public static IsValid(date: string): boolean { - return !isNaN(Number(new Date(date))); + return !isNaN(Number(this.NormalizeDate(date))); + } + + /** + * Function used to normalize the OutSystems Dates + * + * @static + * @param {string} date + * @return {*} {Date} + * @memberof Dates + */ + public static NormalizeDate(date: string): Date { + // Store the current date + let currDate: Date; + + // Check if the given date string is a ISO 8601 date format + if (date.indexOf('T') > -1) { + currDate = new Date(date); + } else { + // Dates are being sent from platform with '-' instead of '/' + currDate = new Date(date.replace(/-/g, '/')); + } + + return currDate; } /** diff --git a/src/scripts/Providers/OSUI/Datepicker/Flatpickr/SingleDate/FlatpickrSingleDate.ts b/src/scripts/Providers/OSUI/Datepicker/Flatpickr/SingleDate/FlatpickrSingleDate.ts index 4d65a2f934..507167d812 100644 --- a/src/scripts/Providers/OSUI/Datepicker/Flatpickr/SingleDate/FlatpickrSingleDate.ts +++ b/src/scripts/Providers/OSUI/Datepicker/Flatpickr/SingleDate/FlatpickrSingleDate.ts @@ -22,7 +22,9 @@ namespace Providers.OSUI.Datepicker.Flatpickr.SingleDate { this.datePickerPlatformInputElem.value !== OSFramework.OSUI.Constants.EmptyString && OSFramework.OSUI.Helper.Dates.IsValid(this.datePickerPlatformInputElem.value) ) { - this.configs.InitialDate = new Date(this.datePickerPlatformInputElem.value); + this.configs.InitialDate = OSFramework.OSUI.Helper.Dates.NormalizeDate( + this.datePickerPlatformInputElem.value + ); } else { // If the date isn't valid, the platform input value will be removed clearPlatformInput = true;