added constant for years range + added comment for month quirk

This commit is contained in:
Jonathan Labreuille
2016-01-22 13:38:43 +01:00
parent 8072b162d4
commit 3fbe5423d0

View File

@@ -6,10 +6,12 @@ define([
Moment Moment
) { ) {
class FormFieldDateYear extends React.Component { class FormFieldDateYear extends React.Component {
const yearsRange = 100;
render() { render() {
const years = []; const years = [];
const currentYear = Moment().year(); const currentYear = Moment().year();
for (let i = currentYear; i >= currentYear - 100; i--) { for (let i = currentYear; i >= currentYear - yearsRange; i--) {
years.push(( years.push((
<option <option
key={ i } key={ i }
@@ -100,6 +102,8 @@ define([
this.setState({ this.setState({
year: Moment.unix(timeStamp).year(), year: Moment.unix(timeStamp).year(),
// Moment returns the month as [0..11]
// We increment it to match PHP's mktime() which expects [1..12]
month: Moment.unix(timeStamp).month() + 1, month: Moment.unix(timeStamp).month() + 1,
day: Moment.unix(timeStamp).date() day: Moment.unix(timeStamp).date()
}); });