-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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: Display the correct remaining dates in given tz #19389
base: main
Are you sure you want to change the base?
Conversation
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details:
|
Graphite Automations"Add foundation team as reviewer" took an action on this PR • (02/19/25)1 reviewer was added to this PR based on Keith Williams's automation. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
@@ -160,7 +160,7 @@ const Days = ({ | |||
const weekdayOfFirst = browsingDate.date(1).day(); | |||
|
|||
const includedDates = getAvailableDatesInMonth({ | |||
browsingDate: browsingDate.toDate(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was losing the information given in the browsingDate, which includes custom tz's selected through the timezone selector. getAvailableDatesInMonth needs this.
expect(result).toHaveLength(daysInMonth(currentDate) - currentDate.getDate() + 1); | ||
} | ||
{ | ||
const currentDate = dayjs().startOf("month"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests the remaining available dates are cut off according to the current time, even if the "currentDate" is in the past.
@@ -82,4 +98,47 @@ describe("Test Suite: Date Picker", () => { | |||
vi.useRealTimers(); | |||
}); | |||
}); | |||
|
|||
test("it returns the current date in selected timezone", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are (a slightly simplified) copy of #15840 - thanks @vijayraghav-io 🙏
import dayjs from "@calcom/dayjs"; | ||
import { daysInMonth, yyyymmdd } from "@calcom/lib/date-fns"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rely fully on Dayjs for now (until we have a TimezonedDate object to efficiently pass the wrapped Date object complimented by booker tz.
minDate?: Date; | ||
includedDates?: string[]; | ||
}) { | ||
// get minDate but with the same UTC offset as the browsingDate. | ||
const minDayjs = dayjs(minDate).utcOffset(browsingDate.utcOffset()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not possible without hacks to get the original timezone from the passed date, but we only need UTC offset granularity to shift the min start time for dateString determination.
// or is the same day, in the same month, in the same year. | ||
date < lastDateOfMonth || dayjs(date).isSame(lastDateOfMonth, "day"); | ||
date = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1) | ||
date.valueOf() <= lastDateOfMonth.valueOf(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more efficient isSameOrBefore check - needed as isSame on a tz'ed Date is not efficient.
This doesn't fix the issue for me. See the loom what I tested: https://www.loom.com/share/cb914fe7f1f34274bacb2ccb27e6a4c3 |
Just in case, if decision is made to go back with this PR - #15840 |
What does this PR do?
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
See tests.