Skip to content
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

Open
mylastore opened this issue Jul 17, 2018 · 5 comments
Open
Labels

Comments

@mylastore
Copy link

This is not an issue just a question.

Can this be used as an appointment setter with time slots?

@quinnlangille
Copy link
Member

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?

@quinnlangille quinnlangille changed the title Can this be used as an appointment setter with slots? Question: Can this be used as an appointment setter with slots? Oct 10, 2018
@akhoury
Copy link

akhoury commented Oct 30, 2018

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, i.e. monday has a time range and not slots.

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 unavailability array, since, well its an array.

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
});

@akhoury
Copy link

akhoury commented Oct 30, 2018

The schedule object will end up looking something like this screenshot

screen shot 2018-10-30 at 4 19 30 pm

@nebez
Copy link

nebez commented Oct 31, 2018

Thanks for the thorough answer @akhoury !
@reachdevelopers - is this sufficient? We'll mark the issue as resolved in the coming days if no answer.

@leooxx
Copy link

leooxx commented Aug 15, 2020

Hello,

This solution doesn't really work.

Example:
9:00 - 12:00 / 12:30 - 17:00
Duration: 1:00

Result => 9:00, 10:00, 11:00, 13:00, 14:00, 15:00 ...

The correct result should be:
Result => 9:00, 10:00, 11:00, 12:30, 13:30, 14:30 ...

So, I made some changes on version 1.3.2 which seems to work:
https://github.com/leooxx/node-sscheduler-slots

It's possible to configure slots like this :

schedule: {
     monday: {
        slots: [
             {from: '09: 00 ', to: '10: 00'},
             {from: '11: 00 ', to: '12: 00'},
             {from: '14: 00 ', to: '15: 00'},
        ]
     }
}

Be careful, this is a first version!
Bye,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants