Dealing with AMAZON.date

amazon-alexa

#1

I’m attempting to set up a skill that returns the opening ours of some of our sites. Simple enough with Dialogflow, but Alexa is not nice.

If the user asks for eg Saturday the AMAZON.date is returning the weekend such as 2019-W25-E rather than the Saturday date eg 2019-06-22.

Apparently this is intended behavior according to the Amazon documentation.

How are people dealing with this?

Is there a way to get just the date and a timestamp like Dialogflow does?

I’m interested to use this to convert between timezones, hence a timestamp would be useful as well, but it doesn’t look like I can get the timestamp without specifically asking the user for it.

Any clues would be appreciated.
Cheers,
Ian


Date validation
#2

Hey @ian,
I liked the amazon-date-parser npm package (https://www.npmjs.com/package/amazon-date-parser), which will give you start and end date with a timestamp. I used it in combination with the moment npm package to bring dialogflow and alexa to a matching format:

if (jovo.isAlexaSkill()) {
                    dateIntervall = new AmazonDateParser(jovo.$inputs.date.value);
                    startDate = moment(dateIntervall.startDate.toDateString());
                    endDate = moment(dateIntervall.endDate.toDateString());
                }
else { //dialogflow
                dateIntervall = jovo.$inputs.date.value;
                startDate = moment(dateIntervall.startDate);
                endDate = moment(dateIntervall.endDate);
}

But I do not completely understand why “saturday” won’t return a date directly. The documentation says:

Utterances that map to a specific date (such as “today”, “now”, or “november twenty-fifth”) convert to a complete date: 2015-11-25 . Note that this defaults to dates on or after the current date (see below for more examples).
(https://developer.amazon.com/docs/custom-skills/slot-type-reference.html#date)


#3

Thanks for pointing me to the Amazon date parser, looks promising.

It’s entirely possible that people are asking for a weekend or their input is being interpreted as a weekend - or we just missed that the questions were around the weekend rather than the day.
(Further down in the documentation it lists the conditions around when it will return a weekend format).
Cheers,
Ian


#4

Beginner question: I can see how the above code works once the slot has been filled. I’m not sure what datatypes to give the slot in the inputs declaration.

Can someone clarify?