Reputation: 11
I have a showtime at 7:30(f.ShowTime) and runtime for show is 1hr:45 min(this.movie.Runtime). The runtime will change based on movie.I have a button with movie timing which should be enabled only till 8:15 i.e 30 min before show ends.I have split the hours and min to different variables and I need to convert hours to min and add together which I am doing in this.showTimeStampmin but I am not getting the correct value.Pls let me know how to add showTimehours and showTimeminutes since I get concatenation of both values when I add '+' symbol.
orderfoodTimeStamp: any;
showTimeStamp: any;
showTimehours: any;
showTimeminutes: any;
showTimesec: any;
showTimeStampmin: any;
runTimehours: any;
runTimeminutes: any;
runTimesec: any;
runTimeStampmin: any;
this.showTimehours = moment(f.ShowTime).format("hh");
this.showTimeminutes = moment(f.ShowTime).format("mm");
this.showTimeStampmin = moment(this.showTimehours * 60,
'minutes').add(this.showTimeminutes, 'minutes').format("mm");
this.runTimehours = moment(this.movie.Runtime).format("hh");
this.runTimeminutes = moment(this.movie.Runtime).format("mm");
this.runTimeStampmin = (this.runTimehours * 60) + this.runTimeminutes;
this.orderfoodTimeStamp = (this.showTimeStampmin + this.runTimeStampmin) -
30;
if ((this.showTimeStampmin) <= this.orderfoodTimeStamp) {
f.Disabled = false;
} else {
f.Disabled = true;
}
Upvotes: 0
Views: 136
Reputation: 7456
You are making it so hard.
Just do use isBetween()
function like I did below:
const runtime = this.movie.Runtime.split(':');
const showEndTime = moment(showStartTime).add(parseInt(runtime[0]), 'hour').add(parseInt(runtime[1]), 'minute');
const enableButtonTime = showEndTime.add(-30, 'minute');
if (moment().isBetween(enableButtonTime , showEndTime )) {
disabled = false;
} else {
disabled = true;
}
Upvotes: 0