Skip to content

Commit 5c37001

Browse files
committed
used Intl for daylight savings
1 parent b870ded commit 5c37001

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

src/frontend/src/pages/CalendarPage/Components/ScheduleEventModal.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useToast } from '../../../hooks/toasts.hooks';
1313
import { formatEventTime } from 'shared';
1414
import { datePipe } from '../../../utils/pipes';
1515
import { routes } from '../../../utils/routes';
16-
import { formatHourInCurrentTimeZone, offsetDate } from '../../../utils/design-review.utils';
16+
import { offsetDate } from '../../../utils/design-review.utils';
1717

1818
interface ScheduleEventModalProps {
1919
open: boolean;
@@ -79,8 +79,7 @@ const ScheduleEventModal: React.FC<ScheduleEventModalProps> = ({
7979
>
8080
<Typography variant="h6">{datePipe(offsetDate(dateToShow()))}</Typography>
8181
<Typography variant="body1" color="text.secondary">
82-
{formatHourInCurrentTimeZone(formatEventTime(startTime))} -
83-
{formatHourInCurrentTimeZone(formatEventTime(endTime))}
82+
{formatEventTime(startTime)} -{formatEventTime(endTime)}
8483
</Typography>
8584
</Box>
8685

src/frontend/src/pages/CalendarPage/EventPartialInfoView.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { getTeamTypeIcon } from './CalendarDayCard';
77
import { Typography } from '@mui/material';
88

99
import { getMutedColor } from '../../utils/calendar.utils';
10-
import { formatHourInCurrentTimeZone } from '../../utils/design-review.utils';
1110

1211
interface EventInfoProps {
1312
event: EventInstance;
@@ -78,8 +77,7 @@ const EventPartialInfoView: React.FC<EventInfoProps> = ({ event, eventTypes, cal
7877
</Typography>
7978
) : (
8079
<Typography marginX={0.5} marginY={0.5} lineHeight={'120%'} fontSize={12} fontWeight="bold" align="left">
81-
{formatHourInCurrentTimeZone(formatEventTime(event.startTime))} -{' '}
82-
{formatHourInCurrentTimeZone(formatEventTime(event.endTime))}
80+
{formatEventTime(event.startTime)} - {formatEventTime(event.endTime)}
8381
</Typography>
8482
)}
8583
</Stack>

src/frontend/src/utils/design-review.utils.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,21 @@ export const HeatmapColors = ['#D9D9D9', '#C1E0C1', '#9BE89B', '#7AE47A', '#45EF
5454

5555
export const NUMBER_OF_TIME_SLOTS = enumToArray(REVIEW_TIMES).length * enumToArray(DAY_NAMES).length;
5656

57-
const nthWeekday = (year: number, month: MONTH_NAMES, weekday: DAY_NAMES, nth: number) => {
58-
const day = new Date(year, month!, 1);
59-
const dayDiff = (weekday! - day.getDay() + 7) % 7;
57+
const ESTOffset = () => {
58+
const parts = new Intl.DateTimeFormat('en', {
59+
timeZone: 'America/New_York',
60+
timeZoneName: 'shortOffset'
61+
}).formatToParts(new Date());
6062

61-
return new Date(year, month, 1 + dayDiff + (nth - 1) * 7);
62-
};
63-
64-
const daylightSavings = () => {
65-
const currDate = new Date();
63+
const GMTTime = parts.find((t) => t.type === 'timeZoneName');
64+
const offsetEST = Number(GMTTime!.value.replace('GMT', ''));
6665

67-
const start = nthWeekday(currDate.getFullYear(), MONTH_NAMES.March, DAY_NAMES.Sunday, 2);
68-
const end = nthWeekday(currDate.getFullYear(), MONTH_NAMES.November, DAY_NAMES.Sunday, 1);
69-
return currDate >= start && currDate < end;
66+
return offsetEST;
7067
};
7168

7269
export const userOffsetTime = () => {
7370
const UTCOffset = -new Date().getTimezoneOffset() / 60;
74-
const EST = daylightSavings() ? -4 : -5;
71+
const EST = ESTOffset();
7572
const userOffset = UTCOffset - EST;
7673
return userOffset;
7774
};

0 commit comments

Comments
 (0)