#144 - Fix date value issue

This commit is contained in:
Elio Struyf
2021-10-11 11:08:45 +02:00
parent c11be0e3ec
commit 70099dc97f
3 changed files with 7 additions and 3 deletions
+1
View File
@@ -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)
+1 -1
View File
@@ -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;
}
}
@@ -30,7 +30,10 @@ export const DateTimeField: React.FunctionComponent<IDateTimeFieldProps> = ({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<IDateTimeFieldProps> = ({lab
<div className={`metadata_field__datetime`}>
<DatePicker
selected={dateValue as Date}
selected={dateValue as Date || null}
onChange={onDateChange}
timeInputLabel="Time:"
dateFormat={format || "MM/dd/yyyy HH:mm"}