Alexa 内置插槽 AMAZON.DATE

Alexa built-in slot AMAZON.DATE

使用内置插槽 AMAZON.DATE 时,根据 developer reference.

,"next week" 被解释为 2016-W38

Utterances that map to just a specific week (such as “this week” or “next week”), convert a date indicating the week number: 2015-W49.

我正在尝试在 SQL 中解析它。使用Alexa服务时是一年的第一周还是W01?谢谢

更新:日期采用 ISO-8601 日期格式。第一周是W01,没有W00.

参考:https://en.wikipedia.org/wiki/ISO_8601#Dates

来源:https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interaction-model-reference

原回答:

我找不到文档,但这是答案...

  • 今天是 9 月 28 日星期三,第 272 天。
  • Alexa 说这是 2016-W39。 (我刚查过)。
  • 2016 年是从星期五开始的,所以 W39 是从上周五的第 267 天开始的,也就是 1 月 1 日之后的 38 周。 (267/7=38.14).
  • 倒数 38 周到年初。

因此,一年中的第一周称为 W1。

这就是我最终使用 SQL 服务器存储过程解析 AMAZON.DATE 内置槽的方式。

CREATE PROCEDURE [dbo].[procMomaAlexaExhibitions]

@p_alexa_date VARCHAR(50) = ''

AS
BEGIN

SET NOCOUNT ON;

DECLARE @p_start_date VARCHAR(10) = ''
DECLARE @p_end_date VARCHAR(10) = ''

--SET @p_alexa_date = '2015-W20-WE'

-- Today if null
IF(@p_alexa_date = '' OR @p_alexa_date IS NULL)
BEGIN
SET @p_start_date = (SELECT CONVERT(VARCHAR(10), GETDATE(), 121)) 
SET @p_end_date = (SELECT CONVERT(VARCHAR(10), GETDATE(), 121)) 
END

-- Alexa provided a normal date
IF(ISDATE(@p_alexa_date) = 1)
BEGIN
SET @p_start_date =  CONVERT(VARCHAR(10), @p_alexa_date, 121) 
SET @p_end_date =  CONVERT(VARCHAR(10), @p_alexa_date, 121) 
END

-- Alexa provided a year-month
IF(LEN(@p_alexa_date) <= 8 AND ISNUMERIC(REPLACE(@p_alexa_date,'-','')) = 1)
BEGIN
SET @p_start_date = @p_alexa_date + '-01' 
SET @p_end_date =  @p_alexa_date + '-31' 
END

