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

fixed dayjs another local and calendar #7302

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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/Day/Day.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const Day = factory<DayFactory>((_props, ref) => {
unstyled={unstyled}
{...others}
>
{renderDay?.(date) || date.getDate()}
{renderDay?.(date) || dayjs(date).date()}
</UnstyledButton>
);
});
Expand Down
3 changes: 1 addition & 2 deletions packages/@mantine/dates/src/components/Month/Month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { getMonthDays } from './get-month-days/get-month-days';
import { getWeekNumber } from './get-week-number/get-week-number';
import { isAfterMinDate } from './is-after-min-date/is-after-min-date';
import { isBeforeMaxDate } from './is-before-max-date/is-before-max-date';
import { isSameMonth } from './is-same-month/is-same-month';
import classes from './Month.module.css';

export type MonthStylesNames =
Expand Down Expand Up @@ -216,7 +215,7 @@ export const Month = factory<MonthFactory>((_props, ref) => {

const rows = dates.map((row, rowIndex) => {
const cells = row.map((date, cellIndex) => {
const outside = !isSameMonth(date, month);
const outside = !dayjs(date).isSame(dayjs(month), 'month');
const ariaLabel =
getDayAriaLabel?.(date) ||
dayjs(date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import dayjs from 'dayjs';
import { DayProps } from '../../Day/Day';
import { isAfterMinDate } from '../is-after-min-date/is-after-min-date';
import { isBeforeMaxDate } from '../is-before-max-date/is-before-max-date';
import { isSameMonth } from '../is-same-month/is-same-month';

export function getDateInTabOrder(
dates: Date[][],
Expand All @@ -21,7 +20,7 @@ export function getDateInTabOrder(
isAfterMinDate(date, minDate) &&
!excludeDate?.(date) &&
!getDateControlProps?.(date)?.disabled &&
(!hideOutsideDates || isSameMonth(date, month))
(!hideOutsideDates || dayjs(date).isSame(dayjs(month), 'month'))
);

const selectedDate = enabledDates.find((date) => getDateControlProps?.(date)?.selected);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import dayjs from 'dayjs';
import type { DayOfWeek } from '../../../types';

export function getEndOfWeek(date: Date, firstDayOfWeek: DayOfWeek = 1) {
const value = new Date(date);
const lastDayOfWeek = firstDayOfWeek === 0 ? 6 : firstDayOfWeek - 1;
let value = dayjs(date);

while (value.getDay() !== lastDayOfWeek) {
value.setDate(value.getDate() + 1);
const lastDayOfWeek = firstDayOfWeek === 0 ? 6 : firstDayOfWeek - 1;
while (value.day() !== lastDayOfWeek) {
value = value.add(1, 'day');
}

return value;
return value.toDate();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dayjs from 'dayjs';
import { DayOfWeek } from '../../../types';
import { getEndOfWeek } from '../get-end-of-week/get-end-of-week';
import { getStartOfWeek } from '../get-start-of-week/get-start-of-week';
Expand All @@ -13,9 +14,10 @@ export function getMonthDays({
firstDayOfWeek = 1,
consistentWeeks,
}: GetMonthDaysInput): Date[][] {
const currentMonth = month.getMonth();
const startOfMonth = new Date(month.getFullYear(), currentMonth, 1);
const endOfMonth = new Date(month.getFullYear(), month.getMonth() + 1, 0);
const day = dayjs(month).subtract(dayjs(month).date() - 1, 'day');
const start = dayjs(day.format('YYYY-M-D'));
const startOfMonth = start.toDate();
const endOfMonth = start.add(+start.daysInMonth() - 1, 'day').toDate();
const endDate = getEndOfWeek(endOfMonth, firstDayOfWeek);
const date = getStartOfWeek(startOfMonth, firstDayOfWeek);
const weeks: Date[][] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import dayjs from 'dayjs';
import type { DayOfWeek } from '../../../types';

export function getStartOfWeek(date: Date, firstDayOfWeek: DayOfWeek = 1) {
const value = new Date(date);

while (value.getDay() !== firstDayOfWeek) {
value.setDate(value.getDate() - 1);
let value = dayjs(date);
while (value.day() !== firstDayOfWeek) {
value = value.subtract(1, 'day');
}

return value;
return value.toDate();
}
1 change: 0 additions & 1 deletion packages/@mantine/dates/src/components/Month/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export { getEndOfWeek } from './get-end-of-week/get-end-of-week';
export { getStartOfWeek } from './get-start-of-week/get-start-of-week';
export { getMonthDays } from './get-month-days/get-month-days';
export { isSameMonth } from './is-same-month/is-same-month';

export { Month } from './Month';
export type { MonthProps, MonthSettings, MonthStylesNames, MonthFactory } from './Month';

This file was deleted.

This file was deleted.

Loading