Use "Intl.DateTimeFormat" instead of Date locale functions

It's recommended to use "Intl.DateTimeFormat" instead of using Date locale functions which get called often with the same options (e.g. https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/date/tolocaletimestring)
This commit is contained in:
schroda
2024-05-03 15:57:38 +02:00
parent 940949f832
commit 29ade85f7f
3 changed files with 21 additions and 14 deletions

View File

@@ -32,6 +32,7 @@ import { StyledGroupHeader } from '@/components/virtuoso/StyledGroupHeader.tsx';
import { StyledGroupItemWrapper } from '@/components/virtuoso/StyledGroupItemWrapper.tsx';
import { Mangas } from '@/lib/data/Mangas.ts';
import { SpinnerImage } from '@/components/util/SpinnerImage.tsx';
import { dateFormatter, dateTimeFormatter } from '@/util/date.ts';
function epochToDate(epoch: number) {
const date = new Date(0); // The 0 there is the key, which sets the date to the epoch
@@ -54,7 +55,7 @@ function getDateString(date: Date) {
const yesterday = new Date();
yesterday.setDate(today.getDate() - 1);
if (isTheSameDay(yesterday, date)) return translate('global.date.label.yesterday');
return date.toLocaleDateString();
return dateFormatter.format(date);
}
const groupByDate = (updates: TChapter[]): [date: string, items: number][] => {
@@ -150,7 +151,7 @@ export const Updates: React.FC = () => {
}}
>
{t('library.settings.global_update.label.last_update', {
date: lastUpdateTimestamp ? new Date(+lastUpdateTimestamp).toLocaleString() : '-',
date: lastUpdateTimestamp ? dateTimeFormatter.format(+lastUpdateTimestamp) : '-',
})}
</Typography>
<StyledGroupedVirtuoso