marquex
2015-07-24 0d9dc7d77f8e5fb48c1b10ac5508cb400fc076fd
Fixes timepicker not showing when dateFormat=false. Added tests.
1 files deleted
2 files added
5 files modified
316 ■■■■ changed files
DateTime.js 20 ●●●●● patch | view | raw | blame | history
README.md 10 ●●●● patch | view | raw | blame | history
dist/react-datetime.js 2 ●●● patch | view | raw | blame | history
dist/react-datetime.min.js 2 ●●● patch | view | raw | blame | history
package.json 5 ●●●● patch | view | raw | blame | history
test/DateTimePickerHoursSpec.jsx 19 ●●●●● patch | view | raw | blame | history
tests/datetime-spec.js 246 ●●●●● patch | view | raw | blame | history
tests/testdom.js 12 ●●●●● patch | view | raw | blame | history
DateTime.js
@@ -23,8 +23,8 @@
        time: TimeView
    },
    propTypes: {
        value: TYPES.object,
        defaultValue: TYPES.object,
        // value: TYPES.object | TYPES.string,
        // defaultValue: TYPES.object | TYPES.string,
        onBlur: TYPES.func,
        onChange: TYPES.func,
        locale: TYPES.string,
@@ -42,7 +42,6 @@
        var nof = function(){};
        return {
            className: '',
            value: false,
            defaultValue: new Date(),
            viewMode: 'days',
            inputProps: {},
@@ -58,7 +57,7 @@
        var state = this.getStateFromProps( this.props );
        state.open = !this.props.input;
        state.currentView = this.props.viewMode;
        state.currentView = this.props.dateFormat ? this.props.viewMode : 'time';
        return state;
    },
@@ -69,16 +68,16 @@
            selectedDate
        ;
        if( typeof date == 'string')
        if( typeof date == 'string' )
            selectedDate = this.localMoment( date, formats.datetime );
        else
            selectedDate = this.localMoment( date );
        return {
            inputFormat: formats.datetime,
            viewDate: this.localMoment(date).startOf("month"),
            selectedDate: this.localMoment(date),
            inputValue: this.localMoment(date).format( formats.datetime )
            viewDate: selectedDate.clone().startOf("month"),
            selectedDate: selectedDate,
            inputValue: selectedDate.format( formats.datetime )
        };
    },
@@ -97,7 +96,10 @@
            formats.time = locale.longDateFormat('LT');
        }
        formats.datetime = formats.date + ' ' + formats.time;
        formats.datetime = formats.date && formats.time ?
            formats.date + ' ' + formats.time :
            formats.date || formats.time
        ;
        return formats;
    },
