1
votes

I am getting data from some sensors that record values in their respective (local) timezone. The timestamps do not indicate what timezone the sensor is in. I'm calling googleway::google_timezone() to use the Google timezone API and get the timezone corresponding to the geoggraphical location of the sensors.

The output is as below (example):

google_timezone(latlon, key = mykey)
$dstOffset
[1] 0

$rawOffset
[1] -18000

$status
[1] "OK"

$timeZoneId
[1] "America/Toronto"

$timeZoneName
[1] "Eastern Standard Time"

The dstOffset field is 0 which seems to be incorrect (location is in Eastern Canada with daylight savings). I need to save the data in UTC on a server. Using attr to convert from the local timezone to UTC fails to address the daylight savings issue - the time difference remains constant regardless of the time of the year. For N. America, the time difference should change by 1 hour during the year on account of daylight savings. I've read the answers for Daylight saving time and time zone best practices and https://stackoverflow.com/tags/timezone/info which seem to suggest that this information (daylight savings) is somehow contained in the "timezone".

Is there any other way to do this?

1

1 Answers

1
votes

Finally figured it out - it's just the way the API reports values. I expected the output to report a standard raw offset of four hours with a one hour offset in winter (when daylight savings are in effect) and zero hour offset in summer. Google API does it the other way around:

Here's the raw output from Google Maps Timezone API (bypassing googleway::google_timezone()) for Jan 11, 2018 (daylight savings in effect):

dstOffset:  0
rawOffset:  -18000
status: "OK"
timeZoneId: "America/Toronto"
timeZoneName:   "Eastern Daylight Time"

And here's the output for April 21, 2018 (daylight savings NOT in effect):

dstOffset:  3600
rawOffset:  -18000
status: "OK"
timeZoneId: "America/Toronto"
timeZoneName:   "Eastern Daylight Time"

This is a bit counter-intuitive and confusing since the daylight saving offset has a non-zero value when the daylight savings are not in effect!!

Anyway, I hope this can help others and also that some day we'll be rid of the scourge that is daylight savings.