Skip to content

Commit

Permalink
Fixed #1217
Browse files Browse the repository at this point in the history
  • Loading branch information
Merve7 committed Mar 4, 2020
1 parent fc24216 commit b2c9f89
Showing 1 changed file with 77 additions and 10 deletions.
87 changes: 77 additions & 10 deletions src/components/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,34 @@ export class Calendar extends Component {
const currentTime = (this.props.value && this.props.value instanceof Date) ? this.props.value : this.getViewDate();
const currentHour = currentTime.getHours();
let newHour = currentHour + this.props.stepHour;
newHour = (newHour >= 24) ? (newHour - 24) : newHour;

if (this.validateHour(newHour, currentTime)) {
newHour = (newHour >= 24) ? (newHour - 24) : newHour;
this.updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds());

if(this.props.maxDate && this.props.maxDate.toDateString() === currentTime.toDateString() && this.props.maxDate.getHours() === newHour) {
if(this.props.maxDate.getMinutes() < currentTime.getMinutes()) {
if(this.props.maxDate.getSeconds() < currentTime.getSeconds()) {
this.updateTime(event, newHour, this.props.maxDate.getMinutes(), this.props.maxDate.getSeconds());
}
else {
this.updateTime(event, newHour, this.props.maxDate.getMinutes(), currentTime.getSeconds());
}
}
else if(this.props.maxDate.getMinutes() === currentTime.getMinutes()) {
if(this.props.maxDate.getSeconds() < currentTime.getSeconds()) {
this.updateTime(event, newHour, this.props.maxDate.getMinutes(), this.props.maxDate.getSeconds());
}
else {
this.updateTime(event, newHour, this.props.maxDate.getMinutes(), currentTime.getSeconds());
}
}
else {
this.updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds());
}
}
else {
this.updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds());
}
}

event.preventDefault();
Expand All @@ -676,10 +700,33 @@ export class Calendar extends Component {
const currentTime = (this.props.value && this.props.value instanceof Date) ? this.props.value : this.getViewDate();
const currentHour = currentTime.getHours();
let newHour = currentHour - this.props.stepHour;
newHour = (newHour < 0) ? (newHour + 24) : newHour;

if (this.validateHour(newHour, currentTime)) {
newHour = (newHour < 0) ? (newHour + 24) : newHour;
this.updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds());
if(this.props.minDate && this.props.minDate.toDateString() === currentTime.toDateString() && this.props.minDate.getHours() === newHour) {
if(this.props.minDate.getMinutes() > currentTime.getMinutes()) {
if(this.props.minDate.getSeconds() > currentTime.getSeconds()) {
this.updateTime(event, newHour, this.props.minDate.getMinutes(), this.props.minDate.getSeconds());
}
else {
this.updateTime(event, newHour, this.props.minDate.getMinutes(), currentTime.getSeconds());
}
}
else if(this.props.minDate.getMinutes() === currentTime.getMinutes()) {
if(this.props.minDate.getSeconds() > currentTime.getSeconds()) {
this.updateTime(event, newHour, this.props.minDate.getMinutes(), this.props.minDate.getSeconds());
}
else {
this.updateTime(event, newHour, this.props.minDate.getMinutes(), currentTime.getSeconds());
}
}
else {
this.updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds());
}
}
else {
this.updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds());
}
}

event.preventDefault();
Expand All @@ -689,10 +736,20 @@ export class Calendar extends Component {
const currentTime = (this.props.value && this.props.value instanceof Date) ? this.props.value : this.getViewDate();
const currentMinute = currentTime.getMinutes();
let newMinute = currentMinute + this.props.stepMinute;
newMinute = (newMinute > 59) ? (newMinute - 60) : newMinute;

if (this.validateMinute(newMinute, currentTime)) {
newMinute = (newMinute > 59) ? (newMinute - 60) : newMinute;
this.updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds());
if(this.props.maxDate && this.props.maxDate.toDateString() === currentTime.toDateString() && this.props.maxDate.getMinutes() === newMinute) {
if(this.props.maxDate.getSeconds() < currentTime.getSeconds()) {
this.updateTime(event, currentTime.getHours(), newMinute, this.props.maxDate.getSeconds());
}
else {
this.updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds());
}
}
else {
this.updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds());
}
}

event.preventDefault();
Expand All @@ -702,10 +759,20 @@ export class Calendar extends Component {
const currentTime = (this.props.value && this.props.value instanceof Date) ? this.props.value : this.getViewDate();
const currentMinute = currentTime.getMinutes();
let newMinute = currentMinute - this.props.stepMinute;
newMinute = (newMinute < 0) ? (newMinute + 60) : newMinute;

if (this.validateMinute(newMinute, currentTime)) {
newMinute = (newMinute < 0) ? (newMinute + 60) : newMinute;
this.updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds());
if(this.props.minDate && this.props.minDate.toDateString() === currentTime.toDateString() && this.props.minDate.getMinutes() === newMinute) {
if(this.props.minDate.getSeconds() > currentTime.getSeconds()) {
this.updateTime(event, currentTime.getHours(), newMinute, this.props.minDate.getSeconds());
}
else {
this.updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds());
}
}
else {
this.updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds());
}
}

event.preventDefault();
Expand All @@ -715,9 +782,9 @@ export class Calendar extends Component {
const currentTime = (this.props.value && this.props.value instanceof Date) ? this.props.value : this.getViewDate();
const currentSecond = currentTime.getSeconds();
let newSecond = currentSecond + this.props.stepSecond;
newSecond = (newSecond > 59) ? (newSecond - 60) : newSecond;

if (this.validateSecond(newSecond, currentTime)) {
newSecond = (newSecond > 59) ? (newSecond - 60) : newSecond;
this.updateTime(event, currentTime.getHours(), currentTime.getMinutes(), newSecond);
}

Expand All @@ -728,9 +795,9 @@ export class Calendar extends Component {
const currentTime = (this.props.value && this.props.value instanceof Date) ? this.props.value : this.getViewDate();
const currentSecond = currentTime.getSeconds();
let newSecond = currentSecond - this.props.stepSecond;
newSecond = (newSecond < 0) ? (newSecond + 60) : newSecond;

if (this.validateSecond(newSecond, currentTime)) {
newSecond = (newSecond < 0) ? (newSecond + 60) : newSecond;
this.updateTime(event, currentTime.getHours(), currentTime.getMinutes(), newSecond);
}

Expand Down

0 comments on commit b2c9f89

Please sign in to comment.