Skip to content

Commit

Permalink
Fix not truncating at minutes the first time in <TimePicker> (#24305)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 authored Jul 31, 2020
1 parent 67dce6d commit ab5eedf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/components/src/date-time/test/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<TimePicker
currentTime="1986-10-18T23:12:35"
onChange={ onChangeSpy }
is12Hour
/>
);

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' );
} );
} );
4 changes: 3 additions & 1 deletion packages/components/src/date-time/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ab5eedf

Please sign in to comment.