Alexa内置插槽AMAZON.DATE

时间:2016-09-08 17:00:45

标签: amazon-web-services alexa-skills-kit

使用内置插槽AMAZON.DATE时,“下周”将被解释为developer reference的2016-W38。

  

映射到特定周的话语(例如“本周”或   “下周”),转换表示周数的日期:2015-W49。

我试图在SQL中解析它。使用Alexa服务时,是W1或W01的第一周吗?感谢。

2 个答案:

答案 0 :(得分:0)

更新:日期为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周。 (7分之267= 38.14)。
  • 算回年初38周。

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

答案 1 :(得分:0)

这就是我最终使用SQL Server存储过程解析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中做这样的事情。 FYI

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