Amazon Alexa:Amazon.Date至Java日期/持续时间



如果我将Amazon.date用作插槽类型,则用户能够输入各种日期。从文档中说明:" 2015-12"," 2017-WI"(2017年冬季)或" 2015-W48-WE"(2015年第48周的周末)。我想将这些日期解析为Java日期/持续时间,我想知道如何实现这一目标。

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

我可以写一个解析器以将其保存为两个日期,一个是在月初,一个是在月底。或开始的日期和持续时间,但这似乎是很多符合ISO 8601的开销。

Amazon的日历读取器技能样本包含JavaScript Amazon.date Parser,它应该很容易转换为其他语言。它采用插槽值并返回JavaScript日期对象。根据评论,它处理所有惯用日期格式。

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

您可以使用nodejs中的亚马逊日期解析器将其转换。

Amazon-Date-Parser是一个有用的NPM软件包(在此处提供更多信息)。它将Amazon.Date插槽值转换为由Startdate组成的JS对象,即端代码,即:

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

最新更新