Skip to content
This repository was archived by the owner on Nov 16, 2018. It is now read-only.

Commit af8343d

Browse files
authored
add locale support
1 parent 268d2bd commit af8343d

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/DateTimePickerDays.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class DateTimePickerDays extends Component {
2222

2323
renderDays = () => {
2424
var cells, classes, days, html, month, nextMonth, prevMonth, minDate, maxDate, row, year;
25+
2526
year = this.props.viewDate.year();
2627
month = this.props.viewDate.month();
2728
prevMonth = this.props.viewDate.clone().subtract(1, "months");
@@ -65,9 +66,23 @@ export default class DateTimePickerDays extends Component {
6566
}
6667
prevMonth.add(1, "d");
6768
}
69+
6870
return html;
6971
}
7072

73+
renderDaysCaption() {
74+
// because of moment doesn't have api to get list of weekdays in local object (when we set locale locally)
75+
// we have to back up locale get weekdays and restore it
76+
let currentLocale = moment.locale();
77+
moment.locale(this.props.locale);
78+
let weekDays = moment.weekdaysMin(true);
79+
moment.locale(currentLocale);
80+
81+
return weekDays.map(function(day, i) {
82+
return <th key={i} className="dow">{day}</th>;
83+
}).concat();
84+
}
85+
7186
render() {
7287
return (
7388
<div className="datepicker-days" style={{display: "block"}}>
@@ -76,25 +91,13 @@ export default class DateTimePickerDays extends Component {
7691
<tr>
7792
<th className="prev" onClick={this.props.subtractMonth}><span className="glyphicon glyphicon-chevron-left" /></th>
7893

79-
<th className="switch" colSpan="5" onClick={this.props.showMonths}>{moment.months()[this.props.viewDate.month()]} {this.props.viewDate.year()}</th>
94+
<th className="switch" colSpan="5" onClick={this.props.showMonths}>{this.props.viewDate.format('MMMM')} {this.props.viewDate.year()}</th>
8095

8196
<th className="next" onClick={this.props.addMonth}><span className="glyphicon glyphicon-chevron-right" /></th>
8297
</tr>
8398

8499
<tr>
85-
<th className="dow">Su</th>
86-
87-
<th className="dow">Mo</th>
88-
89-
<th className="dow">Tu</th>
90-
91-
<th className="dow">We</th>
92-
93-
<th className="dow">Th</th>
94-
95-
<th className="dow">Fr</th>
96-
97-
<th className="dow">Sa</th>
100+
{this.renderDaysCaption()}
98101
</tr>
99102
</thead>
100103

@@ -106,4 +109,3 @@ export default class DateTimePickerDays extends Component {
106109
);
107110
}
108111
}
109-

0 commit comments

Comments
 (0)