diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d1d829c..63c45737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Rendered more hooks than during the previous render in `FileList` - [#142](https://github.com/estruyf/vscode-front-matter/issues/142): Fix for unknown tags where it throws an error - [#143](https://github.com/estruyf/vscode-front-matter/issues/143): Fix for duplicate values in the file list +- [#144](https://github.com/estruyf/vscode-front-matter/issues/144): Fix for `toISOString` does not exist on object ## [5.0.0] - 2021-10-07 - [Release Notes](https://beta.frontmatter.codes/updates/v5.0.0) diff --git a/src/commands/Article.ts b/src/commands/Article.ts index b6a3f44f..f7a3633c 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -245,7 +245,7 @@ export class Article { if (dateFormat && typeof dateFormat === "string") { return format(dateValue, dateFormat); } else { - return dateValue.toISOString(); + return typeof dateValue.toISOString === 'function' ? dateValue.toISOString() : dateValue; } } diff --git a/src/panelWebView/components/Fields/DateTimeField.tsx b/src/panelWebView/components/Fields/DateTimeField.tsx index b18b0c65..2354b4f7 100644 --- a/src/panelWebView/components/Fields/DateTimeField.tsx +++ b/src/panelWebView/components/Fields/DateTimeField.tsx @@ -30,7 +30,10 @@ export const DateTimeField: React.FunctionComponent = ({lab }; React.useEffect(() => { - if (dateValue?.toISOString() !== date?.toISOString()) { + const crntValue = typeof date?.toISOString === 'function' ? date.toISOString() : date; + const stateValue = typeof dateValue?.toISOString === 'function' ? dateValue.toISOString() : dateValue; + + if (crntValue !== stateValue) { setDateValue(date); } }, [ date ]); @@ -45,7 +48,7 @@ export const DateTimeField: React.FunctionComponent = ({lab