From 3b93cff9d175094211533d1c387d1c84644b5081 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Thu, 16 Nov 2023 13:04:47 +0100 Subject: [PATCH 1/3] [Fix #237] Fixed issue with incorrect date values --- src/components/answer/DateTimeAnswer.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/answer/DateTimeAnswer.jsx b/src/components/answer/DateTimeAnswer.jsx index 11b08377..603fd811 100644 --- a/src/components/answer/DateTimeAnswer.jsx +++ b/src/components/answer/DateTimeAnswer.jsx @@ -1,7 +1,7 @@ import React, { useContext } from "react"; import DatePicker from "react-datepicker"; import { FormGroup, Form } from "react-bootstrap"; -import PropTypes from "prop-types"; +import PropTypes, { number } from "prop-types"; import { format } from "date-fns"; import FormUtils from "../../util/FormUtils"; import Constants from "../../constants/Constants"; @@ -21,11 +21,11 @@ const DateTimeAnswer = (props) => { // workaround because it is not possible to construct Date only with time let value; - if (isTime && props.value) { + if (isTime && props.value instanceof number) { value = new Date(`0 ${props.value}`); - } else { - value = props.value ? new Date(props.value) : null; - } + } else if (isDate && props.value instanceof number) { + value = new Date(props.value); + } else value = null; // DatePicker does not know dateFormat "x", translate to datetime const datePickerFormat = From 1d7dcae0202f1eb8ba7607f6ed6fca81a72c4819 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Thu, 16 Nov 2023 13:04:47 +0100 Subject: [PATCH 2/3] [Fix #237] Fixed issue with incorrect date values --- src/components/answer/DateTimeAnswer.jsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/answer/DateTimeAnswer.jsx b/src/components/answer/DateTimeAnswer.jsx index 603fd811..f400d844 100644 --- a/src/components/answer/DateTimeAnswer.jsx +++ b/src/components/answer/DateTimeAnswer.jsx @@ -1,7 +1,7 @@ import React, { useContext } from "react"; import DatePicker from "react-datepicker"; import { FormGroup, Form } from "react-bootstrap"; -import PropTypes, { number } from "prop-types"; +import PropTypes from "prop-types"; import { format } from "date-fns"; import FormUtils from "../../util/FormUtils"; import Constants from "../../constants/Constants"; @@ -21,9 +21,7 @@ const DateTimeAnswer = (props) => { // workaround because it is not possible to construct Date only with time let value; - if (isTime && props.value instanceof number) { - value = new Date(`0 ${props.value}`); - } else if (isDate && props.value instanceof number) { + if ((isTime || isDate) && props.value && props.value !== "0") { value = new Date(props.value); } else value = null; From 59bc883d5057a017d4e3f7edd44bb530e86b4572 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Thu, 16 Nov 2023 13:55:18 +0100 Subject: [PATCH 3/3] [Fix #237] Fixed tests --- src/components/answer/DateTimeAnswer.jsx | 6 ++++-- src/components/answer/TypeaheadAnswer.jsx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/answer/DateTimeAnswer.jsx b/src/components/answer/DateTimeAnswer.jsx index f400d844..75f7a63e 100644 --- a/src/components/answer/DateTimeAnswer.jsx +++ b/src/components/answer/DateTimeAnswer.jsx @@ -21,9 +21,11 @@ const DateTimeAnswer = (props) => { // workaround because it is not possible to construct Date only with time let value; - if ((isTime || isDate) && props.value && props.value !== "0") { + if (isTime && props.value && props.value !== "0") { + value = new Date(`0 ${props.value}`); + } else if (isDate && props.value && props.value !== "0") { value = new Date(props.value); - } else value = null; + } else value = new Date(); // DatePicker does not know dateFormat "x", translate to datetime const datePickerFormat = diff --git a/src/components/answer/TypeaheadAnswer.jsx b/src/components/answer/TypeaheadAnswer.jsx index 25cda163..ccb33227 100644 --- a/src/components/answer/TypeaheadAnswer.jsx +++ b/src/components/answer/TypeaheadAnswer.jsx @@ -14,7 +14,7 @@ import { IntelligentTreeSelect } from "intelligent-tree-select/lib/components/In import "intelligent-tree-select/lib/styles.css"; const processTypeaheadOptions = (options, intl) => { - if (!options) { + if (!options || !options.length) { return []; }