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

[@mantine/dates] Fix error with timezones in Month #5916

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@mantine/dates/src/components/Month/Month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export const Month = factory<MonthFactory>((_props, ref) => {
const dates = getMonthDays({
month,
firstDayOfWeek: ctx.getFirstDayOfWeek(firstDayOfWeek),
timezone: ctx.timezone || undefined,

Choose a reason for hiding this comment

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

It breaks test. You made it more understandable and safe by taking out the "timezone" property from both the function call and the object setup. This change guarantees that you're not trying to set a property that isn't recognized in the type definition of getMonthDays or the object itself.

Copy link
Member

Choose a reason for hiding this comment

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

What test does it break? The CI passed.

Choose a reason for hiding this comment

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

It no longer break tests. It was fixed after my comment

Copy link
Member

Choose a reason for hiding this comment

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

I did not get it. Is the PR fine or is there some issue that you've found?

Choose a reason for hiding this comment

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

It's fine

consistentWeeks: ctx.consistentWeeks,
});

Expand Down Expand Up @@ -243,6 +242,7 @@ export const Month = factory<MonthFactory>((_props, ref) => {
}}
onClick={(event) => {
dayProps?.onClick?.(event);

__onDayClick?.(event, date);
}}
onMouseDown={(event) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const defaultDates = getMonthDays({
month: new Date(2010, 5, 1),
firstDayOfWeek: 1,
consistentWeeks: false,
timezone: undefined,
});
const defaultMinDate = new Date(2000, 0);
const defaultMaxDate = new Date(2100, 0);
Expand Down Expand Up @@ -40,7 +39,6 @@ describe('@mantine/dates/get-date-in-tab-order', () => {
month: new Date(),
firstDayOfWeek: 1,
consistentWeeks: false,
timezone: undefined,
}),
defaultMinDate,
defaultMaxDate,
Expand All @@ -61,7 +59,6 @@ describe('@mantine/dates/get-date-in-tab-order', () => {
month: new Date(2010, 1, 1),
firstDayOfWeek: 1,
consistentWeeks: false,
timezone: undefined,
}),
defaultMinDate,
defaultMaxDate,
Expand Down Expand Up @@ -91,7 +88,6 @@ describe('@mantine/dates/get-date-in-tab-order', () => {
month: new Date(2010, 1, 1),
firstDayOfWeek: 1,
consistentWeeks: false,
timezone: undefined,
}),
defaultMinDate,
defaultMaxDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe('@mantine/dates/get-month-days', () => {
month: new Date(2021, 1, 2),
firstDayOfWeek: 1,
consistentWeeks: false,
timezone: undefined,
});
expect(monthDays).toHaveLength(4);

Expand All @@ -24,7 +23,6 @@ describe('@mantine/dates/get-month-days', () => {
const monthDays = getMonthDays({
month: new Date(2021, 1, 2),
firstDayOfWeek: 0,
timezone: undefined,
consistentWeeks: false,
});
expect(monthDays).toHaveLength(5);
Expand All @@ -42,7 +40,6 @@ describe('@mantine/dates/get-month-days', () => {
month: new Date(2021, 3, 2),
firstDayOfWeek: 1,
consistentWeeks: false,
timezone: undefined,
});

expect(monthDays).toHaveLength(5);
Expand All @@ -58,7 +55,6 @@ describe('@mantine/dates/get-month-days', () => {
month: new Date(2021, 3, 2),
firstDayOfWeek: 0,
consistentWeeks: false,
timezone: undefined,
});

expect(monthDays).toHaveLength(5);
Expand All @@ -74,7 +70,6 @@ describe('@mantine/dates/get-month-days', () => {
month: new Date(2021, 1, 2),
firstDayOfWeek: 1,
consistentWeeks: true,
timezone: undefined,
});

expect(monthDays).toHaveLength(6);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import { DayOfWeek } from '../../../types';
import { shiftTimezone } from '../../../utils';
import { getEndOfWeek } from '../get-end-of-week/get-end-of-week';
import { getStartOfWeek } from '../get-start-of-week/get-start-of-week';

interface GetMonthDaysInput {
month: Date;
firstDayOfWeek: DayOfWeek | undefined;
timezone: string | undefined;
consistentWeeks: boolean | undefined;
}

export function getMonthDays({
month,
firstDayOfWeek = 1,
timezone = undefined,
consistentWeeks,
}: GetMonthDaysInput): Date[][] {
const currentMonth = month.getMonth();
const startOfMonth = shiftTimezone(
'add',
new Date(month.getFullYear(), currentMonth, 1),
timezone
);
const endOfMonth = shiftTimezone(
'add',
new Date(month.getFullYear(), month.getMonth() + 1, 0),
timezone
);
const startOfMonth = new Date(month.getFullYear(), currentMonth, 1);
const endOfMonth = new Date(month.getFullYear(), month.getMonth() + 1, 0);
const endDate = getEndOfWeek(endOfMonth, firstDayOfWeek);
const date = getStartOfWeek(startOfMonth, firstDayOfWeek);
const weeks: Date[][] = [];
Expand Down
Loading