From 0c2d1affcfadbc14e08f9619da486b6aad485114 Mon Sep 17 00:00:00 2001 From: iiPython Date: Thu, 12 Sep 2024 13:48:34 -0500 Subject: [PATCH 1/4] use utc for date formatting --- src/renderer/utils/format.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/renderer/utils/format.tsx b/src/renderer/utils/format.tsx index 572905d2a..2b97750d7 100644 --- a/src/renderer/utils/format.tsx +++ b/src/renderer/utils/format.tsx @@ -1,13 +1,15 @@ import dayjs from 'dayjs'; import relativeTime from 'dayjs/plugin/relativeTime'; +import utc from 'dayjs/plugin/utc'; import formatDuration from 'format-duration'; import type { Album, AlbumArtist, Song } from '/@/renderer/api/types'; import { Rating } from '/@/renderer/components/rating'; dayjs.extend(relativeTime); +dayjs.extend(utc); export const formatDateAbsolute = (key: string | null) => - key ? dayjs(key).format('MMM D, YYYY') : ''; + key ? dayjs.utc(key).format('MMM D, YYYY') : ''; export const formatDateRelative = (key: string | null) => (key ? dayjs(key).fromNow() : ''); From 53a1ceb204b83d70139947d51e2ec0caace6e245 Mon Sep 17 00:00:00 2001 From: iiPython Date: Thu, 12 Sep 2024 20:23:37 -0500 Subject: [PATCH 2/4] add seperate utc function and call that instead --- src/renderer/components/virtual-table/index.tsx | 10 +++++++--- .../features/albums/components/album-detail-header.tsx | 6 +++--- src/renderer/utils/format.tsx | 3 +++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/renderer/components/virtual-table/index.tsx b/src/renderer/components/virtual-table/index.tsx index c21bbe0ca..ec5b1e919 100644 --- a/src/renderer/components/virtual-table/index.tsx +++ b/src/renderer/components/virtual-table/index.tsx @@ -41,7 +41,11 @@ import { useFixedTableHeader } from '/@/renderer/components/virtual-table/hooks/ import { NoteCell } from '/@/renderer/components/virtual-table/cells/note-cell'; import { RowIndexCell } from '/@/renderer/components/virtual-table/cells/row-index-cell'; import i18n from '/@/i18n/i18n'; -import { formatDateAbsolute, formatDateRelative, formatSizeString } from '/@/renderer/utils/format'; +import { + formatDateAbsoluteUTC, + formatDateRelative, + formatSizeString, +} from '/@/renderer/utils/format'; import { useTableChange } from '/@/renderer/hooks/use-song-change'; export * from './table-config-dropdown'; @@ -179,7 +183,7 @@ const tableColumns: { [key: string]: ColDef } = { GenericTableHeader(params, { position: 'center' }), headerName: i18n.t('table.column.dateAdded'), suppressSizeToFit: true, - valueFormatter: (params: ValueFormatterParams) => formatDateAbsolute(params.value), + valueFormatter: (params: ValueFormatterParams) => formatDateAbsoluteUTC(params.value), valueGetter: (params: ValueGetterParams) => params.data ? params.data.createdAt : undefined, width: 130, @@ -253,7 +257,7 @@ const tableColumns: { [key: string]: ColDef } = { GenericTableHeader(params, { position: 'center' }), headerName: i18n.t('table.column.releaseDate'), suppressSizeToFit: true, - valueFormatter: (params: ValueFormatterParams) => formatDateAbsolute(params.value), + valueFormatter: (params: ValueFormatterParams) => formatDateAbsoluteUTC(params.value), valueGetter: (params: ValueGetterParams) => params.data ? params.data.releaseDate : undefined, width: 130, diff --git a/src/renderer/features/albums/components/album-detail-header.tsx b/src/renderer/features/albums/components/album-detail-header.tsx index 98db7db94..cc672b8dd 100644 --- a/src/renderer/features/albums/components/album-detail-header.tsx +++ b/src/renderer/features/albums/components/album-detail-header.tsx @@ -10,7 +10,7 @@ import { LibraryHeader, useSetRating } from '/@/renderer/features/shared'; import { useContainerQuery } from '/@/renderer/hooks'; import { AppRoute } from '/@/renderer/router/routes'; import { useCurrentServer } from '/@/renderer/store'; -import { formatDateAbsolute, formatDurationString } from '/@/renderer/utils'; +import { formatDateAbsoluteUTC, formatDurationString } from '/@/renderer/utils'; interface AlbumDetailHeaderProps { background: { @@ -42,7 +42,7 @@ export const AlbumDetailHeader = forwardRef( id: 'releaseDate', value: detailQuery?.data?.releaseDate && - `${releasePrefix} ${formatDateAbsolute(detailQuery?.data?.releaseDate)}`, + `${releasePrefix} ${formatDateAbsoluteUTC(detailQuery?.data?.releaseDate)}`, }, { id: 'songCount', @@ -62,7 +62,7 @@ export const AlbumDetailHeader = forwardRef( ]; if (originalDifferentFromRelease) { - const formatted = `♫ ${formatDateAbsolute(detailQuery!.data!.originalDate)}`; + const formatted = `♫ ${formatDateAbsoluteUTC(detailQuery!.data!.originalDate)}`; metadataItems.splice(0, 0, { id: 'originalDate', value: formatted, diff --git a/src/renderer/utils/format.tsx b/src/renderer/utils/format.tsx index 2b97750d7..36f84b317 100644 --- a/src/renderer/utils/format.tsx +++ b/src/renderer/utils/format.tsx @@ -9,6 +9,9 @@ dayjs.extend(relativeTime); dayjs.extend(utc); export const formatDateAbsolute = (key: string | null) => + key ? dayjs(key).format('MMM D, YYYY') : ''; + +export const formatDateAbsoluteUTC = (key: string | null) => key ? dayjs.utc(key).format('MMM D, YYYY') : ''; export const formatDateRelative = (key: string | null) => (key ? dayjs(key).fromNow() : ''); From cf8a18ff4c524954be608cc6dfc3cc9db366ae7f Mon Sep 17 00:00:00 2001 From: iiPython Date: Thu, 12 Sep 2024 20:28:57 -0500 Subject: [PATCH 3/4] swap date format to be a constant --- src/renderer/utils/format.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/utils/format.tsx b/src/renderer/utils/format.tsx index 36f84b317..0f2ce2265 100644 --- a/src/renderer/utils/format.tsx +++ b/src/renderer/utils/format.tsx @@ -8,11 +8,13 @@ import { Rating } from '/@/renderer/components/rating'; dayjs.extend(relativeTime); dayjs.extend(utc); +const DATE_FORMAT = 'MMM D, YYYY'; + export const formatDateAbsolute = (key: string | null) => - key ? dayjs(key).format('MMM D, YYYY') : ''; + key ? dayjs(key).format(DATE_FORMAT) : ''; export const formatDateAbsoluteUTC = (key: string | null) => - key ? dayjs.utc(key).format('MMM D, YYYY') : ''; + key ? dayjs.utc(key).format(DATE_FORMAT) : ''; export const formatDateRelative = (key: string | null) => (key ? dayjs(key).fromNow() : ''); From d5edbd71dd4e770e9c9b61956880ed5b789ee9a6 Mon Sep 17 00:00:00 2001 From: iiPython Date: Thu, 12 Sep 2024 20:33:26 -0500 Subject: [PATCH 4/4] make dateadded use non-utc --- src/renderer/components/virtual-table/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/renderer/components/virtual-table/index.tsx b/src/renderer/components/virtual-table/index.tsx index ec5b1e919..fc02696c4 100644 --- a/src/renderer/components/virtual-table/index.tsx +++ b/src/renderer/components/virtual-table/index.tsx @@ -42,6 +42,7 @@ import { NoteCell } from '/@/renderer/components/virtual-table/cells/note-cell'; import { RowIndexCell } from '/@/renderer/components/virtual-table/cells/row-index-cell'; import i18n from '/@/i18n/i18n'; import { + formatDateAbsolute, formatDateAbsoluteUTC, formatDateRelative, formatSizeString, @@ -183,7 +184,7 @@ const tableColumns: { [key: string]: ColDef } = { GenericTableHeader(params, { position: 'center' }), headerName: i18n.t('table.column.dateAdded'), suppressSizeToFit: true, - valueFormatter: (params: ValueFormatterParams) => formatDateAbsoluteUTC(params.value), + valueFormatter: (params: ValueFormatterParams) => formatDateAbsolute(params.value), valueGetter: (params: ValueGetterParams) => params.data ? params.data.createdAt : undefined, width: 130,