tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
987 stars 223 forks source link

Parsing timezone-unaware GPX files #182

Open juseg opened 4 years ago

juseg commented 4 years ago

Maybe a design question rather than a bug. Even when timezone info is missing from an input GPX file, gpxpy returns timezone-aware datetimes. Not only this may result in wrong timezones but also (luckily) timezone-aware times are typically incompatible with timezone-unaware times. For instance in Python's datetime module:

>>> import datetime
>>> utc = datetime.timezone.utc
>>> datetime.datetime(2019, 1, 2, tzinfo=utc) - datetime.datetime(2019, 1, 1)
TypeError: can't subtract offset-naive and offset-aware datetimes

Or in the latest version of pandas (v0.25.0):

>>> import pandas as pd
>>> pd.to_datetime('20190102-00:00:00+00:00') - pd.to_datetime('20190101-00:00:00')
TypeError: Timestamp subtraction must have the same timezones or no timezones

Wouldn't it be more logical that gpxpy returns timezone-unaware data when timezone information is missing? PS. Thanks a lot for your work!

tkrajina commented 4 years ago

Yes, I agree with you here. And this should be fixed together with #190 .