I am building an Alexa skill and using AMAZON.DATE slot type to get a date.
My problem is that when a user says a date without a year, Alexa processes it and returns the date string with a future date.
Example - Today is 2017-09-20
, User asks Alexa about date 'Sixth June'
, Alexa returns 2018-06-06
.
I want to use the closest past date instead of closest future dates, for the case when the user doesn't specify a year in the utterance. If the user specifies a year, I don't want to change the date year.
I can't handle this on AWS Lambda using Python, as Alexa sends the complete date string, no matter if the user provides the year or not, in the JSON body.
I don't know if it is even possible to handle such user inputs with Alexa. Is there something I can do about the AMAZON.DATE slot or some other way to handle such user utterances?
You cannot do that with built-in date slot,
Utterances that map to a specific date (such as “today”, or “november twenty-fifth”) convert to a complete date: 2015-11-25. Note that this defaults to dates on or after the current date.
one logic you can try it out is to do a custom logic. Take the difference between todays date and next year same date of user input. If the difference of months between those is greater than 6 months then the nearest would be future date. If difference is less that 6 months then past date. Say user gives an input July 25th (on 2017 ) and todays date is August 25th 2017. Now you can add 1 year to July 25th then you will get July 25th 2018. Difference between July 25th 2018 and August 25th 2017 is greater than 6 months so the date you want is past date, which is July 25th 2017 and vice versa. For more accuracy you can count in days instead of months