Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix]: switch to UTC for release dates #743

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/renderer/components/virtual-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
iiPythonx marked this conversation as resolved.
Show resolved Hide resolved
valueGetter: (params: ValueGetterParams) =>
params.data ? params.data.createdAt : undefined,
width: 130,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
Expand All @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/renderer/utils/format.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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);

const DATE_FORMAT = 'MMM D, YYYY';

export const formatDateAbsolute = (key: string | null) =>
iiPythonx marked this conversation as resolved.
Show resolved Hide resolved
key ? dayjs(key).format('MMM D, YYYY') : '';
key ? dayjs(key).format(DATE_FORMAT) : '';

export const formatDateAbsoluteUTC = (key: string | null) =>
key ? dayjs.utc(key).format(DATE_FORMAT) : '';

export const formatDateRelative = (key: string | null) => (key ? dayjs(key).fromNow() : '');

Expand Down
Loading