[Gambas-user] Daylight "saving" and time zones

T Lee Davidson t.lee.davidson at gmail.com
Sun Oct 27 18:22:20 CET 2019

On 10/26/19 9:42 PM, Jussi Lahtinen wrote:
> Is there a reliable way to detect any of those shenanigans happening to system clock?
> And how much is shifted and in what direction?

> Let's say I want this; date(2019,10,27,2,3) in UTC, but I'm in different time zone (or perhaps even suddenly changing time zone without any warning). How I get the Date() function to return correct values?
> It would be easy, if date would accept one more argument; date(2019,10,27,2,3, "UTC")...

I think I must be missing something in what you are asking since I'm almost certain that you, knowing more about Gambas than I, 
must already be aware of the gb.util Date functions and System.TimeZone.

It is recommended that a system with only Linux on it should have the hardware (CMOS) clock set to UTC. If that is the case, 
then the system clock should not change. (Linux uses the glibc time functions to convert the system time to local time as needed 
using the time zone info stored under, eg., /usr/share/zoneinfo.)

System.TimeZone yields, "the number of seconds you must add to the local time to get the UTC time." Since this number can be 
negative, this gives us the amount of shift and the direction. Following the example in the Wiki, if one's time zone is UTC+2, 
System.TimeZone will return -7200 since one would actually have to subtract 7200 seconds to get back to a UTC representation.

gb.util has Date.FromUTC ("Move a date back to local time if its local representation is actually in UTC.") and Date.ToUTC 
("Move a date so that its local representation is its UTC value."). So then perhaps one could do:


More information about the User mailing list