Skip to content

Commit

Permalink
Merge pull request #995 from OutSystems/ROU-11179
Browse files Browse the repository at this point in the history
ROU-11179: DatePicker - Fix an issue when used at certain time zones
  • Loading branch information
joselrio authored Sep 26, 2024
2 parents 79fcbbd + b9735f6 commit ee64406
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/scripts/OSFramework/OSUI/Helper/Dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ee64406

Please sign in to comment.