Skip to content

Commit

Permalink
Merge pull request #6265 from thornbill/safe-plugin-dates
Browse files Browse the repository at this point in the history
Add support for plugin revisions with bad timestamps
  • Loading branch information
thornbill authored Oct 28, 2024
2 parents d4d84d0 + 3062f0f commit 71ab6fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,7 +32,7 @@ const PluginRevisions: FC<PluginRevisionsProps> = ({
{version.version}
{version.timestamp && (<>
&nbsp;&mdash;&nbsp;
{toLocaleString(parseISO8601Date(version.timestamp))}
{getDisplayDateTime(version.timestamp)}
</>)}
</AccordionSummary>
<AccordionDetails>
Expand Down
18 changes: 17 additions & 1 deletion src/scripts/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 71ab6fe

Please sign in to comment.