Skip to content

Commit

Permalink
fix: datepicker issue on filter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
harshith-venkatesh-freshworks committed Nov 13, 2024
1 parent 45f7ddb commit f422876
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/crayons-core/src/components/datepicker/datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,19 @@ const parseIcelandicDate = (value, langModule) => {
/jan\.|feb\.|mars|apríl|maí|júní|júlí|ágúst|sept\.|okt\.|nóv\.|des\./g,
(match) => icelandicMonthMapper[match]
);
return parse(correctedDate, icelandicLanguageDisplayFormat, new Date(), {
locale: langModule,
});
return parse(
correctedDate,
icelandicLanguageDisplayFormat,
new Date(),
langModule
);
};

const parseDate = (value, displayFormat, langModule) => {
if (langModule?.code === 'is' && displayFormat === 'dd MMM yyyy') {
if (langModule?.locale?.code === 'is' && displayFormat === 'dd MMM yyyy') {
return parseIcelandicDate(value, langModule);
}
return parse(value, displayFormat, new Date(), {
locale: langModule,
});
return parse(value, displayFormat, new Date(), langModule);
};

@Component({ tag: 'fw-datepicker', styleUrl: 'datepicker.scss', shadow: true })
Expand Down Expand Up @@ -902,11 +903,11 @@ export class Datepicker {
fromDate = fromDate?.trim();
toDate = toDate?.trim();

const parsedFromDate = parse(fromDate, this.displayFormat, new Date(), {
const parsedFromDate = parseDate(fromDate, this.displayFormat, {
locale: this.langModule,
});

const parsedToDate = parse(toDate, this.displayFormat, new Date(), {
const parsedToDate = parseDate(toDate, this.displayFormat, {
locale: this.langModule,
});

Expand All @@ -926,12 +927,14 @@ export class Datepicker {
if (
!isValidFromDate ||
!isValidToDate ||
!isMatch(fromDate, this.displayFormat, {
locale: this.langModule,
}) ||
!isMatch(toDate, this.displayFormat, {
locale: this.langModule,
}) ||
(this.langModule?.code !== 'is' &&
!isMatch(fromDate, this.displayFormat, {
locale: this.langModule,
})) ||
(this.langModule?.code !== 'is' &&
!isMatch(toDate, this.displayFormat, {
locale: this.langModule,
})) ||
year < this.minYear ||
year > this.maxYear ||
toYear < this.minYear ||
Expand Down

0 comments on commit f422876

Please sign in to comment.