[Gambas-user] Daylight "saving" and time zones
g4mba5 at gmail.com
Sun Oct 27 19:25:43 CET 2019
Le 27/10/2019 à 18:22, T Lee Davidson a écrit :
> 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
>> 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:
You must understand that there is always an implicit timezone when
dealing with a date as as string, or with the Date() function and the
functions of the same family: Year(), Month()...
The implicit timezone is always the local timezone (as returned by
System.TimeZone) except for CStr() and CDate(), that assumes UTC timezone.
Internally, the date is stored in UTC.
More information about the User