Skip to content

Commit 10cfe84

Browse files
authored
* fix: issue jquense#2534 this commit fixes the issues mentioned in jquense#2534
1 parent 652502f commit 10cfe84

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const MyCalendar = (props) => (
123123
Note that the dayjsLocalizer extends Day.js with the following plugins:
124124

125125
- [IsBetween](https://day.js.org/docs/en/plugin/is-between)
126+
- [IsLeapYear](https://day.js.org/docs/en/plugin/is-leap-year)
126127
- [IsSameOrAfter](https://day.js.org/docs/en/plugin/is-same-or-after)
127128
- [IsSameOrBefore](https://day.js.org/docs/en/plugin/is-same-or-before)
128129
- [LocaleData](https://day.js.org/docs/en/plugin/locale-data)

src/Month.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class MonthView extends React.Component {
160160

161161
readerDateHeading = ({ date, className, ...props }) => {
162162
let { date: currentDate, getDrilldownView, localizer } = this.props
163-
let isOffRange = localizer.neq(date, currentDate, 'month')
163+
let isOffRange = localizer.neq(currentDate, date, 'month')
164164
let isCurrent = localizer.isSameDate(date, currentDate)
165165
let drilldownView = getDrilldownView(date)
166166
let label = localizer.format(date, 'dateFormat')

src/localizers/dayjs.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import localeData from 'dayjs/plugin/localeData'
1010
import localizedFormat from 'dayjs/plugin/localizedFormat'
1111
import minMax from 'dayjs/plugin/minMax'
1212
import utc from 'dayjs/plugin/utc'
13+
import isLeapYear from 'dayjs/plugin/isLeapYear'
1314

1415
const weekRangeFormat = ({ start, end }, culture, local) =>
1516
local.format(start, 'MMMM DD', culture) +
@@ -70,6 +71,7 @@ export default function (dayjsLib) {
7071
dayjsLib.extend(localizedFormat)
7172
dayjsLib.extend(minMax)
7273
dayjsLib.extend(utc)
74+
dayjsLib.extend(isLeapYear)
7375

7476
const locale = (dj, c) => (c ? dj.locale(c) : dj)
7577

@@ -238,7 +240,15 @@ export default function (dayjsLib) {
238240
}
239241

240242
function firstVisibleDay(date) {
241-
return dayjs(date).startOf('month').startOf('week').toDate()
243+
const firstDayOfMonth = dayjs(date).startOf('month')
244+
let firstDayOfWeek = dayjs(firstDayOfMonth).startOf('week')
245+
// special handling for leapyears until Dayjs patches it
246+
if (dayjs(firstDayOfMonth).isLeapYear()) {
247+
const day = firstDayOfMonth.toDate().getDay(),
248+
diff = firstDayOfMonth.toDate().getDate() - day + (day == 0 ? -6 : 1)
249+
firstDayOfWeek.date(diff)
250+
}
251+
return firstDayOfWeek.toDate()
242252
}
243253

244254
function lastVisibleDay(date) {

0 commit comments

Comments
 (0)