Updated date formatting for locales.
This commit is contained in:
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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user