[Gambas-user] Different quantities of seconds from UNIX date...

Gianluigi bagonergi at gmail.com
Mon Apr 9 11:00:22 CEST 2018


2018-04-07 18:47 GMT+02:00 Gianluigi <bagonergi at gmail.com>:

>
>
> 2018-04-07 18:15 GMT+02:00 Benoît Minisini <g4mba5 at gmail.com>:
>
>> Le 07/04/2018 à 02:02, vuott at tiscali.it a écrit :
>>
>>> Hello,
>>>
>>> I do not understand why these two lines do not return the same result.
>>>
>>> Public Sub Main()
>>>
>>> Print CFloat(DateDiff(CDate("01/01/1970"), Now, gb.Second))
>>>
>>> Print CFloat(Date.ToUnixTime(Now))      ' Obviously we have to activate
>>> "gb.util" Component
>>>
>>> End
>>>
>>>
>>> So that the two results are identical, I have to add 4 hours !
>>>
>>> Public Sub Main()
>>>
>>> Print CFloat(DateDiff(CDate("01/01/1970 04:00:00"), Now, gb.Second))
>>>  '  Here I have to add 4 hours !
>>>
>>> Print CFloat(Date.ToUnixTime(Now))
>>>
>>> End
>>>
>>>
>>> regards
>>> vuott
>>>
>>>
>> It's a bug in Date.ToUnixTime() and Date.FromUnixTime() function.
>>
>> Can you try with commit https://gitlab.com/gambas/gamb
>> as/commit/72384c0806071556d50e1e8870dd12f868985155 ?
>>
>> Regards,
>>
>> --
>> Benoît Minisini
>>
>> --------------------------------------------------
>>
>> This is the Gambas Mailing List:
>> https://lists.gambas-basic.org/listinfo/user
>>
>> Search the list:
>> https://lists.gambas-basic.org/cgi-bin/search.cgi
>>
>> Hosted by https://www.hostsharing.net
>>
>
> Sorry, I know I'm the most ignorant of all, but I think the error is in
> DateDif and not in ToUnixTime, as (perhaps) demonstrated as follows:
>
> Public Sub Main()
>
>   unix
>   diff
>
> End
>
>
> Private Sub unix()
>
>   Dim i, u, r As Float
>
>   i = 60 * 60 * 24 ' ms of one day
>   u = CFloat(Date.ToUnixTime(Now)) ' epoc ms
>   r = u / i
>   r = Frac(r) ' remainder
>   Print Time(r) ' UTC correct
>
> End
>
> Private Sub diff()
>
>   Dim i, u, r As Float
>
>   i = 60 * 60 * 24 ' ms of one day
>   u = CFloat(DateDiff("01/01/1970", Now, gb.Second)) ' epoc ms???
>   r = u / i
>   r = Frac(r) ' remainder
>   Print Time(r) ' UTC incorrect (+ 4 hrs)
>
> End
>
> Regards
> Gianluigi
>

Hi Benoit,
Now both functions return + 4 hours compared to UTC time.
Here in Italy + 2 hours as daylight saving time is in effect

So I insist, for me ToUnixTime before was correct and the error is in
DateDiff
Regards
Gianluigi

[System]
Gambas=3.10.90 80c6f1f (master)
OperatingSystem=Linux
Kernel=4.13.0-38-generic
Architecture=x86_64
Distribution=Ubuntu 16.04.4 LTS
Desktop=UNITY
Theme=Cleanlooks
Language=it_IT.UTF-8
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180409/6deb1a20/attachment-0001.html>


More information about the User mailing list