Dates, timestamps and timezones

Hi guys,

I’m trying to get the current date/time in Paris. I’m using an HTTP API that returns the following JSON for the date 2018-03-31 19:10:55:

{"status":"OK","message":"","countryCode":"FR","countryName":"France","zoneName":"Europe\\/Paris","abbreviation":"CEST","gmtOffset":7200,"dst":"1","dstStart":1521939600,"dstEnd":1540688400,"nextAbbreviation":"CET","timestamp":1522523455,"formatted":"2018-03-31 19:10:55"}

I can’t seem to get the correct time and date (2018-03-31 19:10:55) using the Xojo.Core.Date class and I’m sure it’s because I’m using the constructor incorrectly.

Using the timestamp value from the JSON yields 2018-03-31 21:10:55

dim tz as new Xojo.Core.TimeZone("Europe/Paris") dim d as new Xojo.Core.Date(1522523455, tz)

Using dstStart yields 2018-03-25 03:00:00

dim tz as new Xojo.Core.TimeZone("Europe/Paris") dim d as new Xojo.Core.Date(1521939600, tz)

Using dstEnd yields 2018-10-28 02:00:00

dim tz as new Xojo.Core.TimeZone("Europe/Paris") dim d as new Xojo.Core.Date(1540688400, tz)

The best I can get is two hours out. What am I doing wrong here? Can anyone help?

Thanks,

On a machine set to US EST time zone, I get the exact France time with this :

[code]Dim d As Xojo.Core.Date = Xojo.Core.Date.Now

dim tz as new Xojo.Core.TimeZone(“Europe/Paris”)

Dim myDate As Xojo.Core.Date = Xojo.Core.Date.Now ’ Get date for current time zone

Dim FRDate As New Xojo.Core.Date(myDate.SecondsFrom1970, tz)

msgbox FRDate.ToText[/code]

use gmtoffset which is 7200 seconds, that is the 2 hours you need to substract to the timestamp field.

Thanks!

Hum…

I would rather use “Europe/Paris” instead of a 2 hours offset, since it takes care of daylight saving time.

Otherwise the offset changes with daylight saving time or not. That is less robust.

I hope gmtoffset should change to 3600 when not in daylight saving time ?

While this might fix it mathematically, it does not explain why the api reports Paris local time plus two additional hours. The offset indicates that Paris local time in summer time is GMT + 2, looks like a bug to me.

Do you think the bug is with Xojo or the API?

I’ve settled on this approach which seems to work:

dim t as Text = "2018-03-31 19:10:55" ' Pulled from the "formatted" JSON key try dim d as Xojo.Core.Date = Xojo.Core.Date.FromText( t ) catch ' Fail end try

I verified that the time was right with Xojo.Core.Date. I am inclined to believe the web API is off.

[quote=380468:@Garry Pettet]Do you think the bug is with Xojo or the API?

I’ve settled on this approach which seems to work:

dim t as Text = "2018-03-31 19:10:55" ' Pulled from the "formatted" JSON key try dim d as Xojo.Core.Date = Xojo.Core.Date.FromText( t ) catch ' Fail end try[/quote]

The API by the look of it.