Skip to content

Commit

Permalink
fix(calendar): timezone bug (#2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuLaValva authored Nov 16, 2023
1 parent 5cb9448 commit 1454de8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/components/ebay-calendar/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ export default class extends Marko.Component {
// In this case, we leave the tabindex and position as is. This is a fall-through case.
}
}
while (
this.state.disableAfter &&
this.getMonthDate(
this.state.offset + (input.numMonths || 1) - 1
).toISOString() > this.state.disableAfter
) {
this.state.offset--;
}
}

/**
Expand Down Expand Up @@ -240,8 +248,7 @@ export default class extends Marko.Component {
getMonthDate(offset) {
const baseDate = fromISO(this.state.baseISO);
const date = new Date(
baseDate.getUTCFullYear(),
baseDate.getUTCMonth() + offset
Date.UTC(baseDate.getUTCFullYear(), baseDate.getUTCMonth() + offset)
);
return date;
}
Expand All @@ -254,11 +261,13 @@ export default class extends Marko.Component {
const baseDate = fromISO(this.state.baseISO);
return toISO(
new Date(
baseDate.getUTCFullYear(),
baseDate.getUTCMonth() +
this.state.offset +
(input.numMonths || 1),
0
Date.UTC(
baseDate.getUTCFullYear(),
baseDate.getUTCMonth() +
this.state.offset +
(input.numMonths || 1),
0
)
)
);
}
Expand Down Expand Up @@ -292,7 +301,9 @@ export default class extends Marko.Component {
year: "numeric",
}
);
return formatter.format(date);
return formatter.format(
new Date(date.getUTCFullYear(), date.getUTCMonth())
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/ebay-calendar/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ $ var a11ySeparator = input.a11ySeparator ?? " - ";
$ endDate = daysInMonth;
</else-if>
<for|day| from=startDate to=endDate>
$ var dayISO = toISO(new Date(year, month, day));
$ var dayISO = toISO(new Date(Date.UTC(year, month, day)));
$ var isToday = dayISO === state.todayISO;
$ var isSelected = (Array.isArray(input.selected)
? input.selected.some((iso) => iso === dayISO)
Expand Down

0 comments on commit 1454de8

Please sign in to comment.