Skip to content

Instantly share code, notes, and snippets.

@memodoring
Created August 21, 2018 22:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save memodoring/84f19600e1c55f68e24af16535af52b8 to your computer and use it in GitHub Desktop.
Save memodoring/84f19600e1c55f68e24af16535af52b8 to your computer and use it in GitHub Desktop.
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()));
}
};
@rmtuckerphx
Copy link

Great! How about a sample using Moment Timezone library that tells you the time in the timezone of the device?

@rmtuckerphx
Copy link

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}`;

@mlescaille
Copy link

Thanks!

@darianbjohnson
Copy link

trying to get this example to work, but getting the following error "TypeError: upsServiceClient.getSystemTimeZone is not a function". Thoughts?

@darianbjohnson
Copy link

I forgot to upgrade to the latest version. :(

@rakolock1
Copy link

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!

@memodoring
Copy link
Author

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