mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Updated date formatting for locales.
This commit is contained in:
parent
50bc2371b8
commit
d6d0f99daa
6 changed files with 25 additions and 24 deletions
16
lib/date.js
16
lib/date.js
|
|
@ -23,7 +23,10 @@ import {
|
|||
differenceInCalendarDays,
|
||||
differenceInCalendarMonths,
|
||||
differenceInCalendarYears,
|
||||
format,
|
||||
} from 'date-fns';
|
||||
import { enUS } from 'date-fns/locale';
|
||||
import { dateLocales } from 'lib/lang';
|
||||
|
||||
export function getTimezone() {
|
||||
return moment.tz.guess();
|
||||
|
|
@ -150,3 +153,16 @@ export function getDateLength(startDate, endDate, unit) {
|
|||
const [diff] = dateFuncs[unit];
|
||||
return diff(endDate, startDate) + 1;
|
||||
}
|
||||
|
||||
export const customFormats = {
|
||||
'en-US': {
|
||||
p: 'ha',
|
||||
pp: 'h:mm:ss',
|
||||
},
|
||||
};
|
||||
|
||||
export function dateFormat(date, str, locale = 'en-US') {
|
||||
return format(date, customFormats?.[locale]?.[str] || str, {
|
||||
locale: dateLocales[locale] || enUS,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
14
lib/lang.js
14
lib/lang.js
|
|
@ -1,4 +1,3 @@
|
|||
import { format } from 'date-fns';
|
||||
import {
|
||||
cs,
|
||||
da,
|
||||
|
|
@ -118,11 +117,6 @@ export const dateLocales = {
|
|||
'it-IT': it,
|
||||
};
|
||||
|
||||
const timeFormats = {
|
||||
// https://date-fns.org/v2.17.0/docs/format
|
||||
'en-US': 'ha',
|
||||
};
|
||||
|
||||
export const menuOptions = [
|
||||
{ label: '中文', value: 'zh-CN', display: 'cn' },
|
||||
{ label: '中文(繁體)', value: 'zh-TW', display: 'tw' },
|
||||
|
|
@ -153,11 +147,3 @@ export const menuOptions = [
|
|||
{ label: 'Türkçe', value: 'tr-TR', display: 'tr' },
|
||||
{ label: 'українська', value: 'uk-UA', display: 'uk' },
|
||||
];
|
||||
|
||||
export function dateFormat(date, str, locale) {
|
||||
return format(date, str, { locale: dateLocales[locale] || enUS });
|
||||
}
|
||||
|
||||
export function timeFormat(date, locale = 'en-US') {
|
||||
return format(date, timeFormats[locale] || 'p', { locale: dateLocales[locale] });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue