Skip to content

Commit d431611

Browse files
committed
Use regex
1 parent 776fbc7 commit d431611

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

apinf_packages/core/helper_functions/format_date.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export function formatDate (date, dateFormat = 'LL') {
2424
}
2525

2626
export function getLocaleDateFormat () {
27+
// Use regex to define Finnish locale for different browsers
28+
const regex = RegExp('fi*');
29+
2730
// Get locale
2831
const locale = navigator.languages ? navigator.languages[0] :
2932
(navigator.language || navigator.userLanguage);
@@ -33,15 +36,13 @@ export function getLocaleDateFormat () {
3336
// Get locale data
3437
const localeData = moment.localeData();
3538

36-
let format = localeData.longDateFormat('L');
39+
const format = localeData.longDateFormat('L');
3740

38-
if (locale === 'fi') {
41+
if (regex.text(locale)) {
3942
// Remove year part (save the last dot)
40-
format = format.replace(/YYYY/, '');
41-
} else {
42-
// Remove year part
43-
format = format.replace(/.YYYY/, '');
43+
return format.replace(/YYYY/, '');
4444
}
4545

46-
return format;
46+
// Remove year part
47+
return format.replace(/.YYYY/, '');
4748
}

0 commit comments

Comments
 (0)