Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(calendar): account for timezones with "today" calculation #2246

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-mirrors-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ebay/ebayui-core": patch
---

Use local time in calendar
11 changes: 11 additions & 0 deletions src/common/dates/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,21 @@ export function dateArgToISO(arg: DateConstructor["arguments"]) {
return /^\d\d\d\d-\d\d-\d\d$/g.test(date) ? date : undefined;
}

/**
* ISO 8601 date format (YYYY-MM-DD) in **UTC** timezone
*/
export function toISO(date: Date): DayISO {
return date.toISOString().slice(0, 10) as DayISO;
}

/**
* ISO 8601 date format (YYYY-MM-DD) in **local** timezone
*/
export function toLocalISO(date: Date): DayISO {
// This works because Canada uses the YYYY-MM-DD format
return date.toLocaleDateString("en-CA") as DayISO;
}

export function fromISO(iso: DayISO) {
return new Date(iso);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ebay-calendar/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getWeekdayInfo,
offsetISO,
toISO,
toLocalISO,
type DayISO,
} from "../../common/dates/date-utils";
import { localeDefault } from "../../common/dates";
Expand Down Expand Up @@ -67,7 +68,7 @@ class Calendar extends Marko.Component<Input, State> {
onCreate(input: Input) {
this.locale = input.locale;
const { firstDayOfWeek, weekdayLabels } = getWeekdayInfo(input.locale);
const todayISO = toISO(new Date());
const todayISO = toLocalISO(new Date());
this.state = {
focusISO: null,
baseISO: todayISO,
Expand Down
Loading