mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
Add try catch to toLocaleString
This commit is contained in:
parent
702dbffd3d
commit
1208a9ac02
@ -62,7 +62,7 @@ export const toSelectablePeriod = (
|
|||||||
dayCount,
|
dayCount,
|
||||||
label:
|
label:
|
||||||
label ||
|
label ||
|
||||||
"date.toLocaleString('en-US', { month: 'long', year: 'numeric' })",
|
date.toLocaleString('en-US', { month: 'long', year: 'numeric' }),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,14 +2,22 @@ export const formatDateYMDHMS = (
|
|||||||
date: number | string | Date,
|
date: number | string | Date,
|
||||||
locale?: string,
|
locale?: string,
|
||||||
): string => {
|
): string => {
|
||||||
return new Date(date).toLocaleString(locale, {
|
try {
|
||||||
day: '2-digit',
|
return new Date(date).toLocaleString(locale, {
|
||||||
month: '2-digit',
|
day: '2-digit',
|
||||||
year: 'numeric',
|
month: '2-digit',
|
||||||
hour: '2-digit',
|
year: 'numeric',
|
||||||
minute: '2-digit',
|
hour: '2-digit',
|
||||||
second: '2-digit',
|
minute: '2-digit',
|
||||||
});
|
second: '2-digit',
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
`Invalid toLocaleString locale: ${locale}, date: ${date}`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatDateYMDHM = (
|
export const formatDateYMDHM = (
|
||||||
@ -17,14 +25,22 @@ export const formatDateYMDHM = (
|
|||||||
locale: string,
|
locale: string,
|
||||||
timeZone?: string,
|
timeZone?: string,
|
||||||
): string => {
|
): string => {
|
||||||
return new Date(date).toLocaleString(locale, {
|
try {
|
||||||
day: '2-digit',
|
return new Date(date).toLocaleString(locale, {
|
||||||
month: '2-digit',
|
day: '2-digit',
|
||||||
year: 'numeric',
|
month: '2-digit',
|
||||||
hour: '2-digit',
|
year: 'numeric',
|
||||||
minute: '2-digit',
|
hour: '2-digit',
|
||||||
timeZone,
|
minute: '2-digit',
|
||||||
});
|
timeZone,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
`Invalid toLocaleString locale: ${locale}, date: ${date}`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatDateYMD = (
|
export const formatDateYMD = (
|
||||||
@ -32,20 +48,36 @@ export const formatDateYMD = (
|
|||||||
locale: string,
|
locale: string,
|
||||||
timeZone?: string,
|
timeZone?: string,
|
||||||
): string => {
|
): string => {
|
||||||
return new Date(date).toLocaleString(locale, {
|
try {
|
||||||
day: '2-digit',
|
return new Date(date).toLocaleString(locale, {
|
||||||
month: '2-digit',
|
day: '2-digit',
|
||||||
year: 'numeric',
|
month: '2-digit',
|
||||||
timeZone,
|
year: 'numeric',
|
||||||
});
|
timeZone,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
`Invalid toLocaleString locale: ${locale}, date: ${date}`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatDateHM = (
|
export const formatDateHM = (
|
||||||
date: number | string | Date,
|
date: number | string | Date,
|
||||||
locale: string,
|
locale: string,
|
||||||
): string => {
|
): string => {
|
||||||
return new Date(date).toLocaleString(locale, {
|
try {
|
||||||
hour: '2-digit',
|
return new Date(date).toLocaleString(locale, {
|
||||||
minute: '2-digit',
|
hour: '2-digit',
|
||||||
});
|
minute: '2-digit',
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
`Invalid toLocaleString locale: ${locale}, date: ${date}`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user