Listing my Weekly Schedule:
weekly_schedule: any[] = [
{
id: 0,
value: 'Monday'
},
{
id: 1,
value: 'Tuesday'
}, {
id: 2,
value: 'Wednesday'
}, {
id: 3,
value: 'Thursday'
}, {
id: 4,
value: 'Friday'
}, {
id: 5,
value: 'Saturday'
},
{
id: 6,
value: 'Sunday'
},
]
Business Operational Hours:
business_hours = { day_to: 2, time_to: "23:00", day_from: 5, time_from: "08:00" }
I follow the UTC date format. I am checking if the days in weekly_schedule
align with the values given by day_from
and day_to
.
For instance, if day_from
is 5 (Saturday) and day_to
is 2 (Wednesday), then the necessary array should be:
["Saturday", "Sunday", "Monday". "Tuesday". "Wednesday"]
. The same logic applies for checking the current time against time_from
and time_to
.
The code snippet is as follows:
const activationDate = new Date();
const d_date = activationDate.getUTCDay() - 1;
console.log(d_date);
const B_from = this.getMin(this.business_hours.time_from);
const B_To = this.getMin(this.business_hours.time_to);
const min = activationDate.getUTCMinutes();
console.log(min)
const naan = activationDate.getUTCHours();
console.log(naan)
const utcTime = this.getUtcMin(naan, min);
for(let j = 0; j < this.business_hours.day_to; j++) {
for (let i = this.business_hours.day_from; i < this.weekly_schedule.length; i++) {
console.log(this.weekly_schedule[i]);
if (this.weekly_schedule[i].id === d_date) {
this.is_open = true;
console.log(this.weekly_schedule[i].value);
}
}
}
The expected results are not being generated by the current implementation.