Skip to content

Commit

Permalink
DateTimePicker: correctly convert hours from 12 to 24 format when upd…
Browse files Browse the repository at this point in the history
…ating the time
  • Loading branch information
ciampo committed Nov 25, 2021
1 parent ef17f3f commit 7a1df8e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/components/src/date-time/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,16 @@ export function TimePicker( { is12Hour, currentTime, onChange } ) {
}

function update( name, value ) {
// If the 12-hour format is being used and the 'PM' period is selected, then
// the incoming value (which ranges 1-12) should be increased by 12 to match
// the expected 24-hour format.
let adjustedValue = value;
if ( is12Hour ) {
adjustedValue = from12hTo24h( value, am === 'PM' );
}

// Clone the date and call the specific setter function according to `name`.
const newDate = date.clone()[ name ]( value );
const newDate = date.clone()[ name ]( adjustedValue );
changeDate( newDate );
}

Expand Down

0 comments on commit 7a1df8e

Please sign in to comment.