From 223e7e3d6aa277ba0816df32f5e7d5d3a7dd917a Mon Sep 17 00:00:00 2001 From: myl7 Date: Tue, 8 Feb 2022 20:06:02 +0800 Subject: [PATCH] allow to customize datetime format via dayjs --- components/previews/AudioPreview.tsx | 7 ++----- config/site.config.js | 5 +++++ package.json | 1 + pnpm-lock.yaml | 6 ++++++ utils/fileDetails.ts | 13 +++++-------- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/components/previews/AudioPreview.tsx b/components/previews/AudioPreview.tsx index e2eea60..5a10308 100644 --- a/components/previews/AudioPreview.tsx +++ b/components/previews/AudioPreview.tsx @@ -7,6 +7,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import DownloadButtonGroup from '../DownloadBtnGtoup' import { DownloadBtnContainer, PreviewContainer } from './Containers' import { LoadingIcon } from '../Loading' +import { formatModifiedDateTime } from '../../utils/fileDetails' enum PlayerState { Loading, @@ -36,11 +37,7 @@ const AudioPreview: FC<{ file: OdFileObject }> = ({ file }) => {
{file.name}
- Last modified:{' '} - {new Date(file.lastModifiedDateTime).toLocaleString(undefined, { - dateStyle: 'short', - timeStyle: 'short', - })} + Last modified: {formatModifiedDateTime(file.lastModifiedDateTime)}
{ * @returns Human readable form of the file or folder last modified date */ export const formatModifiedDateTime = (lastModifedDateTime: string) => { - return new Date(lastModifedDateTime).toLocaleString('en-US', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - hour12: false, - }) + return dayjs(lastModifedDateTime).format(siteConfig.datetimeFormat) }