Skip to content

Instantly share code, notes, and snippets.

@michaelmontero
Last active November 2, 2018 15:21
Show Gist options
  • Save michaelmontero/ba19509dd5c2392d8a4739b6d12f0ded to your computer and use it in GitHub Desktop.
Save michaelmontero/ba19509dd5c2392d8a4739b6d12f0ded to your computer and use it in GitHub Desktop.
const Moment = require("moment");
const { extendMoment } = require('moment-range');
const moment = extendMoment(Moment);
var contains = (startDate, endDate, checkDate) => {
var range = moment.range(startDate, endDate);
return range.contains(checkDate);
};
module.exports = { contains };
import { contains } from './../some-directory/date.js';
//Objeto sucursal donde se pretende crear la cita
var data = {
"_id": "5bdb44e14c119d01843ad229",
"rated": 5,
"schedule": [
{
"startHour": "08:00",
"endHour": "12:00"
},
{
"startHour": "14:00",
"endHour": "20:00"
}
],
"specialSchedule": [
{
"startDate": 1542254400000,
"endDate": 1542686400000,
"description": "Mantenimiento"
}
],
"company": "5bdb44e14c119d01843ad228",
"name": "Av. Lope de Vega",
"phone": "111-111-1111",
"address": {
"street": "Av Lincond",
"number": 18,
"township": "Santo Domingo este"
}
};
willBeOpen = (desiredDate : number) => {
var isAvailable = data.specialSchedule.filter(date => {
var desiredDate = 111111111111; //Date timestamp
return contains(date.startDate, date.endDate, desiredDate);
});
//if isAvailable has data means the desiredDate is between a branchoffice's special date
return isAvailable.length === 0;
}
var appointmentDate = new Date().getTime();
var isOpen = willBeOpen(appointmentDate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment