diff --git a/packages/form-js-viewer/src/render/components/form-fields/Datetime.js b/packages/form-js-viewer/src/render/components/form-fields/Datetime.js index d7edefd9c..c3cbe2390 100644 --- a/packages/form-js-viewer/src/render/components/form-fields/Datetime.js +++ b/packages/form-js-viewer/src/render/components/form-fields/Datetime.js @@ -86,7 +86,7 @@ export function Datetime(props) { switch (subtype) { case DATETIME_SUBTYPES.DATE: { - date = new Date(Date.parse(value)); + date = new Date(value ? value + 'T00:00' : NaN); break; } case DATETIME_SUBTYPES.TIME: { diff --git a/packages/form-js-viewer/src/render/components/util/dateTimeUtil.js b/packages/form-js-viewer/src/render/components/util/dateTimeUtil.js index a2c27de21..fe020bc85 100644 --- a/packages/form-js-viewer/src/render/components/util/dateTimeUtil.js +++ b/packages/form-js-viewer/src/render/components/util/dateTimeUtil.js @@ -145,16 +145,17 @@ export function parseIsoTime(isoTimeString) { } } +/** + * Returns the date object as a simple 'YYYY-MM-DD' formatted date in the local timezone. + * + * @param {*} date The date object to serialize. + * @returns {string} The serialized date. + */ export function serializeDate(date) { - var d = new Date(date), - month = '' + (d.getMonth() + 1), - day = '' + d.getDate(), - year = d.getFullYear(); - - if (month.length < 2) month = '0' + month; - if (day.length < 2) day = '0' + day; - - return [year, month, day].join('-'); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; } // this method is used to make the `new Date(value)` parsing behavior stricter