-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed dayjs another local and calendar
- Loading branch information
Showing
5 changed files
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
packages/@mantine/dates/src/components/Month/get-end-of-week/get-end-of-week.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
packages/@mantine/dates/src/components/Month/get-start-of-week/get-start-of-week.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
8 changes: 6 additions & 2 deletions
8
packages/@mantine/dates/src/components/Month/is-same-month/is-same-month.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |