diff --git a/packages/components/src/date-time/test/time.js b/packages/components/src/date-time/test/time.js index 52b33247e1e82e..c55ef191275090 100644 --- a/packages/components/src/date-time/test/time.js +++ b/packages/components/src/date-time/test/time.js @@ -200,4 +200,23 @@ describe( 'TimePicker', () => { pmButton.simulate( 'click' ); expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T11:00:00' ); } ); + + it( 'should truncate at the minutes on change', () => { + const onChangeSpy = jest.fn(); + + const wrapper = shallow( + + ); + + const minuteInput = wrapper.find( 'input[aria-label="Minutes"]' ); + + minuteInput.simulate( 'change', { target: { value: '22' } } ); + minuteInput.simulate( 'blur' ); + + expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T23:22:00' ); + } ); } ); diff --git a/packages/components/src/date-time/time.js b/packages/components/src/date-time/time.js index b2f9c1e44785d5..1b502d70aaf669 100644 --- a/packages/components/src/date-time/time.js +++ b/packages/components/src/date-time/time.js @@ -73,7 +73,9 @@ class TimePicker extends Component { changeDate( newDate ) { const dateWithStartOfMinutes = newDate.clone().startOf( 'minute' ); this.setState( { date: dateWithStartOfMinutes } ); - this.props.onChange( newDate.format( TIMEZONELESS_FORMAT ) ); + this.props.onChange( + dateWithStartOfMinutes.format( TIMEZONELESS_FORMAT ) + ); } getMaxHours() {