Skip to content

Commit

Permalink
fix: ensure dates are parsed timezone agnostically
Browse files Browse the repository at this point in the history
Closes #1223
  • Loading branch information
vladislav-karamfilov authored and Skaiir committed Aug 14, 2024
1 parent bea07f4 commit ccd0d7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
19 changes: 10 additions & 9 deletions packages/form-js-viewer/src/render/components/util/dateTimeUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ccd0d7a

Please sign in to comment.