[Gambas-user] Daylight "saving" and time zones
Jussi Lahtinen
jussi.lahtinen at gmail.com
Sun Oct 27 22:19:15 CET 2019
Sorry, the other line is incorrect.
This is what I want:
? cstr(date(2019,10,27,2,3, "UTC"))
10/27/2019 02:03:00
Jussi
On Sun, Oct 27, 2019 at 11:05 PM Jussi Lahtinen <jussi.lahtinen at gmail.com>
wrote:
> I don't think you have missed anything, but the solution you offer doesn't
> seem to work or maybe I'm missing something.
>
> ? Date.ToUTC(date(2019,10,27,2,3))
> 10/27/2019 00:03:00
>
> ? cstr(Date.ToUTC(date(2019,10,27,2,3)))
> 10/26/2019 22:03:00
>
> ? cstr(date(2019,10,27,2,3))
> 10/27/2019 00:03:00
>
> ? system.timezone
> -7200
>
> This is what I want in essense:
>
> ? date(2019,10,27,2,3, "UTC")
> 10/27/2019 02:03:00
>
> ? cstr(date(2019,10,27,2,3, "UTC"))
> 10/27/2019 02:03:00
>
> In other words, if I write date 27.10.2019 and time 2:03, it should be
> just that and nothing else. I don't want to make guesses where the user
> might travel or when there might be other sudden changes in the time zone.
> System.timezone is not useful here, because it is not constant.
>
>
> Jussi
>
> On Sun, Oct 27, 2019 at 7:23 PM T Lee Davidson <t.lee.davidson at gmail.com>
> wrote:
>
>> 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
>>
>>
>> ----[ 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/20191027/fe1e8c84/attachment-0001.html>
More information about the User
mailing list