Skip to content

Commit

Permalink
fixed dayjs another local and calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
baravak committed Dec 24, 2024
1 parent 41b8186 commit fa37282
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
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
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)
const start = day.subtract(day.date() - 1, 'day')
const startOfMonth = start.toDate();
const endOfMonth = start.add(+ day.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();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import dayjs from "dayjs";

export function isSameMonth(date: Date, comparison: Date) {
const dayDate = dayjs(date)
const dayComparison = dayjs(comparison)
return (
date.getFullYear() === comparison.getFullYear() && date.getMonth() === comparison.getMonth()
dayDate.year() === dayComparison.year() && dayDate.month() === dayComparison.month()
);
}
}

0 comments on commit fa37282

Please sign in to comment.