-- weekend
IF(RIGHT(@p_alexa_date, 3) = '-WE') 
    BEGIN
    DECLARE @p_week VARCHAR(2)
    DECLARE @p_year VARCHAR(4)
    DECLARE @p_start_date_wk VARCHAR(10) = ''
    DECLARE @p_end_date_wk VARCHAR(10) = ''

    SET @p_week = REPLACE(SUBSTRING(@p_alexa_date,7, LEN(@p_alexa_date)),'-WE','')
    SET @p_year = LEFT(@p_alexa_date, 4)

    SET @p_start_date_wk = CONVERT(VARCHAR(10),  DATEADD(wk, DATEDIFF(wk, 6, '1/1/' + @p_year) + (@p_week-1), 6), 121)  
    SET @p_end_date_wk = CONVERT(VARCHAR(10), DATEADD(wk, DATEDIFF(wk, 5, '1/1/' + @p_year) + (@p_week-1), 5), 121)    

    SET @p_start_date = CASE WHEN datename(weekday, CAST(@p_start_date_wk AS smalldatetime)) = 'Saturday' THEN CONVERT(VARCHAR(10), CAST(@p_start_date_wk AS smalldatetime), 121)  
                             WHEN datename(weekday, CAST(@p_start_date_wk AS smalldatetime) + 1) = 'Saturday' THEN CONVERT(VARCHAR(10), CAST(@p_start_date_wk AS smalldatetime) + 1, 121)  
                             WHEN datename(weekday, CAST(@p_start_date_wk AS smalldatetime) + 2) = 'Saturday' THEN CONVERT(VARCHAR(10), CAST(@p_start_date_wk AS smalldatetime) + 2, 121)  
                             WHEN datename(weekday, CAST(@p_start_date_wk AS smalldatetime) + 3) = 'Saturday' THEN CONVERT(VARCHAR(10), CAST(@p_start_date_wk AS smalldatetime) + 3, 121)  
                             WHEN datename(weekday, CAST(@p_start_date_wk AS smalldatetime) + 4) = 'Saturday' THEN CONVERT(VARCHAR(10), CAST(@p_start_date_wk AS smalldatetime) + 4, 121)  
                             WHEN datename(weekday, CAST(@p_start_date_wk AS smalldatetime) + 5) = 'Saturday' THEN CONVERT(VARCHAR(10), CAST(@p_start_date_wk AS smalldatetime) + 5, 121)  
                             WHEN datename(weekday, CAST(@p_start_date_wk AS smalldatetime) + 6) = 'Saturday' THEN CONVERT(VARCHAR(10), CAST(@p_start_date_wk AS smalldatetime) + 6, 121)  
                             END
    SET @p_end_date = CASE WHEN datename(weekday, CAST(@p_end_date_wk AS smalldatetime)) = 'Sunday' THEN CONVERT(VARCHAR(10), CAST(@p_end_date_wk AS smalldatetime), 121)  
                             WHEN datename(weekday, CAST(@p_end_date_wk AS smalldatetime) + 1) = 'Sunday' THEN CONVERT(VARCHAR(10), CAST(@p_end_date_wk AS smalldatetime) + 1, 121)  
                             WHEN datename(weekday, CAST(@p_end_date_wk AS smalldatetime) + 2) = 'Sunday' THEN CONVERT(VARCHAR(10), CAST(@p_end_date_wk AS smalldatetime) + 2, 121)  
                             WHEN datename(weekday, CAST(@p_end_date_wk AS smalldatetime) + 3) = 'Sunday' THEN CONVERT(VARCHAR(10), CAST(@p_end_date_wk AS smalldatetime) + 3, 121)  
                             WHEN datename(weekday, CAST(@p_end_date_wk AS smalldatetime) + 4) = 'Sunday' THEN CONVERT(VARCHAR(10), CAST(@p_end_date_wk AS smalldatetime) + 4, 121)  
                             WHEN datename(weekday, CAST(@p_end_date_wk AS smalldatetime) + 5) = 'Sunday' THEN CONVERT(VARCHAR(10), CAST(@p_end_date_wk AS smalldatetime) + 5, 121)  
                             WHEN datename(weekday, CAST(@p_end_date_wk AS smalldatetime) + 6) = 'Sunday' THEN CONVERT(VARCHAR(10), CAST(@p_end_date_wk AS smalldatetime) + 6, 121)  
                             END
    END

-- not a weekend
IF((@p_alexa_date LIKE '%-W%') AND (RIGHT(@p_alexa_date, 3) <> '-WE'))
    BEGIN

    SET @p_week = SUBSTRING(@p_alexa_date,7, LEN(@p_alexa_date))
    SET @p_year = LEFT(@p_alexa_date, 4)

    SET @p_start_date = CONVERT(VARCHAR(10),  DATEADD(wk, DATEDIFF(wk, 6, '1/1/' + @p_year) + (@p_week-1), 6), 121)  
    SET @p_end_date = CONVERT(VARCHAR(10), DATEADD(wk, DATEDIFF(wk, 5, '1/1/' + @p_year) + (@p_week-1), 5), 121)    

    END

从那里你可以在 SQL 中做这样的事情。仅供参考

WHERE  (ExhVenuesXrefs.BeginISODate <= @p_start_date) 
AND (ExhVenuesXrefs.EndISODate >= @p_end_date)