Skip to content

Commit

Permalink
Fix primefaces#2301: Calendar stepMinute in proper increments
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Nov 20, 2021
1 parent 804480b commit f3ac9d7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/components/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,26 @@ export class Calendar extends Component {
event.preventDefault();
}

doStepMinute(currentMinute, step) {
if (this.props.stepMinute <= 1) {
return currentMinute;
}
if (!step) {
step = this.props.stepMinute;
if (currentMinute % step === 0) {
return currentMinute;
}
}

var newMinute = currentMinute + step;
newMinute = Math.floor(newMinute / step) * step;
return newMinute;
}

incrementMinute(event) {
const currentTime = this.getCurrentDateTime();
const currentMinute = currentTime.getMinutes();
let newMinute = currentMinute + this.props.stepMinute;
let newMinute = this.doStepMinute(currentMinute, this.props.stepMinute);
newMinute = (newMinute > 59) ? (newMinute - 60) : newMinute;

if (this.validateMinute(newMinute, currentTime)) {
Expand Down Expand Up @@ -910,7 +926,7 @@ export class Calendar extends Component {
decrementMinute(event) {
const currentTime = this.getCurrentDateTime();
const currentMinute = currentTime.getMinutes();
let newMinute = currentMinute - this.props.stepMinute;
let newMinute = this.doStepMinute(currentMinute, -this.props.stepMinute);
newMinute = (newMinute < 0) ? (newMinute + 60) : newMinute;

if (this.validateMinute(newMinute, currentTime)) {
Expand Down

0 comments on commit f3ac9d7

Please sign in to comment.