亚马逊Alexa:AMAZON.DATE到Java日期/持续时间

时间:2016-12-07 15:51:18

标签: java iso8601

如果我使用AMAZON.DATE作为插槽类型,则用户可以输入所有类型的日期。从文档说明: " 2015-12"," 2017-WI" (2017年冬季)或" 2015-W48-WE" (2015年第48周的周末)。我想将这些日期解析为Java日期/持续时间,我想知道如何实现这一点。

是否有一个Java库,其日期类似于" 2015-12"并返回两个日期或日期和持续时间? 我可以看到许多潜在的问题,如时区处理或模棱两可的日期,但我希望这是一个常见的问题。

我可以编写一个解析器将其保存为两个日期,一个用于月初,一个用于月末。或者开始日期和持续时间,但这似乎是符合ISO 8601的大量开销。

2 个答案:

答案 0 :(得分:3)

亚马逊的Calendar Reader技能示例包含a JavaScript AMAZON.DATE parser,应该很容易转换为其他语言。它获取槽值并返回JavaScript Date对象。根据评论,它处理所有惯用的日期格式。

// 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)

答案 1 :(得分:-1)

您可以在Node.js中使用Amazon日期解析器对其进行转换。

amazon-date-parser是一个有用的npm软件包(此处有更多信息)。它将AMAZON.DATE广告位值转换为由startDate和endDate组成的JS对象,即:

var AmazonDateParser = require('amazon-date-parser');
var date = new AmazonDateParser('2017-W48');
console.log(date);