@@ -25,13 +25,13 @@ class Calendar extends Component {
2525 constructor ( props , context ) {
2626 super ( props , context ) ;
2727
28- const { format, range, theme, offset } = props ;
28+ const { format, range, theme, offset, firstDayOfWeek } = props ;
2929
3030 const date = parseInput ( props . date , format )
31-
3231 const state = {
3332 date,
3433 shownDate : ( range && range [ 'endDate' ] || date ) . clone ( ) . add ( offset , 'months' ) ,
34+ firstDayOfWeek : ( firstDayOfWeek || moment . localeData ( ) . firstDayOfWeek ( ) ) ,
3535 }
3636
3737 this . state = state ;
@@ -107,7 +107,7 @@ class Calendar extends Component {
107107 }
108108
109109 renderWeekdays ( ) {
110- const dow = moment . localeData ( ) . firstDayOfWeek ( ) ;
110+ const dow = this . state . firstDayOfWeek ;
111111 const weekdays = [ ] ;
112112 const { styles } = this ;
113113
@@ -124,30 +124,31 @@ class Calendar extends Component {
124124
125125 renderDays ( ) {
126126 // TODO: Split this logic into smaller chunks
127- const { styles } = this ;
127+ const { styles } = this ;
128128
129- const { range } = this . props ;
129+ const { range } = this . props ;
130130
131- const shownDate = this . getShownDate ( ) ;
132- const { date } = this . state ;
133- const dateUnix = date . unix ( ) ;
131+ const shownDate = this . getShownDate ( ) ;
132+ const { date, firstDayOfWeek } = this . state ;
133+ const dateUnix = date . unix ( ) ;
134134
135- const monthNumber = shownDate . month ( ) ;
136- const dayCount = shownDate . daysInMonth ( ) ;
137- const startOfMonth = shownDate . clone ( ) . startOf ( 'month' ) . weekday ( ) ;
135+ const monthNumber = shownDate . month ( ) ;
136+ const dayCount = shownDate . daysInMonth ( ) ;
137+ const startOfMonth = shownDate . clone ( ) . startOf ( 'month' ) . isoWeekday ( ) ;
138138
139- const lastMonth = shownDate . clone ( ) . month ( monthNumber - 1 ) ;
140- const lastMonthNumber = lastMonth . month ( ) ;
141- const lastMonthDayCount = lastMonth . daysInMonth ( ) ;
139+ const lastMonth = shownDate . clone ( ) . month ( monthNumber - 1 ) ;
140+ const lastMonthNumber = lastMonth . month ( ) ;
141+ const lastMonthDayCount = lastMonth . daysInMonth ( ) ;
142142
143- const nextMonth = shownDate . clone ( ) . month ( monthNumber + 1 ) ;
144- const nextMonthNumber = nextMonth . month ( ) ;
143+ const nextMonth = shownDate . clone ( ) . month ( monthNumber + 1 ) ;
144+ const nextMonthNumber = nextMonth . month ( ) ;
145145
146- const days = [ ] ;
146+ const days = [ ] ;
147147
148148 // Previous month's days
149- for ( let i = startOfMonth ; i >= 1 ; i -- ) {
150- const dayMoment = lastMonth . clone ( ) . date ( lastMonthDayCount + 1 - i ) ;
149+ const diff = ( Math . abs ( firstDayOfWeek - ( startOfMonth + 7 ) ) % 7 ) ;
150+ for ( let i = diff ; i >= 1 ; i -- ) {
151+ const dayMoment = lastMonth . clone ( ) . date ( lastMonthDayCount - i ) ;
151152 days . push ( { dayMoment, isPassive : true } ) ;
152153 }
153154
@@ -202,21 +203,22 @@ Calendar.defaultProps = {
202203}
203204
204205Calendar . propTypes = {
205- sets : PropTypes . string ,
206- range : PropTypes . shape ( {
207- startDate : PropTypes . object ,
208- endDate : PropTypes . object
206+ sets : PropTypes . string ,
207+ range : PropTypes . shape ( {
208+ startDate : PropTypes . object ,
209+ endDate : PropTypes . object
209210 } ) ,
210- date : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . string , PropTypes . func ] ) ,
211- format : PropTypes . string . isRequired ,
212- onChange : PropTypes . func ,
213- onInit : PropTypes . func ,
214- link : PropTypes . oneOfType ( [ PropTypes . shape ( {
215- startDate : PropTypes . object ,
216- endDate : PropTypes . object ,
211+ date : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . string , PropTypes . func ] ) ,
212+ format : PropTypes . string . isRequired ,
213+ firstDayOfWeek : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
214+ onChange : PropTypes . func ,
215+ onInit : PropTypes . func ,
216+ link : PropTypes . oneOfType ( [ PropTypes . shape ( {
217+ startDate : PropTypes . object ,
218+ endDate : PropTypes . object ,
217219 } ) , PropTypes . bool ] ) ,
218- linkCB : PropTypes . func ,
219- theme : PropTypes . object ,
220+ linkCB : PropTypes . func ,
221+ theme : PropTypes . object ,
220222}
221223
222224export default Calendar ;
0 commit comments