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

Gianluigi bagonergi at gmail.com
Sat Apr 7 18:47:50 CEST 2018


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180407/c026811a/attachment.html>


More information about the User mailing list