Skip to content

Commit

Permalink
fix(DatePicker): Fixed issue when creating a new date based on a give…
Browse files Browse the repository at this point in the history
…n platform date.
  • Loading branch information
joselrio committed Sep 25, 2024
1 parent baaa6da commit 0397643
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 0397643

Please sign in to comment.