136
Views
4
Comments
[Time Zone] Reactive British Summer Time Daylight Savings Corrections
time-zone
Reactive icon
Forge asset by André Vieira
Application Type
Reactive

Hi.

I have an application that stores records into an external database. I wish to record the date and time that the record was entered. The application will be used in the UK where we have British Summer Time daylight savings.

I understand that when using CurrDateTime() via client action, uses the user devices date and time. I do not want to use this because 1) It could be manipulated by the user and 2) Some of the actions are completed by automated processes and there is no user.

Previously, In traditional web, I've used AddHours(CurrDateTime(),Site.BSToffset)) where the site parameter is the daylight saving adjustment. I don't wish to continue to use this, as it requires that admin teams remember to make that adjustment. 

I believe I need a server action that checks whether or not daylight savings is in effect. I've tried using a couple of Forge Components including Time Zone and Time Zone Service, but just can't get it to work properly. I would be very grateful if someone would be able to explain this to me like I'm 5!


2019-11-12 17-31-26
Justin James
 
MVP

If you pass CurrDateTime() in a server action to the Convert from this, and have the proper parameters (the timezone the servers are using, and the timezone you want to convert to), it should work just fine and account for Daylight Savings time without an issue.

If that isn't working, please post a sample OML and I will try to take a look when I have a moment.

Thanks!

J.Ja

2021-11-22 00-14-28
Leigh Rogers

Thank you.

I've managed to get it working.

I'm not sure it behaves how I expected it to.

For example, if you run CurrDateTime() in a server action with the right parameters, it returns the correct date time whilst in the server action. However, when you return that to a client action, it seems to be translated back to something else.

For example. I used the ConvertFromUTC action, which correctly added an hour onto UTC to get the correct current UK time whilst in the server action. But when you return that to a client action, it adds on another hour, which makes it 2 hours ahead of UTC and therefore one hour ahead of current UK time.

The screenshot below from my test module demonstrates this. I also converted the DateTime to text before returning it and when compared to the returned DateTime value, you can see how it is adjusted when it is returned to the client action.


So, as long as I know I can trust the datetime created by time zone component in server actions, and don't try and return it to the client to validate or display it, then I should be ok...

2019-11-12 17-31-26
Justin James
 
MVP

Leigh -

I'm going to recommend that you spend some time checking out the documentation around time zones. The summary here, when a Reactive app sends a full date/time to the server, it gets converted from the user's browser's time zone to the server's time zone. When a Traditional Web app does things, or server-side code (Timers, BPTs, Emails, Service Actions, Server Actions) is running, all date/times are left un-converted. But understanding the nuance will help you tons here.

J.Ja

2019-10-18 11-14-22
Lee Geraghty

You can use this expression, we are also UK based and have had the same issues.

ConvertFromTimeZone(CurrDateTime(), GetCurrentTimeZone().TimeZone.Identifier, "GMT Standard Time")

I would be cautious about the saving of the records with these times as then your times unalign with the server, but we tend to use this for display only in records on the front end in tables/lists etc.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.