different date formats based off of metadata

This commit is contained in:
Kendall Garner 2024-09-16 17:33:06 -07:00
parent 96b4f8dd89
commit 730683fe25
No known key found for this signature in database
GPG key ID: 18D2767419676C87

View file

@ -8,13 +8,22 @@ import { Rating } from '/@/renderer/components/rating';
dayjs.extend(relativeTime);
dayjs.extend(utc);
const DATE_FORMAT = 'MMM D, YYYY';
const FORMATS: Record<number, string> = Object.freeze({
0: 'YYYY',
1: 'MMM YYYY',
2: 'MMM D, YYYY',
});
const getDateFormat = (key: string): string => {
const dashes = Math.min(key.split('-').length - 1, 2);
return FORMATS[dashes];
};
export const formatDateAbsolute = (key: string | null) =>
key ? dayjs(key).format(DATE_FORMAT) : '';
key ? dayjs(key).format(getDateFormat(key)) : '';
export const formatDateAbsoluteUTC = (key: string | null) =>
key ? dayjs.utc(key).format(DATE_FORMAT) : '';
key ? dayjs.utc(key).format(getDateFormat(key)) : '';
export const formatDateRelative = (key: string | null) => (key ? dayjs(key).fromNow() : '');