Created
August 21, 2018 22:07
-
-
Save memodoring/84f19600e1c55f68e24af16535af52b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const upsInterceptor={ | |
async process(handlerInput){ | |
let { requestEnvelope, serviceClientFactory, attributesManager} = handlerInput; | |
let {deviceId} = requestEnvelope.context.System.device; | |
const upsServiceClient = serviceClientFactory.getUpsServiceClient(); | |
const usertimeZone = await upsServiceClient.getSystemTimeZone(deviceId); | |
const requestAttributes = attributesManager.getRequestAttributes(); | |
requestAttributes.timeZone = usertimeZone; | |
attributesManager.setRequestAttributes(requestAttributes); | |
console.log(JSON.stringify(attributesManager.getRequestAttributes())); | |
} | |
}; |
Here I go answering my own request:
// Handler
const moment = require('moment-timezone');
const requestAttributes = attributesManager.getRequestAttributes();
const now = moment.utc();
const localTime = now.tz(requestAttributes.timeZone).format('ddd, MMM D, YYYY [at] h:mma');
const speech = `Your local time is ${localTime}`;
Thanks!
trying to get this example to work, but getting the following error "TypeError: upsServiceClient.getSystemTimeZone is not a function". Thoughts?
I forgot to upgrade to the latest version. :(
i am getting the same error that darianbjohnson got. Unfortunately, I'm not sure what I need to update or how to do it. A little help would be appreciated. Thanks!
i am getting the same error that darianbjohnson got. Unfortunately, I'm not sure what I need to update or how to do it. A little help would be appreciated. Thanks!
Hey rakolock1, you need to make sure you have the latest ask-sdk in your node_modules folder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! How about a sample using Moment Timezone library that tells you the time in the timezone of the device?