mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-25 13:51:13 +00:00
Added error handling to format-past-date to prevent timeouts on modlog (#2083)
* Added error handling to format-past-date to prevent timeouts on modlog * Apply suggestions from code review Co-authored-by: SleeplessOne1917 <abias1122@gmail.com> --------- Co-authored-by: Beehaw Dev <dev@beehaw.dev> Co-authored-by: SleeplessOne1917 <abias1122@gmail.com>
This commit is contained in:
parent
7f993c6ce7
commit
02bb1b84e1
1 changed files with 19 additions and 4 deletions
|
@ -2,8 +2,23 @@ import formatDistanceStrict from "date-fns/formatDistanceStrict";
|
|||
import parseISO from "date-fns/parseISO";
|
||||
|
||||
export default function (dateString?: string) {
|
||||
const parsed = parseISO((dateString ?? Date.now().toString()) + "Z");
|
||||
if (!dateString) {
|
||||
console.error(err);
|
||||
return "DATE ERROR";
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = parseISO(Date.now().toString() + "Z");
|
||||
return formatDistanceStrict(parsed, new Date(), {
|
||||
addSuffix: true,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
if (err instanceof RangeError) {
|
||||
console.error(
|
||||
`Got the invalid value of ${dateString} when attempting to parse to ISO date`,
|
||||
);
|
||||
return "DATE ERROR";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue