Fix value calculation when increasing/decreasing over min/max values
| | |
| | | increase: function( type ){ |
| | | var value = parseInt(this.state[ type ], 10) + this.timeConstraints[ type ].step; |
| | | if ( value > this.timeConstraints[ type ].max ) |
| | | value = this.timeConstraints[ type ].min; |
| | | value = this.timeConstraints[ type ].min + ( value - this.timeConstraints[ type ].max ); |
| | | return this.pad( type, value ); |
| | | }, |
| | | decrease: function( type ){ |
| | | var value = parseInt(this.state[ type ], 10) - this.timeConstraints[ type ].step; |
| | | if ( value < this.timeConstraints[ type ].min ) |
| | | value = this.timeConstraints[ type ].max; |
| | | value = this.timeConstraints[ type ].max + 1 - ( this.timeConstraints[ type ].min - value ); |
| | | return this.pad( type, value ); |
| | | }, |
| | | pad: function( type, value ){ |
| | |
| | | createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){ |
| | | i++; |
| | | if( i > 2 ){ |
| | | assert.equal( selected.hour(), 0 ); |
| | | assert.equal( selected.hour(), 4 ); |
| | | assert.equal( selected.minute(), 17 ); |
| | | assert.equal( selected.second(), 3 ); |
| | | done(); |
| | | } |
| | | }, timeConstraints: { hours: { max: 2 }, minutes: { step: 15 }}}); |
| | | }, timeConstraints: { hours: { max: 6, step: 8 }, minutes: { step: 15 }}}); |
| | | |
| | | trigger( 'mousedown', dt.timeUp( 0 ) ); |
| | | trigger('mouseup', document.body ); |
| | | assert.equal( dt.hour().innerHTML, 0 ); |
| | | assert.equal( dt.hour().innerHTML, 4 ); |
| | | trigger( 'mousedown', dt.timeUp( 1 ) ); |
| | | trigger( 'mouseup', dt.timeUp( 1 ) ); |
| | | assert.equal( dt.minute().innerHTML, 17 ); |
| | |
| | | assert.equal( dt.second().innerHTML, 3 ); |
| | | }); |
| | | |
| | | it( 'decrease time with timeConstraints', function( done ){ |
| | | createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){ |
| | | assert.equal( selected.minute(), 47 ); |
| | | done(); |
| | | }, timeConstraints: { minutes: { step: 15 }}}); |
| | | |
| | | trigger( 'mousedown', dt.timeDown( 1 ) ); |
| | | trigger( 'mouseup', dt.timeDown( 1 ) ); |
| | | assert.equal( dt.minute().innerHTML, 47 ); |
| | | }); |
| | | |
| | | it( 'invalid input value', function( done ){ |
| | | createDatetime({ defaultValue: 'luis', onChange: function( updated ){ |
| | | assert.equal( mDate.format('L LT'), updated.format('L LT') ); |