Search code examples
widgetalexa-skills-kitalexa-presentation-language

Calculating Timezone offset within an APL document for an Alexa Widget


Is there a way from within an APL document to determine the device’s timezone and apply the timezone offset to time represented as milliseconds since the epoch of 1970-01-01T00:00:00Z?

I’m looking to do this in APL because I’m using the Data Store REST API to update data stored on a device which will be displayed by an Alexa Widget.  The data includes a UTC date/time. The Data Store REST API will be initiated by a cron job, updating all supported Alexa devices for a given user.  I can’t see where I would have access to the device’s timezone like I normally would inside a skill intent handler.

I have reviewed the built-in data binding Time functions, but those don’t appear to handle timezone offsets.


Solution

  • APL data binding gives you utcTime and localTime properties, if you subtract the utcTime value from the localTime value then you'll have an offset which you can add to your utc value.

    https://developer.amazon.com/en-US/docs/alexa/alexa-presentation-language/apl-data-binding-evaluation.html#initial-data-binding-context

            "bind": [
              {
                "name": "msOffset",
                "value": "${localTime-utcTime}"
              }
            ]