timezone lost in <time> fields when cloning/copying parsed GPX file
3add3287 opened this issue · 0 comments
3add3287 commented
When parsing a GPX file that doesn't use UTC but TZ aware timestamps, the timestamp is lost when using the clone method. The cloned gpx object now shows the same time as before, but with the wrong timezone. "2018-04-04T10:36:53-0600" now becomes "2018-04-04T10:36:53Z"
The following illustrates the problem:
#!/usr/local/bin/python3.7
import sys
import re
import gpxpy
with open(sys.argv[1], mode='r') as gpx_file:
GPX = gpxpy.parse(gpx_file)
GPX_COPY = GPX.clone()
GPX_XML_ORIG = GPX.to_xml()
GPX_XML_COPY = GPX_COPY.to_xml()
RETIME = re.compile(r'<time>.*</time>')
TIMES_ORIG = RETIME.findall(GPX_XML_ORIG)
TIMES_COPY = RETIME.findall(GPX_XML_COPY)
print("Original:\n{}\n\nCopy:\n{}\n".format(
"\n".join(TIMES_ORIG[1:5]),
"\n".join(TIMES_COPY[1:5])
))
Using a GPX file with TZ aware timestamps:
./test-gpxpy-tz.py GarminNuviTest.gpx
Original:
<time>2018-04-04T10:36:53-0600</time>
<time>2018-04-04T10:41:07-0600</time>
<time>2018-04-04T10:44:44-0600</time>
<time>2018-04-04T10:44:50-0600</time>
Copy:
<time>2018-04-04T10:36:53Z</time>
<time>2018-04-04T10:41:07Z</time>
<time>2018-04-04T10:44:44Z</time>
<time>2018-04-04T10:44:50Z</time>
python 3.7.6 and Gpxpy 1.3.5