File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import * as React from 'react';
3
3
import type { PanelMode , SharedPanelProps } from '../../interface' ;
4
4
import {
5
5
formatValue ,
6
+ getNumberOfWeeksInMonth ,
6
7
getWeekStartDate ,
7
8
isSameDate ,
8
9
isSameMonth ,
@@ -50,6 +51,13 @@ export default function DatePanel<DateType extends object = any>(props: DatePane
50
51
const baseDate = getWeekStartDate ( locale . locale , generateConfig , monthStartDate ) ;
51
52
const month = generateConfig . getMonth ( pickerValue ) ;
52
53
54
+ const numberOfWeeksInMonth = getNumberOfWeeksInMonth (
55
+ generateConfig ,
56
+ pickerValue ,
57
+ weekFirstDay ,
58
+ locale . locale ,
59
+ ) ;
60
+
53
61
// =========================== PrefixColumn ===========================
54
62
const showPrefixColumn = showWeek === undefined ? isWeek : showWeek ;
55
63
const prefixColumn = showPrefixColumn
@@ -199,7 +207,7 @@ export default function DatePanel<DateType extends object = any>(props: DatePane
199
207
titleFormat = { locale . fieldDateFormat }
200
208
{ ...props }
201
209
colNum = { WEEK_DAY_COUNT }
202
- rowNum = { 6 }
210
+ rowNum = { numberOfWeeksInMonth }
203
211
baseDate = { baseDate }
204
212
// Header
205
213
headerCells = { headerCells }
Original file line number Diff line number Diff line change 1
1
import type { GenerateConfig } from '../generate' ;
2
2
import type { CustomFormat , InternalMode , Locale , NullableDateType } from '../interface' ;
3
+ import { differenceInCalendarWeeks , lastDayOfMonth , startOfMonth } from 'date-fns' ;
3
4
4
5
export const WEEK_DAY_COUNT = 7 ;
5
6
@@ -270,3 +271,27 @@ export function fillTime<DateType>(
270
271
271
272
return tmpDate ;
272
273
}
274
+
275
+ type WeekStartsOnType = 0 | 3 | 1 | 4 | 2 | 5 | 6 ;
276
+
277
+ export function getNumberOfWeeksInMonth < DateType > (
278
+ generateConfig : GenerateConfig < DateType > ,
279
+ date : DateType ,
280
+ weekFirstDay : number ,
281
+ locale : string ,
282
+ ) {
283
+ const _date = new Date (
284
+ generateConfig . getYear ( date ) ,
285
+ generateConfig . getMonth ( date ) ,
286
+ generateConfig . getDate ( date ) ,
287
+ ) ;
288
+
289
+ return (
290
+ differenceInCalendarWeeks ( lastDayOfMonth ( _date ) , startOfMonth ( _date ) , {
291
+ weekStartsOn : weekFirstDay as WeekStartsOnType ,
292
+ locale : {
293
+ code : locale ,
294
+ } ,
295
+ } ) + 1
296
+ ) ;
297
+ }
You can’t perform that action at this time.
0 commit comments