-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for time zones #915
Conversation
I found an issue with this implementation for the 'time' field type: the utcoffset of atimezone is not fixed. E.g. if the timezone has daylight saving times. The timezone Europe/Zurich is either UTC+1 or UTC+2. For datetime, this is no problem, as the date is known. Some drivers support timezones for times (e.g. PCDISK, although this driver converts the time to string). I would suggest raising an Exception if a driver does not support timezones and a feature contains a time with a timezone different than UTC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rbuffat I've built and tried this branch's code on my laptop, seems to be working as intended. I have a couple suggestions inline.
@rbuffat thank you! Can't wait to see this fixed in 1.8.14. |
This PR introduces support for time zones.
The PR includes #893 and #902. They are related and help here. I will update the PR once these PRs are merged or closed.
Timezones in GDAL can be set using the TZFlag of OGR_F_SetFieldDateTime[Ex]. Valid values are 0 for an unknown timezone and 100=GMT, 101=GMT+15minute, 99=GMT-15minute, .. for known timezones.
The current behavior of Fiona is to always use unknown timezones (TZFlag = 0). If a field with a timezone is read, the timezone information is discarded. Same for writing data. This leads to issues such as in #914
Support for timezones varies by driver, and unfortunately, no metadata is available for it.
Issues are:
This PR adds a data structure to identify these drivers in drvsupport and the functions _driver_supports_timezones(driver, field_type), _driver_supports_unknown_timezones(driver, field_type).
When reading data, the TZFlag of OGR_F_GetFieldAsDateTimeEx returns a TZFlag is now taken into account. E.g. for the case of #914, "2015-04-22T00:00:00+07:00" is now returned instead of "2015-04-22T00:00:00".
When writing data, it is checked if the driver supports the timezone. If yes, the datetime / time data is saved with the timezones.
If a driver does not support time zones (or only UTC), and the data to be written has a timezone other than UTC, the data is converted to UTC.
The GPKG driver, and the GPX driver until GDAL 2.4 do not support unknown timezones. These drivers interpret the unknown flag as GMT (Writing a TZFlag of 0 results in reading a TZFlag of 100). Thus, while with the old implementation, where the timezone is discarded, when a datetime value was returned as "2015-04-22T00:00:00" it will now be returned as "2015-04-22T00:00:00+00:00".
@jorisvandenbossche if you have time, could you look at the changes in ogrext.pyx and especially test_datetime.py