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

Jussi Lahtinen jussi.lahtinen at gmail.com
Sun Oct 27 23:19:23 CET 2019


if I do this:
? cstr(date.fromutc(date(2019,10,27,2,30)))

Is it guaranteed that in all possible localizations I will always get this?:
10/27/2019 02:30:00

Because I need to write my own routines for Year(), Month(), etc...


Jussi

On Sun, Oct 27, 2019 at 8:26 PM Benoît Minisini <g4mba5 at gmail.com> wrote:

> 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
> >> 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:
> > Date.ToUTC(date(2019,10,27,2,3))
> >
> >
> > ___
> > Lee
> >
>
> That's it.
>
> 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.
>
> Regards,
>
> --
> Benoît Minisini
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20191028/e2fd7844/attachment.html>


More information about the User mailing list