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

fix: Datepicker emitEvent error handling on parsing of icelandic language #949

Merged
Merged
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6ecaec9
fix: emitEvent error handling on parsing of icelandic language
harshith-venkatesh-freshworks Nov 8, 2024
7dc7dc7
Merge branch 'next' into fix/date-picker
harshith-venkatesh-freshworks Nov 11, 2024
e6a6f19
chore: refactor the code related to datepicker
harshith-venkatesh-freshworks Nov 11, 2024
4edde18
fix: parse date on filter
harshith-venkatesh-freshworks Nov 11, 2024
9b60fdf
Merge branch 'next' into fix/date-picker
harshith-venkatesh-freshworks Nov 11, 2024
00a1afb
Merge branch 'next' into fix/date-picker
harshith-venkatesh-freshworks Nov 12, 2024
0a5c0e7
fix: issue related to form builder empty search image changes
harshith-venkatesh-freshworks Nov 12, 2024
20852fc
fix: datepicker year issue fix
harshith-venkatesh-freshworks Nov 12, 2024
d44532c
fix: isMatch change issue for icelandic language
harshith-venkatesh-freshworks Nov 12, 2024
9fc9b73
fix: parsed date for dateInvalid check
harshith-venkatesh-freshworks Nov 12, 2024
99b4576
chore: test comment
harshith-venkatesh-freshworks Nov 12, 2024
1a2b66f
fix: check for error handling for format related issue
harshith-venkatesh-freshworks Nov 12, 2024
ccf0af2
fix: is date validation and matching restriction
harshith-venkatesh-freshworks Nov 12, 2024
039369f
fix: datepicker issue
harshith-venkatesh-freshworks Nov 12, 2024
5b9b682
chore: remove console info
harshith-venkatesh-freshworks Nov 12, 2024
e4a721e
fix: reverse the changes on change value of datepicker
harshith-venkatesh-freshworks Nov 12, 2024
22d391f
fix: refresh handle popover parse on icelandic language issue fix
harshith-venkatesh-freshworks Nov 12, 2024
c8e9357
chore: revert form builder changes
harshith-venkatesh-freshworks Nov 12, 2024
0cdd7bf
chore: refactor parseDate changes
harshith-venkatesh-freshworks Nov 12, 2024
ad2ecca
chore: refactor parseDate changes
harshith-venkatesh-freshworks Nov 12, 2024
bd256a0
refactor: change parse function to ensure we get parsed date on icela…
harshith-venkatesh-freshworks Nov 13, 2024
4e37525
Merge branch 'next' into fix/date-picker
harshith-venkatesh-freshworks Nov 13, 2024
5677657
fix: refresh handle popover parse on icelandic language issue fix
harshith-venkatesh-freshworks Nov 13, 2024
314f902
fix: form builder changes
harshith-venkatesh-freshworks Nov 13, 2024
26b7a18
fix: datepicker issue fix
harshith-venkatesh-freshworks Nov 13, 2024
45f7ddb
test: changes on date picker test case
harshith-venkatesh-freshworks Nov 13, 2024
f422876
fix: datepicker issue on filter changes
harshith-venkatesh-freshworks Nov 13, 2024
d00f87b
fix: generalising the datepicker for icelandic language
harshith-venkatesh-freshworks Nov 13, 2024
c4ec2fa
test: revert datepicker test case
harshith-venkatesh-freshworks Nov 13, 2024
b9dc939
chore: add additional data for datepicker
harshith-venkatesh-freshworks Nov 13, 2024
04f5b2b
chore: remove spaces in the file on format
harshith-venkatesh-freshworks Nov 13, 2024
e51919c
fix: remove condition changes for datepicker
harshith-venkatesh-freshworks Nov 13, 2024
2ba68f4
fix: isValid changes for datefixer
harshith-venkatesh-freshworks Nov 13, 2024
38d84f8
fix: datepicket changes on isMatch
harshith-venkatesh-freshworks Nov 13, 2024
4110887
fix: add validation for is language for isValid
harshith-venkatesh-freshworks Nov 13, 2024
d077d85
fix: datepicker issue changes on isValid
harshith-venkatesh-freshworks Nov 13, 2024
1be7cac
fix: retain isMatch funtionality and change in custom function
harshith-venkatesh-freshworks Nov 13, 2024
802d614
fix: isMatch changes retaining
harshith-venkatesh-freshworks Nov 13, 2024
4a145bc
fix: isMatch negation changes
harshith-venkatesh-freshworks Nov 13, 2024
81e488b
fix: test cases failing on isMatch changes completed
harshith-venkatesh-freshworks Nov 14, 2024
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
77 changes: 48 additions & 29 deletions packages/crayons-core/src/components/datepicker/datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@stencil/core';
import {
isValid,
parse,
parse as parseDate,
parseISO,
getYear,
getMonth,
Expand All @@ -21,7 +21,7 @@ import {
startOfDay,
getDaysInMonth,
format,
isMatch,
isMatch as parseIsMatch,
formatISO,
addDays,
startOfWeek,
Expand Down Expand Up @@ -81,6 +81,52 @@ const getWeekDays = (lang): any => {
format(addDays(startOfWeek(new Date()), i), 'EEEEE', { locale: lang })
);
};

const parseIcelandicDate = (value, langModule) => {
// For Icelandic language, the date format is different. There is a discrepency which is handled in this PR https://github.com/date-fns/date-fns/pull/3934
if (!value) return value;
const icelandicLanguageDisplayFormat = 'dd MMMM yyyy';
const icelandicMonthMapper = {
'jan.': 'jan.',
'feb.': 'feb.',
'mars': 'm',
'apríl': 'apríl',
'maí': 'maí',
'júní': 'júní',
'júlí': 'júlí',
'ágúst': 'á',
'sept.': 's',
'okt.': 'ó',
'nóv.': 'n',
'des.': 'd',
};
const correctedDate = value?.replace(
/jan\.|feb\.|mars|apríl|maí|júní|júlí|ágúst|sept\.|okt\.|nóv\.|des\./g,
(match) => icelandicMonthMapper[match]
);
return parseDate(
correctedDate,
icelandicLanguageDisplayFormat,
new Date(),
langModule
);
};

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

const isMatch = (value, displayFormat, langModule) => {
if (langModule?.locale?.code !== 'is') {
parseIsMatch(value, displayFormat, langModule);
}
return false;
};

@Component({ tag: 'fw-datepicker', styleUrl: 'datepicker.scss', shadow: true })
export class Datepicker {
@State() showDatePicker: boolean;
Expand Down Expand Up @@ -336,33 +382,6 @@ export class Datepicker {

private formatDate(value) {
if (!value) return value;
// For Icelandic language, the date format is different. There is a discrepency which is handled in this PR https://github.com/date-fns/date-fns/pull/3934
if (this.langModule?.code === 'is' && this.dateFormat === 'dd MMM yyyy') {
const icelandicLanguageDisplayFormat = 'dd MMMM yyyy';
const icelandicMonthMapper = {
'jan.': 'jan.',
'feb.': 'feb.',
'mars': 'm',
'apríl': 'apríl',
'maí': 'maí',
'júní': 'júní',
'júlí': 'júlí',
'ágúst': 'á',
'sept.': 's',
'okt.': 'ó',
'nóv.': 'n',
'des.': 'd',
};
const correctedDate = value.replace(
/jan\.|feb\.|mars|apríl|maí|júní|júlí|ágúst|sept\.|okt\.|nóv\.|des\./g,
(match) => icelandicMonthMapper[match]
);
return formatISO(
parse(correctedDate, icelandicLanguageDisplayFormat, new Date(), {
locale: this.langModule,
})
);
}

return this.displayFormat
? formatISO(
Expand Down
Loading