Skip to content

Commit

Permalink
Parse integers before passing them further
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jul 11, 2019
1 parent cc138cf commit 1a640fe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/TimeInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,13 @@ export default class TimeInput extends PureComponent {
} else if (
formElements.every(formElement => formElement.value && formElement.checkValidity())
) {
const hour = `0${values.hour24 || convert12to24(values.hour12, values.amPm)}`.slice(-2);
const minute = `0${values.minute || 0}`.slice(-2);
const second = `0${values.second || 0}`.slice(-2);
const timeString = `${hour}:${minute}:${second}`;
const processedValue = this.getProcessedValue(timeString);
const hour = parseInt(values.hour24 || convert12to24(values.hour12, values.amPm) || 0, 10);
const minute = parseInt(values.minute || 0, 10);
const second = parseInt(values.second || 0, 10);

const padStart = num => `0${num}`.slice(-2);
const proposedValue = `${padStart(hour)}:${padStart(minute)}:${padStart(second)}`;
const processedValue = this.getProcessedValue(proposedValue);
onChange(processedValue, false);
}
}
Expand Down

0 comments on commit 1a640fe

Please sign in to comment.