[Time Zone] GetTimeZoneForLocation throws (400) Bad Request.

[Time Zone] GetTimeZoneForLocation throws (400) Bad Request.

  
Forge Component
(7)
Published on 24 May by André Vieira
7 votes
Published on 24 May by André Vieira

Hi,


I am using the Timezone component to convert some date/time fields according to the user's timezone.

When the user logs in the application I'm setting a variable to the user's location (IANA timezone format)

Intl.DateTimeFormat().resolvedOptions().timeZone


After that I have an action to get the timezone for the user's location (GetTimeZoneForLocation) and also the server's timezone (GetCurrentTimeZone). Using this 2 Timezone identifiers I convert the date/time fields I need to be displayed correctly using CovertFromTimezone action.


The problem is that for example on Internet Explorer (happened on 10 and also on 11) I get the following error (see the attachment) like constantly, but recently I got the same error on chrome. It's not consistent on chrome, but on Internet Explorer it happens all the time. I've also seen that the component uses some Google API to which it sends the coordinates to get the timezone, maybe that's somehow related to the problem.


Thanks in advance :)


Hi Bogdan,

The problem is related to the Google API call. Can you indicate what are you passing to the GetTimeZoneForLocation action?

Hi Andre,


As I previously stated I'm using the timezone (text format - IANA) returned from my Javascript which is stored in a session variable and that's what I'm passing to the GetTimeZoneForLocation action.


One example of timezone would be "Europe/Bucharest".

Solution

Hi Bogdan,

Understood. GetTimeZoneForLocation expects to receive as a parameter a location as in "Paris, France" not an IANA timezone. I've uploaded a new version with a new method that supports IANA timezone codes.

I also updated the sample so that you can test it using IANA codes.

Cheers

Solution

Thank you for the fix, the Timezone component is actually not causing our problems.


The thing is that currently the Internet Explorer browser doesn't support the javascript to get the IANA Timezone so it returns an undefined value. With the last version of the Timezone component I could see that in the logs it tried to calculate the timezone for an empty string "" and figured out that this is causing our issues.


One last question is how could we get the timezone from which the user accesses the aplication in order to use the Timezone component actions.


Anyway, many thanks for your quick and helpful response :)

ECMAScript Internationalization API is only supported by Microsoft starting from Internet Explorer 11.

You can consider using a javascript library for doing this like this one https://bitbucket.org/pellepim/jstimezonedetect - be sure to check the limitations. I took a quick look at the code and I don't see them using the Internationalization API, they're using the Date.getTimezoneOffset which is available since Internet Explorer 5 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset.


Hope this helps.