marquex
2015-10-14 692390104a4e1409fb99a1be69026af876ecac06
Merges addition of strictParsing attribute.
3 files modified
32 ■■■■■ changed files
DateTime.js 9 ●●●●● patch | view | raw | blame | history
README.md 1 ●●●● patch | view | raw | blame | history
tests/datetime-spec.js 22 ●●●●● patch | view | raw | blame | history
DateTime.js
@@ -31,7 +31,9 @@
        // timeFormat: TYPES.string | TYPES.bool,
        inputProps: TYPES.object,
        viewMode: TYPES.oneOf(['years', 'months', 'days', 'time']),
        isValidDate: TYPES.func
        isValidDate: TYPES.func,
        open: TYPES.bool,
        strictParsing: TYPES.bool
    },
    getDefaultProps: function() {
@@ -45,7 +47,8 @@
            onBlur: nof,
            onChange: nof,
            timeFormat: true,
            dateFormat: true
            dateFormat: true,
            strictParsing: true
        };
    },
@@ -259,7 +262,7 @@
    },
    localMoment: function( date, format ){
        var m = moment( date, format );
        var m = moment( date, format, this.props.strictParsing );
        if( this.props.locale )
            m.locale( this.props.locale );
        return m;
README.md
@@ -52,6 +52,7 @@
| **renderDay** | function | DOM.td( day ) | Customize the way that the days are shown in the day picker. The accepted function has the `selectedDate`, the current date and the default calculated `props` for the cell, and must return a React component. See [appearance customization](#appearance-customization) |
| **renderMonth** | function | DOM.td( month ) | Customize the way that the months are shown in the month picker. The accepted function has the `selectedDate`, the current date and the default calculated `props` for the cell, the `month` and the `year` to be shown, and must return a React component. See [appearance customization](#appearance-customization) |
| **renderYear** | function | DOM.td( year ) | Customize the way that the years are shown in the year picker. The accepted function has the `selectedDate`, the current date and the default calculated `props` for the cell, the `year` to be shown, and must return a React component. See [appearance customization](#appearance-customization) |
| **strictParsing** | boolean | false | Whether to use moment's [strict parsing](http://momentjs.com/docs/#/parsing/string-format/) when parsing input.
## i18n
Different language and date formats are supported by react-datetime. React uses [moment.js](http://momentjs.com/) to format the dates, and the easiest way of changing the language of the calendar is [changing the moment.js locale](http://momentjs.com/docs/#/i18n/changing-locale/).
tests/datetime-spec.js
@@ -558,5 +558,27 @@
        dt.input().value = '';
        Utils.Simulate.change( dt.input() );
    });
    it( 'strictParsing=true', function( done ){
        var invalidStrDate = strDate + 'x';
        createDatetime({ defaultValue: '', strictParsing: true, onChange: function( updated ){
            assert.equal( updated, invalidStrDate);
            done();
        }});
        dt.input().value = invalidStrDate;
        Utils.Simulate.change( dt.input() );
    });
    it( 'strictParsing=false', function( done ){
        var invalidStrDate = strDate + 'x';
        createDatetime({ defaultValue: '', strictParsing: false, onChange: function( updated ){
            assert.equal( mDate.format('L LT'), updated.format('L LT') );
            done();
        }});
        dt.input().value = invalidStrDate;
        Utils.Simulate.change( dt.input() );
    });
});