Invalid date
kennymac3 opened this issue · 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
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));
Congratz Dennis for spotting the problem, how do we solve it?
yes, how do we solve it?
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?
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?
Hey guys, could anyone solve the problem above?
Setting proper timezone and timeZoneOffset i.e const timeZone
and const timeZoneOffset
works for me.
Find your timezone here:- https://www.zeitverschiebung.net/en/
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
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!
@Zhipeng-Chang still the same error it says "Invalid date"
@Smarto-Dev what is the error message in your firebase console?
getting the issue of " sorry we're booked " every time. but no issue with date n time
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.
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.
So here is the soln:
Below is the code given in the templateconst 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.