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

vuott at tiscali.it vuott at tiscali.it
Sat Apr 7 19:39:47 CEST 2018


  By using a external standard C function, its result is same that
.ToUnixTime() Method:

Library "libc:6"

Public Struct timespec
 tv_sec
As Long
 tv_nsec As Long
End Struct

Private Const CLOCK_REALTIME As
Integer = 0

' int clock_gettime (clockid_t __clock_id, struct timespec
*__tp)
' Get current value of clock CLOCK_ID and store it in TP.
Private
Extern clock_gettime(__clock_id As Integer, __tp As Timespec) As
Integer

Public Sub Main()

 Dim spec As New Timespec


clock_gettime(CLOCK_REALTIME, spec)

 Print spec.tv_sec, "(from external
function)"

 Print CFloat(Date.ToUnixTime(Now)), "(with .ToUnixTime()
Method)"

 Print CFloat(DateDiff("01/01/1970 04:00:00", Now,
gb.Second)), "(by adding 4 hours)"

 Print
 Print
CFloat(DateDiff("01/01/1970", Now, gb.Second)), "(--> NO added
hours)"

End

regards
vuott

Il 07.04.2018 18:47 Gianluigi ha scritto:


> 2018-04-07 18:15 GMT+02:00 Benoît Minisini :
> 
>> Le 07/04/2018 à
02:02, vuott at tiscali.it [1] 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/gambas/commit/72384c0806071556d50e1e8870dd12f868985155
[2] ?
>> 
>> Regards,
>> 
>> -- 
>> Benoît Minisini
>> 
>>
--------------------------------------------------
>> 
>> This is the
Gambas Mailing List:
>> https://lists.gambas-basic.org/listinfo/user
[3]
>> 
>> Search the list:
>>
https://lists.gambas-basic.org/cgi-bin/search.cgi [4]
>> 
>> Hosted by
https://www.hostsharing.net [5]
> 
> 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
 



Con Mobile Open 6 GB hai 6 Giga, 600 minuti e 300 SMS per il tuo smartphone a 9€ al mese per sempre. Passa ora a Tiscali Mobile, il nostro mese è vero! http://tisca.li/Open6GB0318

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180407/906dcea0/attachment.html>


More information about the User mailing list