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 d089fbd
Show file tree
Hide file tree
Showing 2 changed files with 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,10 @@ export function parseIsoTime(isoTimeString) {
}

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 d089fbd

Please sign in to comment.