-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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/DST issues #7462
Merged
Merged
Fix/DST issues #7462
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f0c8e49
use the organizer timezone and invitee timezone to show slots
roae 57e792e
Merge branch 'main' into fix/DSTissues
roae be5feb8
type fixes
roae b882458
Merge branch 'main' into fix/DSTissues
emrysal 55e7ddf
Merge branch 'main' into fix/DSTissues
zomars a960745
set start date on selected TZ on booking payload
roae 2cfab52
add considerations when only the invitee is on DTS
roae bdf6a1a
Merge branch 'fix/DSTissues' of https://github.com/calcom/cal.com int…
roae 6fdbee4
Merge branch 'main' into fix/DSTissues
alannnc d595e49
Apply suggestions from code review
roae f08199c
fixes typo
roae 3ad3e20
Apply suggestions from code review
roae ec397f2
cleaning
roae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,3 +126,69 @@ export const isNextDayInTimezone = (time: string, timezoneA: string, timezoneB: | |
const timezoneBIsLaterTimezone = sortByTimezone(timezoneA, timezoneB) === -1; | ||
return hoursTimezoneBIsEarlier && timezoneBIsLaterTimezone; | ||
}; | ||
|
||
/** | ||
* Dayjs does not expose the timeZone value publicly through .get("timeZone") | ||
* instead, we as devs are required to somewhat hack our way to get the | ||
* tz value as string | ||
* @param date Dayjs | ||
* @returns Time Zone name | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const getTimeZone = (date: Dayjs): string => (date as any)["$x"]["$timezone"]; | ||
|
||
/** | ||
* Verify if timeZone has Daylight Saving Time (DST). | ||
* | ||
* Many countries in the Northern Hemisphere. Daylight Saving Time usually starts in March-April and ends in | ||
* September-November when the countries return to standard time, or winter time as it is also known. | ||
* | ||
* In the Southern Hemisphere (south of the equator) the participating countries usually start the DST period | ||
* in September-November and end DST in March-April. | ||
* | ||
* @param timeZone Time Zone Name (Ex. America/Mazatlan) | ||
* @returns boolean | ||
*/ | ||
export const timeZoneWithDST = (timeZone: string): boolean => { | ||
const jan = dayjs.tz(`${new Date().getFullYear()}-01-01T00:00:00`, timeZone); | ||
const jul = dayjs.tz(`${new Date().getFullYear()}-07-01T00:00:00`, timeZone); | ||
return jan.utcOffset() !== jul.utcOffset(); | ||
}; | ||
|
||
/** | ||
* Get DST difference. | ||
* Today clocks are almost always set one hour back or ahead. | ||
* However, on Lord Howe Island, Australia, clocks are set only 30 minutes forward | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥲 |
||
* from LHST (UTC+10:30) to LHDT (UTC+11) during DST. | ||
* @param timeZone Time Zone Name (Ex. America/Mazatlan) | ||
* @returns minutes | ||
*/ | ||
export const getDSTDifference = (timeZone: string): number => { | ||
const jan = dayjs.tz(`${new Date().getFullYear()}-01-01T00:00:00`, timeZone); | ||
const jul = dayjs.tz(`${new Date().getFullYear()}-07-01T00:00:00`, timeZone); | ||
return jul.utcOffset() - jan.utcOffset(); | ||
}; | ||
|
||
/** | ||
* Get UTC offset of given time zone when in DST | ||
* @param timeZone Time Zone Name (Ex. America/Mazatlan) | ||
* @returns minutes | ||
*/ | ||
export const getUTCOffsetInDST = (timeZone: string) => { | ||
if (timeZoneWithDST(timeZone)) { | ||
const jan = dayjs.tz(`${new Date().getFullYear()}-01-01T00:00:00`, timeZone); | ||
const jul = dayjs.tz(`${new Date().getFullYear()}-07-01T00:00:00`, timeZone); | ||
return jan.utcOffset() < jul.utcOffset() ? jul.utcOffset() : jan.utcOffset(); | ||
} | ||
return 0; | ||
}; | ||
/** | ||
* Verifies if given time zone is in DST | ||
* @param date | ||
* @returns | ||
*/ | ||
export const isInDST = (date: Dayjs) => { | ||
const timeZone = getTimeZone(date); | ||
|
||
return timeZoneWithDST(timeZone) && date.utcOffset() === getUTCOffsetInDST(timeZone); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does Toronto has a special DST/TZ?
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.
No, nothing special