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: #15833 [CAL-4055] Same first slot in different timezones #15840

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

vijayraghav-io
Copy link
Contributor

@vijayraghav-io vijayraghav-io commented Jul 19, 2024

What does this PR do?

After Changes -
https://www.loom.com/share/d3e067e558184cd2aa7e62ca2e48c770?sid=76ab6332-5e38-4421-8247-e76991fa4751

Root cause -
The minDate, used to set the start date in getAvailableDatesInMonth was using browserDate, updated this to calculate today's date in selected timezone.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A-I have added a Docs issue here if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Copy link

vercel bot commented Jul 19, 2024

@vijayraghav-io is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot requested a review from a team July 19, 2024 20:11
@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jul 19, 2024
@github-actions github-actions bot added bookings area: bookings, availability, timezones, double booking 🐛 bug Something isn't working labels Jul 19, 2024
@dosubot dosubot bot added the ui area: UI, frontend, button, form, input label Jul 19, 2024
Copy link

graphite-app bot commented Jul 19, 2024

Graphite Automations

"Add community label" took an action on this PR • (07/19/24)

1 label was added to this PR based on Keith Williams's automation.

"Add consumer team as reviewer" took an action on this PR • (07/19/24)

1 reviewer was added to this PR based on Keith Williams's automation.

