Skip to content

Instantly share code, notes, and snippets.

@adicuco
Last active July 11, 2018 07:32
Show Gist options
  • Select an option

  • Save adicuco/03e3607393b30d4859d2aae63f4a2a35 to your computer and use it in GitHub Desktop.

Select an option

Save adicuco/03e3607393b30d4859d2aae63f4a2a35 to your computer and use it in GitHub Desktop.
function createBooking(agent) {
let guests = agent.parameters.guests;
let time = new Date(agent.parameters.time);
let date = new Date(agent.parameters.date);
let bookingDate = new Date(date);
bookingDate.setHours(time.getHours());
bookingDate.setMinutes(time.getMinutes());
let now = new Date();
if (guests < 1){
agent.add('You need to reserve a table for at least one person. Please try again!');
} else if (bookingDate < now){
agent.add(`You can't make a reservation in the past. Please try again!`);
} else if (bookingDate.getFullYear() > now.getFullYear()) {
agent.add(`You can't make a reservation for ${bookingDate.getFullYear()} yet. Please choose a date in ${now.getFullYear()}.`);
} else {
let timezone = parseInt(agent.parameters.time.toString().slice(19,22));
bookingDate.setHours(bookingDate.getHours() + timezone);
agent.add(`You have successfully booked a table for ${guests} guests on ${bookingDate.toString().slice(0,21)}`);
agent.add('See you at the restaurant!');
agent.add('Have a wonderful day!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment