[Time Zone] ConvertFromTimeZone

Forge Component
(13)
Published on 2018-10-01 by André Vieira
13 votes
Published on 2018-10-01 by André Vieira
I'm using the ConvertFromTimeZone action to convert from the current system time zone, to my time zone; however, the ConvertFromTimeZone action asks for the SourceTimeZone to be in a text format. How can I get the current system's time zone into the SourceTimeZone?
Hi!

check the sample application. You have there the information about the system time zone and how to convert to other time zones. You should probably use GetCurrentTimeZone to get the system time zone...
Hi,
I'm still a bit confused. What am I supposed to write (because it asks for a Text data type):
 ConvertFromTimeZone( ,Here, And Here)
Having an example in the Action Description would be good.

Hi Carlos,

You are right! The parameters of this action are missing some description :(
These are supposed to be identifiers of the TimeZoneInfo in C#.
You can validate how to use this action in the TimeZone module:
  • Open the screen in the MainFlow.
  • Double click the expression next to the  'Converted Data Time' label.
This expression uses this action.

Hope this helps, If not please share your module so that I can have a look and see what's missing...
Cheers
André,
how exactly am I supposed to write the TimeZone name in ConvertFromUTC(DateTimeUTC,TimeZone)?

Someone told me to use the names shown here:
https://msdn.microsoft.com/en-us/library/ms912391(v=winembedded.11).aspx

I don't really think that's how it works so...
Use the test page to determine the identifier you want (http://andrevieira.outsystemscloud.com/TimeZone/)
From the drop down select the timezone you want and below you will see the identifier which is the value you should use.

Hello Andre,

how would it be in case that I have many users entering from different timezones? and How can I change the time format from YYYYMMDD HH:MM:SS to MMDDYYYY HH:MM AM/PM ?

Thanks

HI Alvaro,

You should store your dates in UTC and convert them to the timezone of each user for display only. The way you manage this can be by automatically determining the timezone from the browser or the device or by a user configuration in the backoffice. Either way, you need to program for this.

Regarding the format it is independent of the timezone conversion since the timezone returns a DateTime. You can use the FormatDateTime function for that.

Cheers

Hello

Function (GetCurrentTimeZone) does get the system time zone from the server. Any idea how to get the client time zone? Will it be the client time zone defined on the PC or derived from another parameter like the IP?

Khalil Dahham wrote:

Hello

Function (GetCurrentTimeZone) does get the system time zone from the server. Any idea how to get the client time zone? Will it be the client time zone defined on the PC or derived from another parameter like the IP?

The client time will be derived based on the Client Browser settings for the Locale of the client,


Thank you André for sharing the test page, it was very helpful. Just one question about Daylight Saving, as you know the date to change the clocks for daylight saving might be different between countries, for example Mexico changes to daylight savings one or two weeks after the US, does TimeZone takes into account the dates defined by each country, or how does it works? 

Hi Isa,

The information about daylight saving is handled by the underlying library in .NET or Java. The library reports if the timezone supports daylight saving time and if it is currently using daylight saving time. You can test this on the test page searching for "Mexico, Mexico" in the location input.

André Vieira wrote:

Use the test page to determine the identifier you want (http://andrevieira.outsystemscloud.com/TimeZone/)
From the drop down select the timezone you want and below you will see the identifier which is the value you should use.

Hi gents,


I reckon Andre's proposed solution is a good one. I'm located at Australia. And By selecting the respective time zone and hit search, BOOM!, I got the identifier of my time zone, which is exactly the attribute for the action - ConvertTimeFromUTC(currentTime, TimeZone).

In terms of foramtting the time, I would suggest using DateTime_PrettyFormat(..). Very Handy.


What am I missing? I still don't understand how to get the client's timezone rather than the server's timezone.


Hi Peter.

Unfortunately the client timezone is not available through this component. Heck, it isn't even available through HTTP (as opposed to the language, which is available in HTTP headers).

You need to resort to JavaScript to find out the client's timezone. Here is the API you should use for that effect: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset


What I suggest you to do is to use this JavaScript API to send the offset to the server, and store it on a session variable. You can do this by including a hidden input and a button on your layout web block, then on page load use a javascript to write the timezone offset into that input and automatically click the button. Make sure the button is an ajax submit. I also suggest you only do this once (e.g. skip the click on the button if the session variable was already initialized with an offset).

A consequence of this is that you cannot be sure of the client's timezone on the first page load. If you need to re-render some content, you can end the button's logic with a redirect, which will reload the screen. A better usability would be to display a message saying "we detected that your timezone is XXX, click here to update the app to this timezone", and only set the session variable if the user clicks that link. The advantage of this is that it handles users that are in transit or on a short trip, and intentionally don't want to use the current timezone.

Hi Peter,

Check this article for a step by step instructions how to work with time zones.

Regards,

Marcelo

Thanks Leonardo & Marcelo!