@vijayraghav-io vijayraghav-io changed the title fix: #15833 [CAL-4055] Not able to book a time on a date that is earlier than today fix: #15833 [CAL-4055] Same first slot in different timezones Jul 19, 2024
const includedDates = getAvailableDatesInMonth({
browsingDate: browsingDate.toDate(),
minDate,
minDate: getTodaysDateInTimeZone(timezone),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, instead of setting the minimum date here, can we modify or pass it from the Datepicker? This way, we eliminate the need for an extra prop like timezone and also minDate prop used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained below anyway we will have to pass one of the prop, if its minDate, we will have to pass from DatePickerComponent which is in packages/features/bookings/Booker/Components/DatePicker.tsx.

FYR, there are two different DatePicker.tsx files.
So this should be ok.

@@ -414,6 +423,7 @@ const DatePicker = ({
slots={!isBookingInPast ? slots : {}}
includedDates={!isBookingInPast ? includedDates : []}
isBookingInPast={isBookingInPast}
timezone={timezone}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing the timezone, can we set or modify the minDate from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained, refer other comments.

@@ -38,6 +39,7 @@ export const DatePicker = ({
shallow
);
const nonEmptyScheduleDays = useNonEmptyScheduleDays(schedule?.data?.slots);
const { timezone } = useTimePreferences();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vijayraghav-io, can we do the same directly inside the DatePickerComponent instead of passing it from here?

Copy link
Contributor Author

@vijayraghav-io vijayraghav-io Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i started with having useTimePreferences() inside <Days component, everything works fine w.r.t this fix and functionality.

But when i ran the complete tests, the test "date-override-list.test.tsx" fails without even showing proper error message.
I found it in really hard way spending so much time, then finally found that - useTimePreferences() inside Days() component or even inside getTodaysDateInTimeZone.ts was causing this test to fail.

components/DatePicker.tsx is the nearest parent component which was not throwing this test fail.

// 'todayDateInPreferredTZ' is dayjs date, we need to convert this into type 'Date',
// as input required for getAvailableDatesInMonth() is 'Date' type.
const offsetMinutes = dayjs().utcOffset();
const jsDate = new Date(`${todayDateInPreferredTZ.format("YYYY-MM-DDTHH:mm:ss")}Z`); // UTC format
Copy link
Contributor

@anikdhabal anikdhabal Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of jsDate can we set localDate or currentDate ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am intending to be Date of type Date (JS/TS native object), as we can also get date from Dayjs().toDate() but this will again give date in local timezone

// Example :
// Consider browser current date-time is - "Sat Jul 20 2024 01:00:00 AM (Asia/Kolkata GMT +5:30)".
// And, if preferred timezone is "Pacific/Pago GMT -11:00", we need to get today's date as "Fri Jul 19".
export function getTodaysDateInTimeZone(selectedTimeZone: string | undefined): Date {
Copy link
Contributor

@anikdhabal anikdhabal Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectedTimeZone must not be undefined

Copy link
Contributor Author

@vijayraghav-io vijayraghav-io Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be an issue, because always there will be a timezone selection in booking page and also there is a default value provided here

timezone: localStorage.getItem(timezoneLocalStorageKey) || dayjs.tz.guess() || "Europe/London",

| undefined was added for typechecks ,because DatePicker prop should have timezone as optional , to be compatible with dependent components

Copy link
Contributor

@anikdhabal anikdhabal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unit test for this?

Copy link
Contributor

@anikdhabal anikdhabal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vijayraghav-io great works. Left some comment. Let me know what you think?

@anikdhabal anikdhabal requested a review from hariombalhara July 20, 2024 06:14
@hariombalhara hariombalhara requested a review from emrysal July 20, 2024 06:51
@vijayraghav-io
Copy link
Contributor Author

Can we add a unit test for this?

Yes i am adding

@vijayraghav-io
Copy link
Contributor Author

@vijayraghav-io great works. Left some comment. Let me know what you think?

Thankyou! replied inline

@vijayraghav-io
Copy link
Contributor Author

@vijayraghav-io
Copy link
Contributor Author

@emrysal , can you please share your comments/reviews

@PeerRich PeerRich added this to the Community Only milestone Jul 31, 2024
@keithwillcode keithwillcode requested a review from a team July 31, 2024 15:09
@github-actions github-actions bot added the High priority Created by Linear-GitHub Sync label Aug 9, 2024
@vijayraghav-io
Copy link
Contributor Author

vijayraghav-io commented Aug 9, 2024

reminding to please review or approve if reviewed

@vijayraghav-io
Copy link
Contributor Author

vijayraghav-io commented Oct 3, 2024

Could we also fix this dot that is shown on the current day?
Everything else looks good to me 🙏

Thankyou! 🙏 , Sure have fixed the dot to show as per selected timezone's 'today' and verified.

@CarinaWolli CarinaWolli requested a review from anikdhabal October 3, 2024 13:42
Copy link
Contributor

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Oct 18, 2024
@vijayraghav-io
Copy link
Contributor Author

Gentle Reminder!

Copy link
Contributor

github-actions bot commented Oct 24, 2024

E2E results are ready!

Comment on lines 20 to 21
// 'todayDateInPreferredTZ' is dayjs date, we need to convert this into type 'Date',
// as input required for getAvailableDatesInMonth() is 'Date' type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pls remove this extra comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduced the overall comments

Comment on lines 6 to 10
// with new Date(), we get browser's current date.
// The below function gets today's date w.r.t to selected timezone.
// Example :
// Consider browser current date-time is - "Sat Jul 20 2024 01:00:00 AM (Asia/Kolkata GMT +5:30)".
// And, if preferred timezone is "Pacific/Pago GMT -11:00", we need to get today's date as "Fri Jul 19".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduced to 1-2 lines, as i feel it's important and also for someone who is sees/reviews this code for first time.
The question may come for anybody seeing this for first time, why not use already existing function to get current date in timezone.
That's why had added detailed explanation, now reduced to just 2 lines.

Comment on lines 324 to 328
// We need to set minDate to today's (or current) date w.r.t selected timezone.
// If we just do new Date(), we get browser's current date.
// getTodaysDateInTimeZone() function gets today's date w.r.t to selected timezone.
// Returned Date will be of type Date (native TS/JS Date type).
// As getAvailableDatesInMonth() function requires minDate in TS/JS Date type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to explain everything in detail in a comment; just add important points if necessary. Instead try to self-review the code with explanations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this and added as self review comment

@@ -309,6 +321,8 @@ const DatePicker = ({
};
scrollToTimeSlots?: () => void;
}) => {
const minDate = getTodaysDateInTimeZone(selectedTimeZone);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to set minDate to today's (or current) date w.r.t selected timezone.
If we just do new Date(), we get browser's current date.
getTodaysDateInTimeZone() function gets today's date w.r.t to selected timezone.
Returned Date will be of type Date (native TS/JS Date type).
As getAvailableDatesInMonth() function requires minDate in TS/JS Date type.

@vijayraghav-io
Copy link
Contributor Author

@anikdhabal , have addressed your latest comments.

@keithwillcode keithwillcode added Medium priority Created by Linear-GitHub Sync and removed High priority Created by Linear-GitHub Sync labels Nov 13, 2024
@keithwillcode keithwillcode modified the milestones: Community Only, v4.7, v4.8 Nov 13, 2024
@dosubot dosubot bot removed this from the v4.8 milestone Nov 29, 2024
@github-actions github-actions bot added the High priority Created by Linear-GitHub Sync label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bookings area: bookings, availability, timezones, double booking 🐛 bug Something isn't working community Created by Linear-GitHub Sync High priority Created by Linear-GitHub Sync Medium priority Created by Linear-GitHub Sync ready-for-e2e ui area: UI, frontend, button, form, input
Projects
None yet
6 participants