Where the information for userTimezone.id comes from?

82 צפיות
מעבר להודעה הראשונה שלא נקראה

Ihor Stefurak

לא נקראה,
12 באוג׳ 2020, 6:05:3312.8.2020
עד Google Apps Script Community
I'm working on a Gmail Add-on and accessing userTimezone.id using this code, and it's working:

function onHomePage(e) {
 var userTimeZoneId = e.userTimezone.id;
 Logger.log(userTimeZoneId);
}

The problem is when I go to Google Calendar and change my timezone, the function shows the same information. Is it cached somewhere? Where the information comes from?

Alan Wells

לא נקראה,
12 באוג׳ 2020, 8:15:2612.8.2020
עד Google Apps Script Community
The calendar time zone is independent from the script project time zone.
Also, a Google Sheet can have it's own time zone.
A Google Form doesn't have a setting for it's own time zone.
So, change the time zone in your Apps Script project, and see if that does something.
File -> Project properties -> Time Zone

Ihor Stefurak

לא נקראה,
12 באוג׳ 2020, 8:34:1912.8.2020
עד Google Apps Script Community
As I'm working on the public add-on I would like to access the user's time zone not the script's one.

Anyway, I opened the settings you suggest and noticed a different timezone from what was printed by my log's.

Знімок екрана  о 15.17.08.png


The script's timezone can be accessed by Session.getScriptTimeZone().

Знімок екрана  о 15.31.01.png


Here is what I see in logs: the result from Session.getScriptTimeZone() is at the top, the result from e.userTimezone.id — at the bottom.

Alan Wells

לא נקראה,
12 באוג׳ 2020, 8:42:4112.8.2020
עד Google Apps Script Community
Try changing the time zone on your computers operating system.
I know that if the time zone in the computers operating system is changed,
that changes the browser time zone.
Other than that, I don't have any other guesses of how to change the time zone returned by:
e.userTimezone
If you change the time zone on your computers operating system,
you may eventually be detected as a potential security risk.
Regardless of whether you are or not.
I'm assuming that you want to do testing for different time zones for your add-on.

Andrew Roberts

לא נקראה,
12 באוג׳ 2020, 8:43:4312.8.2020
עד google-apps-sc...@googlegroups.com
Personally, I use the user's calendar to get their timezone -

https://developers.google.com/apps-script/reference/calendar/calendar#gettimezone.

Although this will require extra scopes.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/371f4eb9-0d10-4470-9b6f-a6ce60694263o%40googlegroups.com.

Andrew Roberts

לא נקראה,
12 באוג׳ 2020, 8:45:2912.8.2020
עד google-apps-sc...@googlegroups.com
Take a look at getCalendarDateTime() in this library  (ID: 1X2qbPZljrYN_TrvWkwW8OAn6zQgN7Gu5o1D4OBq522FVaCskiyZe44Au), which may be useful.

Ihor Stefurak

לא נקראה,
12 באוג׳ 2020, 8:48:3312.8.2020
עד Google Apps Script Community
Thanks for helping me figure this out AJ! Changing my computer's timezone helped. Now I'm sure it's working properly.

Andrew, thanks for the option. I won't request another restricted scope just to get timezone.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
השב לכולם
השב למחבר
העבר לנמענים
0 הודעות חדשות