Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROU-11179: DatePicker - Fix an issue when used at certain time zones #995

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading