Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Alexa: AMAZON.DATE to Java Date/Duration

Tags:

java

iso8601

If I use AMAZON.DATE as a slot type, the user is able to input all kind of dates. Stating from the documentation: "2015-12", "2017-WI" (for winter of 2017) or "2015-W48-WE" (for weekend of week 48 of 2015). I want to parse these dates into Java dates/durations and I wonder how to achieve this.

Is there a Java library that takes a date like "2015-12" and returns two dates or a date and a duration? I can see a lot of potential problems like time zone handling or ambiguous dates, but I hope this is a common problem.

I could write a parser to save it as two Dates, one for the beginning of the month and one for the end of the month. Or a date for the beginning and a duration, but this seems like a lot of overhead to comply with ISO 8601.

like image 847
David Liffmann Avatar asked Oct 29 '22 15:10

David Liffmann


1 Answers

Amazon's Calendar Reader skill sample contains a JavaScript AMAZON.DATE parser that should be fairly easy to convert to other languages. It takes the slot value and returns a JavaScript Date object. According to the comments, it handles all of the idiomatic date formats.

// Utterances that map to the weekend for a specific week (such as 'this weekend') convert to a date indicating the week number and weekend: 2015-W49-WE.
// Utterances that map to a month, but not a specific day (such as 'next month', or 'December') convert to a date with just the year and month: 2015-12.
// Utterances that map to a year (such as 'next year') convert to a date containing just the year: 2016.
// Utterances that map to a decade convert to a date indicating the decade: 201X.
// Utterances that map to a season (such as 'next winter') convert to a date with the year and a season indicator: winter: WI, spring: SP, summer: SU, fall: FA)
like image 74
ladenedge Avatar answered Nov 09 '22 03:11

ladenedge