README.md
@@ -31,8 +31,8 @@
| Name         | Type    | Default | Description |
| ------------ | ------- | ------- | ----------- |
| **value** | Date | new Date() | Represents the value for the compones, in order to use it as a [controlled component](https://facebook.github.io/react/docs/forms.html#controlled-components). This prop is parsed by moment.js, so it is possible to use a date string or a moment.js date. |
| **defaultValue** | Date | new Date() | Represents the inital value for the component to use it as a [uncontrolled component](https://facebook.github.io/react/docs/forms.html#uncontrolled-components). This prop is parsed by moment.js, so it is possible to use a date string or a moment.js date. |
| **value** | Date | new Date() | Represents the selected date by the component, in order to use it as a [controlled component](https://facebook.github.io/react/docs/forms.html#controlled-components). This prop is parsed by moment.js, so it is possible to use a date string or a moment.js date. |
| **defaultValue** | Date | new Date() | Represents the selected date for the component to use it as a [uncontrolled component](https://facebook.github.io/react/docs/forms.html#uncontrolled-components). This prop is parsed by moment.js, so it is possible to use a date string or a moment.js date. |
| **dateFormat**   | `bool` or `string`  | `true` | Defines the format for the date. It accepts any [moment.js date format](http://momentjs.com/docs/#/displaying/format/). If `true` the date will be displayed using the defaults for the current locale. If `false` the datepicker is disabled and the component can be used as timepicker. |
| **timeFormat**   | `bool` or `string`  | `true` | Defines the format for the time. It accepts any [moment.js time format](http://momentjs.com/docs/#/displaying/format/). If `true` the time will be displayed using the defaults for the current locale. If `false` the timepicker is disabled and the component can be used as datepicker. |
| **input** | boolean | true | Wether to show an input field to edit the date manually. |
@@ -43,9 +43,9 @@
| **className** | string | `""` | Extra class names for the component markup. |
| **inputProps** | object | undefined | Defines additional attributes for the input element of the component. |
| **isValidDate** | function | () => true | Define the dates that can be selected. The function receives `(currentDate, selectedDate)` and should return a `true` or `false` whether the `currentDate` is valid or not. See [selectable dates](#selectable-dates).|
| **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) |
| **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) |
## 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/).
dist/react-datetime.js
@@ -59,7 +59,7 @@
/* 0 */
/***/ function(module, exports, __webpack_require__) {
    eval("'use strict';\r\n\r\n__webpack_require__(1);\r\n\r\nvar assign = __webpack_require__(2),\r\n\tReact = __webpack_require__(3),\r\n\tDaysView = __webpack_require__(4),\r\n\tMonthsView = __webpack_require__(6),\r\n\tYearsView = __webpack_require__(7),\r\n\tTimeView = __webpack_require__(8),\r\n\tmoment = __webpack_require__(5)\r\n;\r\n\r\nvar TYPES = React.PropTypes;\r\nvar Datetime = React.createClass({\r\n\tmixins: [\r\n\t\t__webpack_require__(9)\r\n\t],\r\n\tviewComponents: {\r\n\t\tdays: DaysView,\r\n\t\tmonths: MonthsView,\r\n\t\tyears: YearsView,\r\n\t\ttime: TimeView\r\n\t},\r\n\tpropTypes: {\r\n\t\tvalue: TYPES.object,\r\n\t\tdefaultValue: TYPES.object,\r\n\t\tonBlur: TYPES.func,\r\n\t\tonChange: TYPES.func,\r\n\t\tlocale: TYPES.string,\r\n\t\tinput: TYPES.bool,\r\n\t\t// dateFormat: TYPES.string | TYPES.bool,\r\n\t\t// timeFormat: TYPES.string | TYPES.bool,\r\n\t\tinputProps: TYPES.object,\r\n\t\tviewMode: TYPES.oneOf(['years', 'months', 'days', 'time']),\r\n\t\tisValidDate: TYPES.func,\r\n\t\tminDate: TYPES.object,\r\n\t\tmaxDate: TYPES.object\r\n\t},\r\n\r\n\tgetDefaultProps: function() {\r\n\t\tvar nof = function(){};\r\n\t\treturn {\r\n\t\t\tclassName: '',\r\n\t\t\tvalue: false,\r\n\t\t\tdefaultValue: new Date(),\r\n\t\t\tviewMode: 'days',\r\n\t\t\tinputProps: {},\r\n\t\t\tinput: true,\r\n\t\t\tonBlur: nof,\r\n\t\t\tonChange: nof,\r\n\t\t\ttimeFormat: true,\r\n\t\t\tdateFormat: true\r\n\t\t};\r\n\t},\r\n\r\n\tgetInitialState: function() {\r\n\t\tvar state = this.getStateFromProps( this.props );\r\n\r\n\t\tstate.open = !this.props.input;\r\n\t\tstate.currentView = this.props.viewMode;\r\n\r\n\t\treturn state;\r\n\t},\r\n\r\n\tgetStateFromProps: function( props ){\r\n\t\tvar formats = this.getFormats( props ),\r\n\t\t\tdate = props.value || props.defaultValue,\r\n\t\t\tselectedDate\r\n\t\t;\r\n\r\n\t\tif( typeof date == 'string')\r\n\t\t\tselectedDate = this.localMoment( date, formats.datetime );\r\n\t\telse\r\n\t\t\tselectedDate = this.localMoment( date );\r\n\r\n\t\treturn {\r\n\t\t\tinputFormat: formats.datetime,\r\n\t\t\tviewDate: this.localMoment(date).startOf(\"month\"),\r\n\t\t\tselectedDate: this.localMoment(date),\r\n\t\t\tinputValue: this.localMoment(date).format( formats.datetime )\r\n\t\t};\r\n\t},\r\n\r\n\tgetFormats: function( props ){\r\n\t\tvar formats = {\r\n\t\t\t\tdate: props.dateFormat || '',\r\n\t\t\t\ttime: props.timeFormat || ''\r\n\t\t\t},\r\n\t\t\tlocale = this.localMoment( props.date ).localeData()\r\n\t\t;\r\n\r\n\t\tif( formats.date === true ){\r\n\t\t\tformats.date = locale.longDateFormat('L');\r\n\t\t}\r\n\t\tif( formats.time === true ){\r\n\t\t\tformats.time = locale.longDateFormat('LT');\r\n\t\t}\r\n\r\n\t\tformats.datetime = formats.date + ' ' + formats.time;\r\n\r\n\t\treturn formats;\r\n\t},\r\n\r\n\tcomponentWillReceiveProps: function(nextProps) {\r\n\t\tvar formats = this.getFormats( nextProps ),\r\n\t\t\tupdate = {}\r\n\t\t;\r\n\r\n\t\tif( nextProps.value ){\r\n\t\t\tupdate = this.getStateFromProps( nextProps );\r\n\t\t}\r\n\t\tif ( formats.datetime !== this.getFormats( this.props ).datetime ) {\r\n\t\t\tupdate.inputFormat = formats.datetime;\r\n\t\t}\r\n\r\n\t\tthis.setState( update );\r\n\t},\r\n\r\n\tonInputChange: function( e ) {\r\n\t\tvar value = e.target == null ? e : e.target.value,\r\n\t\t\tlocalMoment = this.localMoment( value, this.state.inputFormat ),\r\n\t\t\tupdate = { inputValue: value }\r\n\t\t;\r\n\r\n\t\tif ( localMoment.isValid() && !this.props.value ) {\r\n\t\t\tupdate.selectedDate = localMoment;\r\n\t\t\tupdate.viewDate = localMoment.clone().startOf(\"month\");\r\n\t\t}\r\n\r\n\t\treturn this.setState( update, function() {\r\n\t\t\tif( localMoment.isValid() )\r\n\t\t\t\treturn this.props.onChange( localMoment );\r\n\t\t});\r\n\t},\r\n\r\n\tshowView: function( view ){\r\n\t\tvar me = this;\r\n\t\treturn function( e ){\r\n\t\t\tme.setState({ currentView: view });\r\n\t\t};\r\n\t},\r\n\r\n\tsetDate: function( type ){\r\n\t\tvar me = this,\r\n\t\t\tnextViews = {\r\n\t\t\t\tmonth: 'days',\r\n\t\t\t\tyear: 'months'\r\n\t\t\t}\r\n\t\t;\r\n\t\treturn function( e ){\r\n\t\t\tme.setState({\r\n\t\t\t\tviewDate: me.state.viewDate.clone()[ type ]( parseInt(e.target.getAttribute('data-value')) ).startOf( type ),\r\n\t\t\t\tcurrentView: nextViews[ type ]\r\n\t\t\t});\r\n\t\t};\r\n\t},\r\n\r\n\taddTime: function( amount, type, toSelected ){\r\n\t\treturn this.updateTime( 'add', amount, type, toSelected );\r\n\t},\r\n\r\n\tsubtractTime: function( amount, type, toSelected ){\r\n\t\treturn this.updateTime( 'subtract', amount, type, toSelected );\r\n\t},\r\n\r\n\tupdateTime: function( op, amount, type, toSelected ){\r\n\t\tvar me = this;\r\n\r\n\t\treturn function(){\r\n\t\t\tvar update = {},\r\n\t\t\t\tdate = toSelected ? 'selectedDate' : 'viewDate'\r\n\t\t\t;\r\n\r\n\t\t\tupdate[ date ] = me.state[ date ].clone()[ op ]( amount, type );\r\n\r\n\t\t\tme.setState( update );\r\n\t\t};\r\n\t},\r\n\r\n\tallowedSetTime: ['hours','minutes','seconds', 'milliseconds'],\r\n\tsetTime: function( type, value ){\r\n\t\tvar index = this.allowedSetTime.indexOf( type ) + 1,\r\n\t\t\tdate = this.state.selectedDate.clone(),\r\n\t\t\tnextType\r\n\t\t;\r\n\r\n\t\t// It is needed to set all the time properties\r\n\t\t// to not to reset the time\r\n\t\tdate[ type ]( value );\r\n\t\tfor (; index < this.allowedSetTime.length; index++) {\r\n\t\t\tnextType = this.allowedSetTime[index];\r\n\t\t\tdate[ nextType ]( date[nextType]() );\r\n\t\t}\r\n\r\n\t\tif( !this.props.value ){\r\n\t\t\tthis.setState({\r\n\t\t\t\tselectedDate: date,\r\n\t\t\t\tinputValue: date.format( this.state.inputFormat )\r\n\t\t\t});\r\n\t\t}\r\n\t\tthis.props.onChange( date );\r\n\t},\r\n\r\n\tupdateSelectedDate: function( e ) {\r\n\t\tvar target = e.target,\r\n\t\t\tmodifier = 0,\r\n\t\t\tcurrentDate = this.state.selectedDate,\r\n\t\t\tdate\r\n\t\t;\r\n\r\n\t\tif(target.className.indexOf(\"new\") != -1)\r\n\t\t\tmodifier = 1;\r\n\t\telse if(target.className.indexOf(\"old\") != -1)\r\n\t\t\tmodifier = -1;\r\n\r\n\t\tdate = this.state.viewDate.clone()\r\n\t\t\t.month( this.state.viewDate.month() + modifier )\r\n\t\t\t.date( parseInt( target.getAttribute('data-value') ) )\r\n\t\t\t.hours( currentDate.hours() )\r\n\t\t\t.minutes( currentDate.minutes() )\r\n\t\t\t.seconds( currentDate.seconds() )\r\n\t\t\t.milliseconds( currentDate.milliseconds() )\r\n\t\t;\r\n\r\n\t\tif( !this.props.value ){\r\n\t\t\tthis.setState({\r\n\t\t\t\tselectedDate: date,\r\n\t\t\t\tviewDate: date.clone().startOf('month'),\r\n\t\t\t\tinputValue: date.format( this.state.inputFormat )\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tthis.props.onChange( date );\r\n\t},\r\n\r\n\topenCalendar: function() {\r\n\t\tthis.setState({ open: true });\r\n\t},\r\n\r\n\thandleClickOutside: function(){\r\n\t\tthis.props.onBlur( this.state.selectedDate );\r\n\t\tif( this.props.input && this.state.open )\r\n\t\t\tthis.setState({ open: false });\r\n\t},\r\n\r\n\tlocalMoment: function( date, format ){\r\n\t\tvar m = moment( date, format );\r\n\t\tif( this.props.locale )\r\n\t\t\tm.locale( this.props.locale );\r\n\t\treturn m;\r\n\t},\r\n\r\n\tcomponentProps: {\r\n\t\tfromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear'],\r\n\t\tfromState: ['viewDate', 'selectedDate' ],\r\n\t\tfromThis: ['setDate', 'setTime', 'showView', 'addTime', 'subtractTime', 'updateSelectedDate', 'localMoment']\r\n\t},\r\n\r\n\tgetComponentProps: function(){\r\n\t\tvar me = this,\r\n\t\t\tformats = this.getFormats( this.props ),\r\n\t\t\tprops = {dateFormat: formats.date, timeFormat: formats.time}\r\n\t\t;\r\n\r\n\t\tthis.componentProps.fromProps.forEach( function( name ){\r\n\t\t\tprops[ name ] = me.props[ name ];\r\n\t\t});\r\n\t\tthis.componentProps.fromState.forEach( function( name ){\r\n\t\t\tprops[ name ] = me.state[ name ];\r\n\t\t});\r\n\t\tthis.componentProps.fromThis.forEach( function( name ){\r\n\t\t\tprops[ name ] = me[ name ];\r\n\t\t});\r\n\r\n\t\treturn props;\r\n\t},\r\n\r\n\trender: function() {\r\n\t\tvar Component = this.viewComponents[ this.state.currentView ],\r\n\t\t\tDOM = React.DOM,\r\n\t\t\tclassName = 'rdt ' + this.props.className,\r\n\t\t\tchildren = []\r\n\t\t;\r\n\r\n\t\tif( this.props.input ){\r\n\t\t\tchildren = [ DOM.input( assign({\r\n\t\t\t\tkey: 'i',\r\n\t\t\t\ttype:'text',\r\n\t\t\t\tclassName: 'form-control',\r\n\t\t\t\tonFocus: this.openCalendar,\r\n\t\t\t\tonChange: this.onInputChange,\r\n\t\t\t\tvalue: this.state.inputValue\r\n\t\t\t}, this.props.inputProps ))];\r\n\t\t}\r\n\t\telse {\r\n\t\t\tclassName += ' rdtStatic';\r\n\t\t}\r\n\r\n\t\tif( this.state.open )\r\n\t\t\tclassName += ' rdtOpen';\r\n\r\n\t\treturn DOM.div({className: className}, children.concat(\r\n\t\t\tDOM.div(\r\n\t\t\t\t{ key: 'dt', className: 'rdtPicker' },\r\n\t\t\t\tReact.createElement( Component, this.getComponentProps())\r\n\t\t\t)\r\n\t\t));\r\n\t}\r\n});\r\n\r\n// Make moment accessible through the Datetime class\r\nDatetime.moment = moment;\r\n\r\nmodule.exports = Datetime;\r\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./Datetime.js\n ** module id = 0\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./Datetime.js?");
    eval("'use strict';\r\n\r\n__webpack_require__(1);\r\n\r\nvar assign = __webpack_require__(2),\r\n\tReact = __webpack_require__(3),\r\n\tDaysView = __webpack_require__(4),\r\n\tMonthsView = __webpack_require__(6),\r\n\tYearsView = __webpack_require__(7),\r\n\tTimeView = __webpack_require__(8),\r\n\tmoment = __webpack_require__(5)\r\n;\r\n\r\nvar TYPES = React.PropTypes;\r\nvar Datetime = React.createClass({\r\n\tmixins: [\r\n\t\t__webpack_require__(9)\r\n\t],\r\n\tviewComponents: {\r\n\t\tdays: DaysView,\r\n\t\tmonths: MonthsView,\r\n\t\tyears: YearsView,\r\n\t\ttime: TimeView\r\n\t},\r\n\tpropTypes: {\r\n\t\t// value: TYPES.object | TYPES.string,\r\n\t\t// defaultValue: TYPES.object | TYPES.string,\r\n\t\tonBlur: TYPES.func,\r\n\t\tonChange: TYPES.func,\r\n\t\tlocale: TYPES.string,\r\n\t\tinput: TYPES.bool,\r\n\t\t// dateFormat: TYPES.string | TYPES.bool,\r\n\t\t// timeFormat: TYPES.string | TYPES.bool,\r\n\t\tinputProps: TYPES.object,\r\n\t\tviewMode: TYPES.oneOf(['years', 'months', 'days', 'time']),\r\n\t\tisValidDate: TYPES.func,\r\n\t\tminDate: TYPES.object,\r\n\t\tmaxDate: TYPES.object\r\n\t},\r\n\r\n\tgetDefaultProps: function() {\r\n\t\tvar nof = function(){};\r\n\t\treturn {\r\n\t\t\tclassName: '',\r\n\t\t\tdefaultValue: new Date(),\r\n\t\t\tviewMode: 'days',\r\n\t\t\tinputProps: {},\r\n\t\t\tinput: true,\r\n\t\t\tonBlur: nof,\r\n\t\t\tonChange: nof,\r\n\t\t\ttimeFormat: true,\r\n\t\t\tdateFormat: true\r\n\t\t};\r\n\t},\r\n\r\n\tgetInitialState: function() {\r\n\t\tvar state = this.getStateFromProps( this.props );\r\n\r\n\t\tstate.open = !this.props.input;\r\n\t\tstate.currentView = this.props.dateFormat ? this.props.viewMode : 'time';\r\n\r\n\t\treturn state;\r\n\t},\r\n\r\n\tgetStateFromProps: function( props ){\r\n\t\tvar formats = this.getFormats( props ),\r\n\t\t\tdate = props.value || props.defaultValue,\r\n\t\t\tselectedDate\r\n\t\t;\r\n\r\n\t\tif( typeof date == 'string' )\r\n\t\t\tselectedDate = this.localMoment( date, formats.datetime );\r\n\t\telse\r\n\t\t\tselectedDate = this.localMoment( date );\r\n\r\n\t\treturn {\r\n\t\t\tinputFormat: formats.datetime,\r\n\t\t\tviewDate: selectedDate.clone().startOf(\"month\"),\r\n\t\t\tselectedDate: selectedDate,\r\n\t\t\tinputValue: selectedDate.format( formats.datetime )\r\n\t\t};\r\n\t},\r\n\r\n\tgetFormats: function( props ){\r\n\t\tvar formats = {\r\n\t\t\t\tdate: props.dateFormat || '',\r\n\t\t\t\ttime: props.timeFormat || ''\r\n\t\t\t},\r\n\t\t\tlocale = this.localMoment( props.date ).localeData()\r\n\t\t;\r\n\r\n\t\tif( formats.date === true ){\r\n\t\t\tformats.date = locale.longDateFormat('L');\r\n\t\t}\r\n\t\tif( formats.time === true ){\r\n\t\t\tformats.time = locale.longDateFormat('LT');\r\n\t\t}\r\n\r\n\t\tformats.datetime = formats.date && formats.time ?\r\n\t\t\tformats.date + ' ' + formats.time :\r\n\t\t\tformats.date || formats.time\r\n\t\t;\r\n\r\n\t\treturn formats;\r\n\t},\r\n\r\n\tcomponentWillReceiveProps: function(nextProps) {\r\n\t\tvar formats = this.getFormats( nextProps ),\r\n\t\t\tupdate = {}\r\n\t\t;\r\n\r\n\t\tif( nextProps.value ){\r\n\t\t\tupdate = this.getStateFromProps( nextProps );\r\n\t\t}\r\n\t\tif ( formats.datetime !== this.getFormats( this.props ).datetime ) {\r\n\t\t\tupdate.inputFormat = formats.datetime;\r\n\t\t}\r\n\r\n\t\tthis.setState( update );\r\n\t},\r\n\r\n\tonInputChange: function( e ) {\r\n\t\tvar value = e.target == null ? e : e.target.value,\r\n\t\t\tlocalMoment = this.localMoment( value, this.state.inputFormat ),\r\n\t\t\tupdate = { inputValue: value }\r\n\t\t;\r\n\r\n\t\tif ( localMoment.isValid() && !this.props.value ) {\r\n\t\t\tupdate.selectedDate = localMoment;\r\n\t\t\tupdate.viewDate = localMoment.clone().startOf(\"month\");\r\n\t\t}\r\n\r\n\t\treturn this.setState( update, function() {\r\n\t\t\tif( localMoment.isValid() )\r\n\t\t\t\treturn this.props.onChange( localMoment );\r\n\t\t});\r\n\t},\r\n\r\n\tshowView: function( view ){\r\n\t\tvar me = this;\r\n\t\treturn function( e ){\r\n\t\t\tme.setState({ currentView: view });\r\n\t\t};\r\n\t},\r\n\r\n\tsetDate: function( type ){\r\n\t\tvar me = this,\r\n\t\t\tnextViews = {\r\n\t\t\t\tmonth: 'days',\r\n\t\t\t\tyear: 'months'\r\n\t\t\t}\r\n\t\t;\r\n\t\treturn function( e ){\r\n\t\t\tme.setState({\r\n\t\t\t\tviewDate: me.state.viewDate.clone()[ type ]( parseInt(e.target.getAttribute('data-value')) ).startOf( type ),\r\n\t\t\t\tcurrentView: nextViews[ type ]\r\n\t\t\t});\r\n\t\t};\r\n\t},\r\n\r\n\taddTime: function( amount, type, toSelected ){\r\n\t\treturn this.updateTime( 'add', amount, type, toSelected );\r\n\t},\r\n\r\n\tsubtractTime: function( amount, type, toSelected ){\r\n\t\treturn this.updateTime( 'subtract', amount, type, toSelected );\r\n\t},\r\n\r\n\tupdateTime: function( op, amount, type, toSelected ){\r\n\t\tvar me = this;\r\n\r\n\t\treturn function(){\r\n\t\t\tvar update = {},\r\n\t\t\t\tdate = toSelected ? 'selectedDate' : 'viewDate'\r\n\t\t\t;\r\n\r\n\t\t\tupdate[ date ] = me.state[ date ].clone()[ op ]( amount, type );\r\n\r\n\t\t\tme.setState( update );\r\n\t\t};\r\n\t},\r\n\r\n\tallowedSetTime: ['hours','minutes','seconds', 'milliseconds'],\r\n\tsetTime: function( type, value ){\r\n\t\tvar index = this.allowedSetTime.indexOf( type ) + 1,\r\n\t\t\tdate = this.state.selectedDate.clone(),\r\n\t\t\tnextType\r\n\t\t;\r\n\r\n\t\t// It is needed to set all the time properties\r\n\t\t// to not to reset the time\r\n\t\tdate[ type ]( value );\r\n\t\tfor (; index < this.allowedSetTime.length; index++) {\r\n\t\t\tnextType = this.allowedSetTime[index];\r\n\t\t\tdate[ nextType ]( date[nextType]() );\r\n\t\t}\r\n\r\n\t\tif( !this.props.value ){\r\n\t\t\tthis.setState({\r\n\t\t\t\tselectedDate: date,\r\n\t\t\t\tinputValue: date.format( this.state.inputFormat )\r\n\t\t\t});\r\n\t\t}\r\n\t\tthis.props.onChange( date );\r\n\t},\r\n\r\n\tupdateSelectedDate: function( e ) {\r\n\t\tvar target = e.target,\r\n\t\t\tmodifier = 0,\r\n\t\t\tcurrentDate = this.state.selectedDate,\r\n\t\t\tdate\r\n\t\t;\r\n\r\n\t\tif(target.className.indexOf(\"new\") != -1)\r\n\t\t\tmodifier = 1;\r\n\t\telse if(target.className.indexOf(\"old\") != -1)\r\n\t\t\tmodifier = -1;\r\n\r\n\t\tdate = this.state.viewDate.clone()\r\n\t\t\t.month( this.state.viewDate.month() + modifier )\r\n\t\t\t.date( parseInt( target.getAttribute('data-value') ) )\r\n\t\t\t.hours( currentDate.hours() )\r\n\t\t\t.minutes( currentDate.minutes() )\r\n\t\t\t.seconds( currentDate.seconds() )\r\n\t\t\t.milliseconds( currentDate.milliseconds() )\r\n\t\t;\r\n\r\n\t\tif( !this.props.value ){\r\n\t\t\tthis.setState({\r\n\t\t\t\tselectedDate: date,\r\n\t\t\t\tviewDate: date.clone().startOf('month'),\r\n\t\t\t\tinputValue: date.format( this.state.inputFormat )\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tthis.props.onChange( date );\r\n\t},\r\n\r\n\topenCalendar: function() {\r\n\t\tthis.setState({ open: true });\r\n\t},\r\n\r\n\thandleClickOutside: function(){\r\n\t\tthis.props.onBlur( this.state.selectedDate );\r\n\t\tif( this.props.input && this.state.open )\r\n\t\t\tthis.setState({ open: false });\r\n\t},\r\n\r\n\tlocalMoment: function( date, format ){\r\n\t\tvar m = moment( date, format );\r\n\t\tif( this.props.locale )\r\n\t\t\tm.locale( this.props.locale );\r\n\t\treturn m;\r\n\t},\r\n\r\n\tcomponentProps: {\r\n\t\tfromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear'],\r\n\t\tfromState: ['viewDate', 'selectedDate' ],\r\n\t\tfromThis: ['setDate', 'setTime', 'showView', 'addTime', 'subtractTime', 'updateSelectedDate', 'localMoment']\r\n\t},\r\n\r\n\tgetComponentProps: function(){\r\n\t\tvar me = this,\r\n\t\t\tformats = this.getFormats( this.props ),\r\n\t\t\tprops = {dateFormat: formats.date, timeFormat: formats.time}\r\n\t\t;\r\n\r\n\t\tthis.componentProps.fromProps.forEach( function( name ){\r\n\t\t\tprops[ name ] = me.props[ name ];\r\n\t\t});\r\n\t\tthis.componentProps.fromState.forEach( function( name ){\r\n\t\t\tprops[ name ] = me.state[ name ];\r\n\t\t});\r\n\t\tthis.componentProps.fromThis.forEach( function( name ){\r\n\t\t\tprops[ name ] = me[ name ];\r\n\t\t});\r\n\r\n\t\treturn props;\r\n\t},\r\n\r\n\trender: function() {\r\n\t\tvar Component = this.viewComponents[ this.state.currentView ],\r\n\t\t\tDOM = React.DOM,\r\n\t\t\tclassName = 'rdt ' + this.props.className,\r\n\t\t\tchildren = []\r\n\t\t;\r\n\r\n\t\tif( this.props.input ){\r\n\t\t\tchildren = [ DOM.input( assign({\r\n\t\t\t\tkey: 'i',\r\n\t\t\t\ttype:'text',\r\n\t\t\t\tclassName: 'form-control',\r\n\t\t\t\tonFocus: this.openCalendar,\r\n\t\t\t\tonChange: this.onInputChange,\r\n\t\t\t\tvalue: this.state.inputValue\r\n\t\t\t}, this.props.inputProps ))];\r\n\t\t}\r\n\t\telse {\r\n\t\t\tclassName += ' rdtStatic';\r\n\t\t}\r\n\r\n\t\tif( this.state.open )\r\n\t\t\tclassName += ' rdtOpen';\r\n\r\n\t\treturn DOM.div({className: className}, children.concat(\r\n\t\t\tDOM.div(\r\n\t\t\t\t{ key: 'dt', className: 'rdtPicker' },\r\n\t\t\t\tReact.createElement( Component, this.getComponentProps())\r\n\t\t\t)\r\n\t\t));\r\n\t}\r\n});\r\n\r\n// Make moment accessible through the Datetime class\r\nDatetime.moment = moment;\r\n\r\nmodule.exports = Datetime;\r\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./Datetime.js\n ** module id = 0\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./Datetime.js?");
/***/ },
/* 1 */
dist/react-datetime.min.js
@@ -3,4 +3,4 @@
https://github.com/arqex/react-datetime
MIT: https://github.com/arqex/react-datetime/raw/master/LICENSE
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require(void 0),require(void 0)):"function"==typeof define&&define.amd?define([,],e):"object"==typeof exports?exports.Datetime=e(require(void 0),require(void 0)):t.Datetime=e(t.React,t.moment)}(this,function(t,e){return function(t){function e(n){if(s[n])return s[n].exports;var r=s[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var s={};return e.m=t,e.c=s,e.p="",e(0)}([function(t,e,s){"use strict";s(1);var n=s(2),r=s(3),i=s(4),a=s(6),o=s(7),c=s(8),u=s(5),l=r.PropTypes,p=r.createClass({mixins:[s(9)],viewComponents:{days:i,months:a,years:o,time:c},propTypes:{value:l.object,defaultValue:l.object,onBlur:l.func,onChange:l.func,locale:l.string,input:l.bool,inputProps:l.object,viewMode:l.oneOf(["years","months","days","time"]),isValidDate:l.func,minDate:l.object,maxDate:l.object},getDefaultProps:function(){var t=function(){};return{className:"",value:!1,defaultValue:new Date,viewMode:"days",inputProps:{},input:!0,onBlur:t,onChange:t,timeFormat:!0,dateFormat:!0}},getInitialState:function(){var t=this.getStateFromProps(this.props);return t.open=!this.props.input,t.currentView=this.props.viewMode,t},getStateFromProps:function(t){var e,s=this.getFormats(t),n=t.value||t.defaultValue;return e="string"==typeof n?this.localMoment(n,s.datetime):this.localMoment(n),{inputFormat:s.datetime,viewDate:this.localMoment(n).startOf("month"),selectedDate:this.localMoment(n),inputValue:this.localMoment(n).format(s.datetime)}},getFormats:function(t){var e={date:t.dateFormat||"",time:t.timeFormat||""},s=this.localMoment(t.date).localeData();return e.date===!0&&(e.date=s.longDateFormat("L")),e.time===!0&&(e.time=s.longDateFormat("LT")),e.datetime=e.date+" "+e.time,e},componentWillReceiveProps:function(t){var e=this.getFormats(t),s={};t.value&&(s=this.getStateFromProps(t)),e.datetime!==this.getFormats(this.props).datetime&&(s.inputFormat=e.datetime),this.setState(s)},onInputChange:function(t){var e=null==t.target?t:t.target.value,s=this.localMoment(e,this.state.inputFormat),n={inputValue:e};return s.isValid()&&!this.props.value&&(n.selectedDate=s,n.viewDate=s.clone().startOf("month")),this.setState(n,function(){return s.isValid()?this.props.onChange(s):void 0})},showView:function(t){var e=this;return function(s){e.setState({currentView:t})}},setDate:function(t){var e=this,s={month:"days",year:"months"};return function(n){e.setState({viewDate:e.state.viewDate.clone()[t](parseInt(n.target.getAttribute("data-value"))).startOf(t),currentView:s[t]})}},addTime:function(t,e,s){return this.updateTime("add",t,e,s)},subtractTime:function(t,e,s){return this.updateTime("subtract",t,e,s)},updateTime:function(t,e,s,n){var r=this;return function(){var i={},a=n?"selectedDate":"viewDate";i[a]=r.state[a].clone()[t](e,s),r.setState(i)}},allowedSetTime:["hours","minutes","seconds","milliseconds"],setTime:function(t,e){var s,n=this.allowedSetTime.indexOf(t)+1,r=this.state.selectedDate.clone();for(r[t](e);n<this.allowedSetTime.length;n++)s=this.allowedSetTime[n],r[s](r[s]());this.props.value||this.setState({selectedDate:r,inputValue:r.format(this.state.inputFormat)}),this.props.onChange(r)},updateSelectedDate:function(t){var e,s=t.target,n=0,r=this.state.selectedDate;-1!=s.className.indexOf("new")?n=1:-1!=s.className.indexOf("old")&&(n=-1),e=this.state.viewDate.clone().month(this.state.viewDate.month()+n).date(parseInt(s.getAttribute("data-value"))).hours(r.hours()).minutes(r.minutes()).seconds(r.seconds()).milliseconds(r.milliseconds()),this.props.value||this.setState({selectedDate:e,viewDate:e.clone().startOf("month"),inputValue:e.format(this.state.inputFormat)}),this.props.onChange(e)},openCalendar:function(){this.setState({open:!0})},handleClickOutside:function(){this.props.onBlur(this.state.selectedDate),this.props.input&&this.state.open&&this.setState({open:!1})},localMoment:function(t,e){var s=u(t,e);return this.props.locale&&s.locale(this.props.locale),s},componentProps:{fromProps:["value","isValidDate","renderDay","renderMonth","renderYear"],fromState:["viewDate","selectedDate"],fromThis:["setDate","setTime","showView","addTime","subtractTime","updateSelectedDate","localMoment"]},getComponentProps:function(){var t=this,e=this.getFormats(this.props),s={dateFormat:e.date,timeFormat:e.time};return this.componentProps.fromProps.forEach(function(e){s[e]=t.props[e]}),this.componentProps.fromState.forEach(function(e){s[e]=t.state[e]}),this.componentProps.fromThis.forEach(function(e){s[e]=t[e]}),s},render:function(){var t=this.viewComponents[this.state.currentView],e=r.DOM,s="rdt "+this.props.className,i=[];return this.props.input?i=[e.input(n({key:"i",type:"text",className:"form-control",onFocus:this.openCalendar,onChange:this.onInputChange,value:this.state.inputValue},this.props.inputProps))]:s+=" rdtStatic",this.state.open&&(s+=" rdtOpen"),e.div({className:s},i.concat(e.div({key:"dt",className:"rdtPicker"},r.createElement(t,this.getComponentProps()))))}});p.moment=u,t.exports=p},function(t,e){"document"in window.self&&("classList"in document.createElement("_")?!function(){"use strict";var t=document.createElement("_");if(t.classList.add("c1","c2"),!t.classList.contains("c2")){var e=function(t){var e=DOMTokenList.prototype[t];DOMTokenList.prototype[t]=function(t){var s,n=arguments.length;for(s=0;n>s;s++)t=arguments[s],e.call(this,t)}};e("add"),e("remove")}if(t.classList.toggle("c3",!1),t.classList.contains("c3")){var s=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(t,e){return 1 in arguments&&!this.contains(t)==!e?e:s.call(this,t)}}t=null}():!function(t){"use strict";if("Element"in t){var e="classList",s="prototype",n=t.Element[s],r=Object,i=String[s].trim||function(){return this.replace(/^\s+|\s+$/g,"")},a=Array[s].indexOf||function(t){for(var e=0,s=this.length;s>e;e++)if(e in this&&this[e]===t)return e;return-1},o=function(t,e){this.name=t,this.code=DOMException[t],this.message=e},c=function(t,e){if(""===e)throw new o("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new o("INVALID_CHARACTER_ERR","String contains an invalid character");return a.call(t,e)},u=function(t){for(var e=i.call(t.getAttribute("class")||""),s=e?e.split(/\s+/):[],n=0,r=s.length;r>n;n++)this.push(s[n]);this._updateClassName=function(){t.setAttribute("class",this.toString())}},l=u[s]=[],p=function(){return new u(this)};if(o[s]=Error[s],l.item=function(t){return this[t]||null},l.contains=function(t){return t+="",-1!==c(this,t)},l.add=function(){var t,e=arguments,s=0,n=e.length,r=!1;do t=e[s]+"",-1===c(this,t)&&(this.push(t),r=!0);while(++s<n);r&&this._updateClassName()},l.remove=function(){var t,e,s=arguments,n=0,r=s.length,i=!1;do for(t=s[n]+"",e=c(this,t);-1!==e;)this.splice(e,1),i=!0,e=c(this,t);while(++n<r);i&&this._updateClassName()},l.toggle=function(t,e){t+="";var s=this.contains(t),n=s?e!==!0&&"remove":e!==!1&&"add";return n&&this[n](t),e===!0||e===!1?e:!s},l.toString=function(){return this.join(" ")},r.defineProperty){var d={get:p,enumerable:!0,configurable:!0};try{r.defineProperty(n,e,d)}catch(h){-2146823252===h.number&&(d.enumerable=!1,r.defineProperty(n,e,d))}}else r[s].__defineGetter__&&n.__defineGetter__(e,p)}}(window.self))},function(t,e){"use strict";function s(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function n(t){var e=Object.getOwnPropertyNames(t);return Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(t))),e.filter(function(e){return r.call(t,e)})}var r=Object.prototype.propertyIsEnumerable;t.exports=Object.assign||function(t,e){for(var r,i,a=s(t),o=1;o<arguments.length;o++){r=arguments[o],i=n(Object(r));for(var c=0;c<i.length;c++)a[i[c]]=r[i[c]]}return a}},function(e,s){e.exports=t},function(t,e,s){var n=s(3),r=s(5),i=n.DOM,a=n.createClass({render:function(){var t,e=this.renderFooter(),s=this.props.viewDate,n=s.localeData();return t=[i.thead({key:"th"},[i.tr({key:"h"},[i.th({key:"p",className:"prev"},i.button({onClick:this.props.subtractTime(1,"months"),type:"button"},"‹")),i.th({key:"s",className:"switch",onClick:this.props.showView("months"),colSpan:5},n.months(s)+" "+s.year()),i.th({key:"n",className:"next"},i.button({onClick:this.props.addTime(1,"months"),type:"button"},"›"))]),i.tr({key:"d"},this.getDaysOfWeek(n).map(function(t){return i.th({key:t,className:"dow"},t)}))]),i.tbody({key:"tb"},this.renderDays())],e&&t.push(e),i.div({className:"rdtDays"},i.table({},t))},getDaysOfWeek:function(t){var e=t._weekdaysMin,s=t.firstDayOfWeek(),n=[],r=0;return e.forEach(function(t){n[(7+r++-s)%7]=t}),n},renderDays:function(){var t,e,s,n,a=this.props.viewDate,o=this.props.selectedDate.clone(),c=a.clone().subtract(1,"months"),u=a.year(),l=a.month(),p={y:o.year(),M:o.month(),d:o.date()},d=(this.props.minDate,this.props.maxDate,[]),h=[],m=this.props.renderDay||this.renderDay,f=this.props.isValidDate||this.isValidDate;c.date(c.daysInMonth()).startOf("week");for(var v=c.clone().add(42,"d");c.isBefore(v);)t="day",n=c.clone(),c.year()<u||c.month()<l?t+=" old":(c.year()>u||c.month()>l)&&(t+=" new"),c.isSame(p)&&(t+=" active"),c.isSame(r(),"day")&&(t+=" today"),e=!f(n,o),e&&(t+=" disabled"),s={key:c.format("M_D"),"data-value":c.date(),className:t},e||(s.onClick=this.props.updateSelectedDate),h.push(m(s,n,o)),7==h.length&&(d.push(i.tr({key:c.format("M_D")},h)),h=[]),c.add(1,"d");return d},renderDay:function(t,e,s){return i.td(t,e.date())},renderFooter:function(){return this.props.timeFormat?i.tfoot({key:"tf"},i.tr({},i.td({onClick:this.props.showView("time"),colSpan:7,className:"timeToggle"},this.props.selectedDate.format(this.props.timeFormat)))):""},isValidDate:function(){return 1}});t.exports=a},function(t,s){t.exports=e},function(t,e,s){"use strict";var n=s(3),r=(s(5),n.DOM),i=n.createClass({render:function(){return r.div({className:"rdtMonths"},[r.table({key:"a"},r.thead({},r.tr({},[r.th({key:"prev",className:"prev"},r.button({onClick:this.props.subtractTime(1,"years"),type:"button"},"‹")),r.th({key:"year",className:"switch",onClick:this.props.showView("years"),colSpan:2},this.props.viewDate.year()),r.th({key:"next",className:"next"},r.button({onClick:this.props.addTime(1,"years"),type:"button"},"›"))]))),r.table({key:"months"},r.tbody({key:"b"},this.renderMonths()))])},renderMonths:function(){for(var t,e,s=this.props.selectedDate,n=s.month(),i=this.props.viewDate.year(),a=[],o=0,c=[],u=this.props.renderMonth||this.renderMonth;12>o;)t="month",o===n&&i===s.year()&&(t+=" active"),e={key:o,"data-value":o,className:t,onClick:this.props.setDate("month")},c.push(u(e,o,i,s.clone())),4==c.length&&(a.push(r.tr({key:n+"_"+a.length},c)),c=[]),o++;return a},renderMonth:function(t,e,s,n){return r.td(t,n.localeData()._monthsShort[e])}});t.exports=i},function(t,e,s){"use strict";var n=s(3),r=n.DOM,i=n.createClass({render:function(){var t=10*parseInt(this.props.viewDate.year()/10,10);return r.div({className:"rdtYears"},[r.table({key:"a"},r.thead({},r.tr({},[r.th({key:"prev",className:"prev"},r.button({onClick:this.props.subtractTime(10,"years"),type:"button"},"‹")),r.th({key:"year",className:"switch",onClick:this.props.showView("years"),colSpan:2},t+"-"+(t+9)),r.th({key:"next",className:"next"},r.button({onClick:this.props.addTime(10,"years"),type:"button"},"›"))]))),r.table({key:"years"},r.tbody({},this.renderYears(t)))])},renderYears:function(t){var e,s,n=[],i=-1,a=[],o=this.props.renderYear||this.renderYear;for(t--;11>i;)e="year",-1===i|10===i&&(e+=" old"),this.props.selectedDate.year()===t&&(e+=" active"),s={key:t,"data-value":t,className:e,onClick:this.props.setDate("year")},n.push(o(s,t,this.props.selectedDate.clone())),4==n.length&&(a.push(r.tr({key:i},n)),n=[]),t++,i++;return a},renderYear:function(t,e,s){return r.td(t,e)}});t.exports=i},function(t,e,s){"use strict";var n=s(3),r=n.DOM,i=n.createClass({getInitialState:function(){return this.calculateState(this.props)},calculateState:function(t){var e=t.selectedDate,s=t.timeFormat,n=[];return(-1!=s.indexOf("H")||-1!=s.indexOf("h"))&&(n.push("hours"),-1!=s.indexOf("m")&&(n.push("minutes"),-1!=s.indexOf("s")&&n.push("seconds"))),{hours:e.format("H"),minutes:e.format("mm"),seconds:e.format("ss"),milliseconds:e.format("SSS"),counters:n}},renderCounter:function(t){return r.div({key:t,className:"rdtCounter"},[r.button({key:"up",className:"btn",onMouseDown:this.onStartClicking("increase",t),type:"button"},"â–²"),r.div({key:"c",className:"rdtCount"},this.state[t]),r.button({key:"do",className:"btn",onMouseDown:this.onStartClicking("decrease",t),type:"button"},"â–¼")])},render:function(){var t=this,e=[];return this.state.counters.forEach(function(s){e.length&&e.push(r.div({key:"sep"+e.length,className:"rdtCounterSeparator"},":")),e.push(t.renderCounter(s))}),3==this.state.counters.length&&-1!=this.props.timeFormat.indexOf("S")&&(e.push(r.div({className:"rdtCounterSeparator",key:"sep5"},":")),e.push(r.div({className:"rdtCounter rdtMilli",key:"m"},r.input({value:this.state.milliseconds,type:"text",onChange:this.updateMilli})))),r.div({className:"rdtTime"},r.table({},[this.renderHeader(),r.tbody({key:"b"},r.tr({},r.td({},r.div({className:"rdtCounters"},e))))]))},componentWillReceiveProps:function(t,e){this.setState(this.calculateState(t))},updateMilli:function(t){var e=parseInt(t.target.value);e==t.target.value&&e>=0&&1e3>e&&(this.props.setTime("milliseconds",e),this.setState({milliseconds:e}))},renderHeader:function(){return this.props.dateFormat?r.thead({key:"h"},r.tr({},r.th({colSpan:4,onClick:this.props.showView("days")},this.props.selectedDate.format(this.props.dateFormat)))):""},onStartClicking:function(t,e){{var s=this;this.state[e]}return function(){var n={};n[e]=s[t](e),s.setState(n),s.timer=setTimeout(function(){s.increaseTimer=setInterval(function(){n[e]=s[t](e),s.setState(n)},70)},500),s.mouseUpListener=function(){clearTimeout(s.timer),clearInterval(s.increaseTimer),s.props.setTime(e,s.state[e]),document.body.removeEventListener("mouseup",s.mouseUpListener)},document.body.addEventListener("mouseup",s.mouseUpListener)}},maxValues:{hours:23,minutes:59,seconds:59,milliseconds:999},padValues:{hours:1,minutes:2,seconds:2,milliseconds:3},increase:function(t){var e=parseInt(this.state[t])+1;return e>this.maxValues[t]&&(e=0),this.pad(t,e)},decrease:function(t){var e=parseInt(this.state[t])-1;return 0>e&&(e=this.maxValues[t]),this.pad(t,e)},pad:function(t,e){for(var s=e+"";s.length<this.padValues[t];)s="0"+s;return s}});t.exports=i},function(t,e,s){var n,r,i;!function(s,a){r=[],n=a,i="function"==typeof n?n.apply(e,r):n,!(void 0!==i&&(t.exports=i))}(this,function(){"use strict";var t=[],e=[],s="ignore-react-onclickoutside";return{componentDidMount:function(){if(!this.handleClickOutside)throw new Error("Component lacks a handleClickOutside(event) function for processing outside click events.");var n=this.__outsideClickHandler=function(t,e){return function(n){for(var r=n.target,i=!1;r.parentNode;){if(i=r===t||r.classList.contains(s))return;r=r.parentNode}e(n)}}(this.getDOMNode(),this.handleClickOutside),r=t.length;t.push(this),e[r]=n,this.props.disableOnClickOutside||this.enableOnClickOutside()},componentWillUnmount:function(){this.disableOnClickOutside(),this.__outsideClickHandler=!1;var s=t.indexOf(this);s>-1&&e[s]&&(e.splice(s,1),t.splice(s,1))},enableOnClickOutside:function(){var t=this.__outsideClickHandler;document.addEventListener("mousedown",t),document.addEventListener("touchstart",t)},disableOnClickOutside:function(t){var t=this.__outsideClickHandler;document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t)}}})}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require(void 0),require(void 0)):"function"==typeof define&&define.amd?define([,],e):"object"==typeof exports?exports.Datetime=e(require(void 0),require(void 0)):t.Datetime=e(t.React,t.moment)}(this,function(t,e){return function(t){function e(n){if(s[n])return s[n].exports;var r=s[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var s={};return e.m=t,e.c=s,e.p="",e(0)}([function(t,e,s){"use strict";s(1);var n=s(2),r=s(3),i=s(4),a=s(6),o=s(7),c=s(8),u=s(5),l=r.PropTypes,p=r.createClass({mixins:[s(9)],viewComponents:{days:i,months:a,years:o,time:c},propTypes:{onBlur:l.func,onChange:l.func,locale:l.string,input:l.bool,inputProps:l.object,viewMode:l.oneOf(["years","months","days","time"]),isValidDate:l.func,minDate:l.object,maxDate:l.object},getDefaultProps:function(){var t=function(){};return{className:"",defaultValue:new Date,viewMode:"days",inputProps:{},input:!0,onBlur:t,onChange:t,timeFormat:!0,dateFormat:!0}},getInitialState:function(){var t=this.getStateFromProps(this.props);return t.open=!this.props.input,t.currentView=this.props.dateFormat?this.props.viewMode:"time",t},getStateFromProps:function(t){var e,s=this.getFormats(t),n=t.value||t.defaultValue;return e="string"==typeof n?this.localMoment(n,s.datetime):this.localMoment(n),{inputFormat:s.datetime,viewDate:e.clone().startOf("month"),selectedDate:e,inputValue:e.format(s.datetime)}},getFormats:function(t){var e={date:t.dateFormat||"",time:t.timeFormat||""},s=this.localMoment(t.date).localeData();return e.date===!0&&(e.date=s.longDateFormat("L")),e.time===!0&&(e.time=s.longDateFormat("LT")),e.datetime=e.date&&e.time?e.date+" "+e.time:e.date||e.time,e},componentWillReceiveProps:function(t){var e=this.getFormats(t),s={};t.value&&(s=this.getStateFromProps(t)),e.datetime!==this.getFormats(this.props).datetime&&(s.inputFormat=e.datetime),this.setState(s)},onInputChange:function(t){var e=null==t.target?t:t.target.value,s=this.localMoment(e,this.state.inputFormat),n={inputValue:e};return s.isValid()&&!this.props.value&&(n.selectedDate=s,n.viewDate=s.clone().startOf("month")),this.setState(n,function(){return s.isValid()?this.props.onChange(s):void 0})},showView:function(t){var e=this;return function(s){e.setState({currentView:t})}},setDate:function(t){var e=this,s={month:"days",year:"months"};return function(n){e.setState({viewDate:e.state.viewDate.clone()[t](parseInt(n.target.getAttribute("data-value"))).startOf(t),currentView:s[t]})}},addTime:function(t,e,s){return this.updateTime("add",t,e,s)},subtractTime:function(t,e,s){return this.updateTime("subtract",t,e,s)},updateTime:function(t,e,s,n){var r=this;return function(){var i={},a=n?"selectedDate":"viewDate";i[a]=r.state[a].clone()[t](e,s),r.setState(i)}},allowedSetTime:["hours","minutes","seconds","milliseconds"],setTime:function(t,e){var s,n=this.allowedSetTime.indexOf(t)+1,r=this.state.selectedDate.clone();for(r[t](e);n<this.allowedSetTime.length;n++)s=this.allowedSetTime[n],r[s](r[s]());this.props.value||this.setState({selectedDate:r,inputValue:r.format(this.state.inputFormat)}),this.props.onChange(r)},updateSelectedDate:function(t){var e,s=t.target,n=0,r=this.state.selectedDate;-1!=s.className.indexOf("new")?n=1:-1!=s.className.indexOf("old")&&(n=-1),e=this.state.viewDate.clone().month(this.state.viewDate.month()+n).date(parseInt(s.getAttribute("data-value"))).hours(r.hours()).minutes(r.minutes()).seconds(r.seconds()).milliseconds(r.milliseconds()),this.props.value||this.setState({selectedDate:e,viewDate:e.clone().startOf("month"),inputValue:e.format(this.state.inputFormat)}),this.props.onChange(e)},openCalendar:function(){this.setState({open:!0})},handleClickOutside:function(){this.props.onBlur(this.state.selectedDate),this.props.input&&this.state.open&&this.setState({open:!1})},localMoment:function(t,e){var s=u(t,e);return this.props.locale&&s.locale(this.props.locale),s},componentProps:{fromProps:["value","isValidDate","renderDay","renderMonth","renderYear"],fromState:["viewDate","selectedDate"],fromThis:["setDate","setTime","showView","addTime","subtractTime","updateSelectedDate","localMoment"]},getComponentProps:function(){var t=this,e=this.getFormats(this.props),s={dateFormat:e.date,timeFormat:e.time};return this.componentProps.fromProps.forEach(function(e){s[e]=t.props[e]}),this.componentProps.fromState.forEach(function(e){s[e]=t.state[e]}),this.componentProps.fromThis.forEach(function(e){s[e]=t[e]}),s},render:function(){var t=this.viewComponents[this.state.currentView],e=r.DOM,s="rdt "+this.props.className,i=[];return this.props.input?i=[e.input(n({key:"i",type:"text",className:"form-control",onFocus:this.openCalendar,onChange:this.onInputChange,value:this.state.inputValue},this.props.inputProps))]:s+=" rdtStatic",this.state.open&&(s+=" rdtOpen"),e.div({className:s},i.concat(e.div({key:"dt",className:"rdtPicker"},r.createElement(t,this.getComponentProps()))))}});p.moment=u,t.exports=p},function(t,e){"document"in window.self&&("classList"in document.createElement("_")?!function(){"use strict";var t=document.createElement("_");if(t.classList.add("c1","c2"),!t.classList.contains("c2")){var e=function(t){var e=DOMTokenList.prototype[t];DOMTokenList.prototype[t]=function(t){var s,n=arguments.length;for(s=0;n>s;s++)t=arguments[s],e.call(this,t)}};e("add"),e("remove")}if(t.classList.toggle("c3",!1),t.classList.contains("c3")){var s=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(t,e){return 1 in arguments&&!this.contains(t)==!e?e:s.call(this,t)}}t=null}():!function(t){"use strict";if("Element"in t){var e="classList",s="prototype",n=t.Element[s],r=Object,i=String[s].trim||function(){return this.replace(/^\s+|\s+$/g,"")},a=Array[s].indexOf||function(t){for(var e=0,s=this.length;s>e;e++)if(e in this&&this[e]===t)return e;return-1},o=function(t,e){this.name=t,this.code=DOMException[t],this.message=e},c=function(t,e){if(""===e)throw new o("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new o("INVALID_CHARACTER_ERR","String contains an invalid character");return a.call(t,e)},u=function(t){for(var e=i.call(t.getAttribute("class")||""),s=e?e.split(/\s+/):[],n=0,r=s.length;r>n;n++)this.push(s[n]);this._updateClassName=function(){t.setAttribute("class",this.toString())}},l=u[s]=[],p=function(){return new u(this)};if(o[s]=Error[s],l.item=function(t){return this[t]||null},l.contains=function(t){return t+="",-1!==c(this,t)},l.add=function(){var t,e=arguments,s=0,n=e.length,r=!1;do t=e[s]+"",-1===c(this,t)&&(this.push(t),r=!0);while(++s<n);r&&this._updateClassName()},l.remove=function(){var t,e,s=arguments,n=0,r=s.length,i=!1;do for(t=s[n]+"",e=c(this,t);-1!==e;)this.splice(e,1),i=!0,e=c(this,t);while(++n<r);i&&this._updateClassName()},l.toggle=function(t,e){t+="";var s=this.contains(t),n=s?e!==!0&&"remove":e!==!1&&"add";return n&&this[n](t),e===!0||e===!1?e:!s},l.toString=function(){return this.join(" ")},r.defineProperty){var d={get:p,enumerable:!0,configurable:!0};try{r.defineProperty(n,e,d)}catch(h){-2146823252===h.number&&(d.enumerable=!1,r.defineProperty(n,e,d))}}else r[s].__defineGetter__&&n.__defineGetter__(e,p)}}(window.self))},function(t,e){"use strict";function s(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function n(t){var e=Object.getOwnPropertyNames(t);return Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(t))),e.filter(function(e){return r.call(t,e)})}var r=Object.prototype.propertyIsEnumerable;t.exports=Object.assign||function(t,e){for(var r,i,a=s(t),o=1;o<arguments.length;o++){r=arguments[o],i=n(Object(r));for(var c=0;c<i.length;c++)a[i[c]]=r[i[c]]}return a}},function(e,s){e.exports=t},function(t,e,s){var n=s(3),r=s(5),i=n.DOM,a=n.createClass({render:function(){var t,e=this.renderFooter(),s=this.props.viewDate,n=s.localeData();return t=[i.thead({key:"th"},[i.tr({key:"h"},[i.th({key:"p",className:"prev"},i.button({onClick:this.props.subtractTime(1,"months"),type:"button"},"‹")),i.th({key:"s",className:"switch",onClick:this.props.showView("months"),colSpan:5},n.months(s)+" "+s.year()),i.th({key:"n",className:"next"},i.button({onClick:this.props.addTime(1,"months"),type:"button"},"›"))]),i.tr({key:"d"},this.getDaysOfWeek(n).map(function(t){return i.th({key:t,className:"dow"},t)}))]),i.tbody({key:"tb"},this.renderDays())],e&&t.push(e),i.div({className:"rdtDays"},i.table({},t))},getDaysOfWeek:function(t){var e=t._weekdaysMin,s=t.firstDayOfWeek(),n=[],r=0;return e.forEach(function(t){n[(7+r++-s)%7]=t}),n},renderDays:function(){var t,e,s,n,a=this.props.viewDate,o=this.props.selectedDate.clone(),c=a.clone().subtract(1,"months"),u=a.year(),l=a.month(),p={y:o.year(),M:o.month(),d:o.date()},d=(this.props.minDate,this.props.maxDate,[]),h=[],m=this.props.renderDay||this.renderDay,f=this.props.isValidDate||this.isValidDate;c.date(c.daysInMonth()).startOf("week");for(var v=c.clone().add(42,"d");c.isBefore(v);)t="day",n=c.clone(),c.year()<u||c.month()<l?t+=" old":(c.year()>u||c.month()>l)&&(t+=" new"),c.isSame(p)&&(t+=" active"),c.isSame(r(),"day")&&(t+=" today"),e=!f(n,o),e&&(t+=" disabled"),s={key:c.format("M_D"),"data-value":c.date(),className:t},e||(s.onClick=this.props.updateSelectedDate),h.push(m(s,n,o)),7==h.length&&(d.push(i.tr({key:c.format("M_D")},h)),h=[]),c.add(1,"d");return d},renderDay:function(t,e,s){return i.td(t,e.date())},renderFooter:function(){return this.props.timeFormat?i.tfoot({key:"tf"},i.tr({},i.td({onClick:this.props.showView("time"),colSpan:7,className:"timeToggle"},this.props.selectedDate.format(this.props.timeFormat)))):""},isValidDate:function(){return 1}});t.exports=a},function(t,s){t.exports=e},function(t,e,s){"use strict";var n=s(3),r=(s(5),n.DOM),i=n.createClass({render:function(){return r.div({className:"rdtMonths"},[r.table({key:"a"},r.thead({},r.tr({},[r.th({key:"prev",className:"prev"},r.button({onClick:this.props.subtractTime(1,"years"),type:"button"},"‹")),r.th({key:"year",className:"switch",onClick:this.props.showView("years"),colSpan:2},this.props.viewDate.year()),r.th({key:"next",className:"next"},r.button({onClick:this.props.addTime(1,"years"),type:"button"},"›"))]))),r.table({key:"months"},r.tbody({key:"b"},this.renderMonths()))])},renderMonths:function(){for(var t,e,s=this.props.selectedDate,n=s.month(),i=this.props.viewDate.year(),a=[],o=0,c=[],u=this.props.renderMonth||this.renderMonth;12>o;)t="month",o===n&&i===s.year()&&(t+=" active"),e={key:o,"data-value":o,className:t,onClick:this.props.setDate("month")},c.push(u(e,o,i,s.clone())),4==c.length&&(a.push(r.tr({key:n+"_"+a.length},c)),c=[]),o++;return a},renderMonth:function(t,e,s,n){return r.td(t,n.localeData()._monthsShort[e])}});t.exports=i},function(t,e,s){"use strict";var n=s(3),r=n.DOM,i=n.createClass({render:function(){var t=10*parseInt(this.props.viewDate.year()/10,10);return r.div({className:"rdtYears"},[r.table({key:"a"},r.thead({},r.tr({},[r.th({key:"prev",className:"prev"},r.button({onClick:this.props.subtractTime(10,"years"),type:"button"},"‹")),r.th({key:"year",className:"switch",onClick:this.props.showView("years"),colSpan:2},t+"-"+(t+9)),r.th({key:"next",className:"next"},r.button({onClick:this.props.addTime(10,"years"),type:"button"},"›"))]))),r.table({key:"years"},r.tbody({},this.renderYears(t)))])},renderYears:function(t){var e,s,n=[],i=-1,a=[],o=this.props.renderYear||this.renderYear;for(t--;11>i;)e="year",-1===i|10===i&&(e+=" old"),this.props.selectedDate.year()===t&&(e+=" active"),s={key:t,"data-value":t,className:e,onClick:this.props.setDate("year")},n.push(o(s,t,this.props.selectedDate.clone())),4==n.length&&(a.push(r.tr({key:i},n)),n=[]),t++,i++;return a},renderYear:function(t,e,s){return r.td(t,e)}});t.exports=i},function(t,e,s){"use strict";var n=s(3),r=n.DOM,i=n.createClass({getInitialState:function(){return this.calculateState(this.props)},calculateState:function(t){var e=t.selectedDate,s=t.timeFormat,n=[];return(-1!=s.indexOf("H")||-1!=s.indexOf("h"))&&(n.push("hours"),-1!=s.indexOf("m")&&(n.push("minutes"),-1!=s.indexOf("s")&&n.push("seconds"))),{hours:e.format("H"),minutes:e.format("mm"),seconds:e.format("ss"),milliseconds:e.format("SSS"),counters:n}},renderCounter:function(t){return r.div({key:t,className:"rdtCounter"},[r.button({key:"up",className:"btn",onMouseDown:this.onStartClicking("increase",t),type:"button"},"â–²"),r.div({key:"c",className:"rdtCount"},this.state[t]),r.button({key:"do",className:"btn",onMouseDown:this.onStartClicking("decrease",t),type:"button"},"â–¼")])},render:function(){var t=this,e=[];return this.state.counters.forEach(function(s){e.length&&e.push(r.div({key:"sep"+e.length,className:"rdtCounterSeparator"},":")),e.push(t.renderCounter(s))}),3==this.state.counters.length&&-1!=this.props.timeFormat.indexOf("S")&&(e.push(r.div({className:"rdtCounterSeparator",key:"sep5"},":")),e.push(r.div({className:"rdtCounter rdtMilli",key:"m"},r.input({value:this.state.milliseconds,type:"text",onChange:this.updateMilli})))),r.div({className:"rdtTime"},r.table({},[this.renderHeader(),r.tbody({key:"b"},r.tr({},r.td({},r.div({className:"rdtCounters"},e))))]))},componentWillReceiveProps:function(t,e){this.setState(this.calculateState(t))},updateMilli:function(t){var e=parseInt(t.target.value);e==t.target.value&&e>=0&&1e3>e&&(this.props.setTime("milliseconds",e),this.setState({milliseconds:e}))},renderHeader:function(){return this.props.dateFormat?r.thead({key:"h"},r.tr({},r.th({colSpan:4,onClick:this.props.showView("days")},this.props.selectedDate.format(this.props.dateFormat)))):""},onStartClicking:function(t,e){{var s=this;this.state[e]}return function(){var n={};n[e]=s[t](e),s.setState(n),s.timer=setTimeout(function(){s.increaseTimer=setInterval(function(){n[e]=s[t](e),s.setState(n)},70)},500),s.mouseUpListener=function(){clearTimeout(s.timer),clearInterval(s.increaseTimer),s.props.setTime(e,s.state[e]),document.body.removeEventListener("mouseup",s.mouseUpListener)},document.body.addEventListener("mouseup",s.mouseUpListener)}},maxValues:{hours:23,minutes:59,seconds:59,milliseconds:999},padValues:{hours:1,minutes:2,seconds:2,milliseconds:3},increase:function(t){var e=parseInt(this.state[t])+1;return e>this.maxValues[t]&&(e=0),this.pad(t,e)},decrease:function(t){var e=parseInt(this.state[t])-1;return 0>e&&(e=this.maxValues[t]),this.pad(t,e)},pad:function(t,e){for(var s=e+"";s.length<this.padValues[t];)s="0"+s;return s}});t.exports=i},function(t,e,s){var n,r,i;!function(s,a){r=[],n=a,i="function"==typeof n?n.apply(e,r):n,!(void 0!==i&&(t.exports=i))}(this,function(){"use strict";var t=[],e=[],s="ignore-react-onclickoutside";return{componentDidMount:function(){if(!this.handleClickOutside)throw new Error("Component lacks a handleClickOutside(event) function for processing outside click events.");var n=this.__outsideClickHandler=function(t,e){return function(n){for(var r=n.target,i=!1;r.parentNode;){if(i=r===t||r.classList.contains(s))return;r=r.parentNode}e(n)}}(this.getDOMNode(),this.handleClickOutside),r=t.length;t.push(this),e[r]=n,this.props.disableOnClickOutside||this.enableOnClickOutside()},componentWillUnmount:function(){this.disableOnClickOutside(),this.__outsideClickHandler=!1;var s=t.indexOf(this);s>-1&&e[s]&&(e.splice(s,1),t.splice(s,1))},enableOnClickOutside:function(){var t=this.__outsideClickHandler;document.addEventListener("mousedown",t),document.addEventListener("touchstart",t)},disableOnClickOutside:function(t){var t=this.__outsideClickHandler;document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t)}}})}])});
package.json
@@ -9,7 +9,8 @@
  },
  "main": "./DateTime.js",
  "scripts": {
    "build": "./node_modules/.bin/gulp.cmd"
    "build": "./node_modules/.bin/gulp.cmd",
    "test": "node node_modules/mocha/bin/mocha tests"
  },
  "keywords": [
    "react",
@@ -31,6 +32,8 @@
    "gulp-insert": "^0.4.0",
    "gulp-uglify": "^1.2.0",
    "gulp-webpack": "^1.5.0",
    "jsdom": "^3.1.2",
    "mocha": "^2.2.5",
    "react": ">=0.12",
    "react-tools": "^0.12.2",
    "webpack": "^1.5.1",
test/DateTimePickerHoursSpec.jsx
File was deleted
tests/datetime-spec.js
New file
@@ -0,0 +1,246 @@
// Create the dom before requiring react
var DOM = require( './testdom');
DOM();
var React = require('react'),
    ReactAddons = require('react/addons'),
    Utils = React.addons.TestUtils,
    Datetime = require('../Datetime'),
    assert = require('assert'),
    moment = require('moment')
;
var createDatetime = function( props ){
    document.body.innerHTML = '';
    props.onUpdated = function(){};
    React.render(
        React.createElement( Datetime, props ),
        document.body
    );
    return document.body.children[0];
};
var date = new Date( 2000, 0, 15 ),
    mDate = moment( date ),
    strDate = mDate.format('L') + ' ' + mDate.format('LT')
;
console.log( date );
describe( 'Datetime', function(){
    it( 'Create Datetime', function(){
        var component = createDatetime({});
        assert( component );
        assert.equal( component.children.length, 2 );
        assert.equal( component.children[0].tagName , 'INPUT' );
        assert.equal( component.children[1].tagName , 'DIV' );
    });
    it( 'input=false', function(){
        var component = createDatetime({ input: false });
        assert( component );
        assert.equal( component.children.length, 1 );
        assert.equal( component.children[0].tagName , 'DIV' );
    });
    it( 'Date value', function(){
        var component = createDatetime({ value: date }),
            input = component.children[0]
        ;
        assert.equal( input.value, strDate );
    });
    it( 'Moment value', function(){
        var component = createDatetime({ value: mDate }),
            input = component.children[0]
        ;
        assert.equal( input.value, strDate );
    });
    it( 'String value', function(){
        var component = createDatetime({ value: strDate }),
            input = component.children[0]
        ;
        assert.equal( input.value, strDate );
    });
    it( 'Date defaultValue', function(){
        var component = createDatetime({ defaultValue: date }),
            input = component.children[0]
        ;
        assert.equal( input.value, strDate );
    });
    it( 'Moment defaultValue', function(){
        var component = createDatetime({ defaultValue: mDate }),
            input = component.children[0]
        ;
        assert.equal( input.value, strDate );
    });
    it( 'String defaultValue', function(){
        var component = createDatetime({ defaultValue: strDate }),
            input = component.children[0]
        ;
        assert.equal( input.value, strDate );
    });
    it( 'dateFormat', function(){
        var component = createDatetime({ value: date, dateFormat: 'M&D' }),
            input = component.children[0]
        ;
        assert.equal( input.value, mDate.format('M&D LT') );
    });
    it( 'dateFormat=false', function(){
        var component = createDatetime({ value: date, dateFormat: false }),
            input = component.children[0],
            view = component.children[1].children[0]
        ;
        assert.equal( input.value, mDate.format('LT') );
        // The view must be the timepicker
        assert.equal( view.className, 'rdtTime' );
        // There must not be a date toggle
        assert.equal( view.querySelectorAll('thead').length, 0);
    });
    it( 'timeFormat', function(){
        var format = 'HH:mm:ss:SSS',
            component = createDatetime({ value: date, timeFormat: format }),
            input = component.children[0]
        ;
        assert.equal( input.value, mDate.format('L ' + format) );
    });
    it( 'timeFormat=false', function(){
        var component = createDatetime({ value: date, timeFormat: false }),
            input = component.children[0],
            view = component.children[1].children[0]
        ;
        assert.equal( input.value, mDate.format('L') );
        // The view must be the daypicker
        assert.equal( view.className, 'rdtDays' );
        // There must not be a time toggle
        assert.equal( view.querySelectorAll('.timeToggle').length, 0);
    });
    it( 'viewMode=years', function(){
        var component = createDatetime({ viewMode: 'years' }),
            view = component.children[1].children[0]
        ;
        assert.equal( view.className, 'rdtYears' );
    });
    it( 'viewMode=months', function(){
        var component = createDatetime({ viewMode: 'months' }),
            view = component.children[1].children[0]
        ;
        assert.equal( view.className, 'rdtMonths' );
    });
    it( 'viewMode=time', function(){
        var component = createDatetime({ viewMode: 'time' }),
            view = component.children[1].children[0]
        ;
        assert.equal( view.className, 'rdtTime' );
    });
    it( 'className', function(){
        var component = createDatetime({ className: 'custom' });
        assert.notEqual( component.className.indexOf('custom'), -1 );
    });
    it( 'inputProps', function(){
        var component = createDatetime({ inputProps: { className: 'myInput', type: 'email' } }),
            input = component.children[0]
        ;
        assert.equal( input.className, 'myInput' );
        assert.equal( input.type, 'email' );
    });
    it( 'renderDay', function(){
        var props, currentDate, selectedDate,
            component = createDatetime({ value: mDate, renderDay: function( p, current, selected ){
                props = p;
                currentDate = current;
                selectedDate = selected;
                return React.DOM.td( props, 'day' );
            }}),
            view = component.children[1].children[0]
        ;
        // Last day should be 6th of february
        assert.equal( currentDate.day(), 6 );
        assert.equal( currentDate.month(), 1 );
        // The date must be the same
        assert.equal( selectedDate.isSame( mDate ), true );
        // There should be a onClick function in the props
        assert.equal( typeof props.onClick, 'function' );
        // The cell text should be 'day'
        assert.equal( view.querySelector('.day').innerHTML, 'day' );
    });
    it( 'renderMonth', function(){
        var props, month, year, selectedDate,
            component = createDatetime({ value: mDate, viewMode: 'months', renderMonth: function( p, m, y, selected ){
                props = p;
                month = m;
                year = y;
                selectedDate = selected;
                return React.DOM.td( props, 'month' );
            }}),
            view = component.children[1].children[0]
        ;
        // The date must be the same
        assert.equal( selectedDate.isSame( mDate ), true );
        assert.equal( month, 11 );
        assert.equal( year, 2000 );
        // There should be a onClick function in the props
        assert.equal( typeof props.onClick, 'function' );
        // The cell text should be 'day'
        assert.equal( view.querySelector('.month').innerHTML, 'month' );
    });
    it( 'renderYear', function(){
        var props, year, selectedDate,
            component = createDatetime({ value: mDate, viewMode: 'years', renderYear: function( p, y, selected ){
                props = p;
                year = y;
                selectedDate = selected;
                return React.DOM.td( props, 'year' );
            }}),
            view = component.children[1].children[0]
        ;
        // The date must be the same
        assert.equal( selectedDate.isSame( mDate ), true );
        assert.equal( year, 2010 );
        // There should be a onClick function in the props
        assert.equal( typeof props.onClick, 'function' );
        // The cell text should be 'day'
        assert.equal( view.querySelector('.year').innerHTML, 'year' );
    });
});
tests/testdom.js
New file
@@ -0,0 +1,12 @@
module.exports = function(markup) {
   if (typeof document !== 'undefined') return
   var jsdom          = require("jsdom").jsdom
   global.document    = jsdom(markup || '<!doctype html><html><body></body></html>');
   global.window         = document.parentWindow;
   global.navigator = window.navigator = {};
    navigator.userAgent = 'NodeJs JsDom';
    navigator.appVersion = '';
    return document;
};