fix(datetime): account for 30 and 45 minute timezones when getting current date (#25120)

resolves #25112
This commit is contained in:
Liam DeBeasi
2022-04-14 22:54:11 +05:45
committed by GitHub
parent 1b407abdf5
commit 96b2003b2b

View File

@ -27,7 +27,24 @@ export const getToday = () => {
* there was a net change of zero hours from the
* local date.
*/
date.setHours(date.getHours() - tzOffset / 60);
const adjustedHours = date.getHours() - tzOffset / 60;
/**
* Some timezones include minute adjustments
* such as 30 or 45 minutes.
* Example: India Standard Time
* Timezone offset: -330 = -5.5 hours.
*
* As a result, we need to make sure we also
* increment the minutes as well.
* List of timezones with 30 and 45 minute timezones:
* https://www.timeanddate.com/time/time-zones-interesting.html
*/
const minutesRemainder = adjustedHours % 1;
const adjustedMinutes = date.getMinutes() + minutesRemainder * 60;
date.setHours(adjustedHours);
date.setMinutes(adjustedMinutes);
return date.toISOString();
};