fulfillment-bike-shop-nodejs icon indicating copy to clipboard operation
fulfillment-bike-shop-nodejs copied to clipboard

Invalid date

Open kennymac3 opened this issue 5 years ago • 15 comments

Hi there,

thanks for creating this template.

After i have followed all the steps, i tried the bot and after i fill up the date and time, it says " I'm sorry, there are no slots available for Invalid Date. "

Possible to assist? Thanks in advance! Kenny

kennymac3 avatar Oct 18 '18 14:10 kennymac3

I experienced the same issue (albeit with the code version from this tutorial) and traced it down to the time zone offset. I'm in European time zone (GMT+1) and configured my agent, fulfillment and calendar to be in this time zone, rather than in the LA time zone in the code. The parsing code in the snippet below assumes the "date" parameter to contain a "-" to split, so it only supports time zones with a negative offset.

function makeAppointment (agent) {
   // Calculate appointment start and end datetimes (end = +1hr from start)
   const dateTimeStart = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('-')[0] + timeZoneOffset));

DennisvdPluijm avatar Oct 24 '18 11:10 DennisvdPluijm

Congratz Dennis for spotting the problem, how do we solve it?

unbanksytv avatar Nov 16 '18 23:11 unbanksytv

yes, how do we solve it?

JohnnyB95 avatar Nov 27 '18 17:11 JohnnyB95

I experienced the same issue (albeit with the code version from this tutorial) and traced it down to the time zone offset. I'm in European time zone (GMT+1) and configured my agent, fulfillment and calendar to be in this time zone, rather than in the LA time zone in the code. The parsing code in the snippet below assumes the "date" parameter to contain a "-" to split, so it only supports time zones with a negative offset.

function makeAppointment (agent) {
   // Calculate appointment start and end datetimes (end = +1hr from start)
   const dateTimeStart = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('-')[0] + timeZoneOffset));

What do we need to modify in our code to allow for support of other timezones?

JohnnyB95 avatar Nov 29 '18 03:11 JohnnyB95

yes, how do we solve it?

in this code : agent.parameters.time.split('T')[1].split('-')[0] just replace '-' to your local timezone symbol for an example, my timezone is +07:00, then i replace '-' to '+' but the response is still

"I'm sorry, there are no slots available for February 1, 1 PM."

which is i don't have any event for that date in my google calendar how to fix it?

Prayuga avatar Jan 31 '19 10:01 Prayuga

Hey guys, could anyone solve the problem above?

lupeh-dcu avatar May 03 '19 13:05 lupeh-dcu

Setting proper timezone and timeZoneOffset i.e const timeZone and const timeZoneOffset works for me. Find your timezone here:- https://www.zeitverschiebung.net/en/

Tirth27 avatar May 05 '19 14:05 Tirth27

const dateTimeStart = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('-')[0] + timeZoneOffset));

Hi Dennis, I am in New Zealand time . I changed the setting as per your suggestion but no luck. Can you please help. Thanks Naimish

naimishranderi avatar May 29 '19 03:05 naimishranderi

Hi all! I fixed the problem by changing the code to: const dateTimeStart = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time + timeZoneOffset));

I found that the agent.parameters.time always return the time in this format: '15:32:00', so there is no need to split the time with '-' or 'T', we can just combine the time with the date and timeZone offset as long as you have correct offset.

Hopefully It helps!

jackson-zhipeng-chang avatar Jun 20 '19 21:06 jackson-zhipeng-chang

@Zhipeng-Chang still the same error it says "Invalid date"

Smarto-Dev avatar Jul 04 '19 04:07 Smarto-Dev

@Smarto-Dev what is the error message in your firebase console?

jackson-zhipeng-chang avatar Jul 04 '19 15:07 jackson-zhipeng-chang

getting the issue of " sorry we're booked " every time. but no issue with date n time

borasuyog avatar Jul 24 '19 21:07 borasuyog

So here is the soln: Below is the code given in the template

 const timeZone = 'America/Los_Angeles'; 
 const timeZoneOffset = '-07:00'; 
 const dateTimeStart  = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('-')[0] + timeZoneOffset));

As we can see, the timezone followed is 'America/Los_Angeles', But as I live in India, changed code snippet will be:

 const timeZone = 'India/Kolkata'; 
 const timeZoneOffset = '+5:30'; 
 const dateTimeStart  = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('+')[0] + timeZoneOffset));

//check how I replaced '-' with '+' as offset for me is '+5:30' in last line

Hence find your respective timezones and do the mentioned changes.

vidushi-agarwal avatar Mar 17 '20 07:03 vidushi-agarwal

See below the code that worked for me. Take as example Spain:

const timeZone = 'Europe/Madrid' const timeZoneOffset = '+02:00' const dateTimeStart = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('+')[0] + timeZoneOffset))

Make sure you have the time timeZoneOffset with the following format '+/-nn:nn'. I was missing the leading zero ('+02:00') in my example.

icm92 avatar Jul 10 '20 20:07 icm92

So here is the soln: Below is the code given in the template

 const timeZone = 'America/Los_Angeles'; 
 const timeZoneOffset = '-07:00'; 
 const dateTimeStart  = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('-')[0] + timeZoneOffset));

As we can see, the timezone followed is 'America/Los_Angeles', But as I live in India, changed code snippet will be:

 const timeZone = 'India/Kolkata'; 
 const timeZoneOffset = '+5:30'; 
 const dateTimeStart  = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('+')[0] + timeZoneOffset));

//check how I replaced '-' with '+' as offset for me is '+5:30' in last line

Hence find your respective timezones and do the mentioned changes.

Thanks man, worked for me.

mdfarooq0815 avatar Apr 27 '21 05:04 mdfarooq0815