-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Can this be used as an appointment setter with slots? #9
Comments
Hey @reachdevelopers, I'm not sure if you're still looking for an answer to this, but if so could you elaborate on "appointment setter with time slots"? And if possible, could you send an example? |
If I am not mistaken, I think @reachdevelopers is asking the following: if you have free slots for appointments let's say, can this figure out the availability? since the "weekday" schedule: {
monday: {
from: '09:00',
to: '17:00'
}
} vs something like this schedule: {
monday: {
slots: [
{ from: '09:00', to: '10:00' },
{ from: '11:00', to: '12:00' },
{ from: '14:00', to: '15:00' },
]
}
} The answer is YES, but you gotta leverage the so say you have let weekdays = {
monday: {
slots: [
{ from: '09:00', to: '10:00' },
{ from: '11:00', to: '12:00' },
{ from: '14:00', to: '15:00' }
]
},
tuesday: {
slots: [
{ from: '12:00', to: '13:00' }
]
},
// .... etc
};
let schedule = {};
for (let dayName in weekdays) {
let weekday = weekdays[dayName];
if (weekday && weekday.slots && weekday.slots.length) {
// choose when the day starts and ends
// i ran into an infinite loop when I used "00:00" and "23:59", but I didn't investigate it, it's happening internally in this module
// so I just chose 1am and 11pm
let dayStartTime = '01:00';
let dayEndTime = '23:00';
// create "momentified" versions of these times
let mDayStartTime = moment(dayStartTime, 'HH:mm');
let mDayEndTime = moment(dayEndTime, 'HH:mm');
// create an entry for that dayName in the schedule
schedule[dayName] = {
from: dayStartTime,
to: dayEndTime,
reference: `${dayName}.[${weekday.slots.map(s => `${s.from}-${s.to}`).join(',')}]`,
unavailability: []
};
// here we set the unavailability,
// basically anything not in the SLOTS is unavailable
weekday.slots.forEach((slot, i) => {
let mSlotStartTime = moment(slot.from, 'HH:mm');
let mSlotEndTime = moment(slot.to, 'HH:mm');
// from the start of the day till the beginning of the slot
schedule[dayName].unavailability.push({
from: mDayStartTime.format('HH:mm'),
to: mSlotStartTime.format('HH:mm'),
reference: `${dayName}.{${slot.from},${slot.to}}`
});
if (weekday.slots.length - 1 !== i) {
// then shift the start till the end of that slot, and repeat
mDayStartTime = mSlotEndTime.clone();
} else {
// if last slot we add one more unavailability till the dayEndTime
schedule[dayName].unavailability.push({
from: mSlotEndTime.clone().format('HH:mm'),
to: mDayEndTime.format('HH:mm'),
reference: `${dayName}.{${slot.from}-${slot.to}}(last slot)`
});
}
});
}
}
// now you can use the schedule object we just created in
const availability = scheduler.getAvailability({
from: '2017-02-01',
to: '2017-03-01',
duration: 60,
interval: 60,
schedule
}); |
Thanks for the thorough answer @akhoury ! |
Hello, This solution doesn't really work. Example: Result => 9:00, 10:00, 11:00, 13:00, 14:00, 15:00 ... The correct result should be: So, I made some changes on version 1.3.2 which seems to work: It's possible to configure slots like this :
Be careful, this is a first version! |
This is not an issue just a question.
Can this be used as an appointment setter with time slots?
The text was updated successfully, but these errors were encountered: