Merge pull request #6265 from thornbill/safe-plugin-dates

Add support for plugin revisions with bad timestamps
This commit is contained in:
Bill Thornton 2024-10-28 12:53:08 -04:00 committed by GitHub
commit 71ab6fea5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -9,7 +9,7 @@ import Stack from '@mui/material/Stack/Stack';
import React, { type FC } from 'react';
import MarkdownBox from 'components/MarkdownBox';
import { parseISO8601Date, toLocaleString } from 'scripts/datetime';
import { getDisplayDateTime } from 'scripts/datetime';
import globalize from 'lib/globalize';
import type { PluginDetails } from '../types/PluginDetails';
@ -32,7 +32,7 @@ const PluginRevisions: FC<PluginRevisionsProps> = ({
{version.version}
{version.timestamp && (<>
&nbsp;&mdash;&nbsp;
{toLocaleString(parseISO8601Date(version.timestamp))}
{getDisplayDateTime(version.timestamp)}
</>)}
</AccordionSummary>
<AccordionDetails>

View File

@ -203,12 +203,28 @@ export function toLocaleTimeString(date, options) {
return date.toLocaleTimeString();
}
export function getDisplayDateTime(date) {
if (!date) {
throw new Error('date cannot be null');
}
if (typeof date === 'string') {
try {
date = parseISO8601Date(date, true);
} catch (err) {
return date;
}
}
return toLocaleString(date);
}
export function getDisplayTime(date) {
if (!date) {
throw new Error('date cannot be null');
}
if ((typeof date).toString().toLowerCase() === 'string') {
if (typeof date === 'string') {
try {
date = parseISO8601Date(date, true);
} catch (err) {