In Gmail Add-ons you can get the user timezone and locale in buildAddOn parameters by activating the useLocaleFromApp. Check the documentation of Accessing User Locale and Timezone
Step to get the timezone and locale:
- In manifest add useLocaleFromApp with true
"useLocaleFromApp": true
- Add the scope "https://www.googleapis.com/auth/script.locale"
- In buildAddOn you will receive the parameter userLocale and userTimezone
Manifest example:
{
"timeZone": "Etc/GMT"
"oauthScopes": ["https://www.googleapis.com/auth/gmail.addons.execute", "https://www.googleapis.com/auth/gmail.addons.current.message.readonly", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/script.external_request","https://www.googleapis.com/auth/script.locale"],
"gmail": {
"name": "TestApp",
"logoUrl": "https://storage.googleapis.com/xxxxxxx/favicon.ico",
"contextualTriggers": [{
"unconditional": {
},
"onTriggerFunction": "buildAddOn"
}],
"primaryColor": "#fea001",
"secondaryColor": "#fea001",
"openLinkUrlPrefixes": ["https://mail.google.com/"],
"version": "TRUSTED_TESTER_V2",
"useLocaleFromApp": true
}
}
Add-ons example:
function buildAddOn(e)
{
var cards = [];
var card = CardService.newCardBuilder().setName("Test timeZone");
card.setHeader(CardService.newCardHeader().setTitle("test"));
var section = CardService.newCardSection();
section.addWidget( CardService.newTextParagraph().setText(e.userLocale));
section.addWidget( CardService.newTextParagraph().setText(e.userTimezone.offSet));
section.addWidget( CardService.newTextParagraph().setText(e.userTimezone.id));
card.addSection(section);
cards.push( card.build());
return cards;
}
Caution with userTimezone.offSet parameter. The parameter have
distinct case that the referenced in the documentation. The parameter
is userTimezone.offSet with S uppercase