Skip to content
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

timezone lost in <time> fields when cloning/copying parsed GPX file #190

Open
3add3287 opened this issue Jan 7, 2020 · 0 comments
Open
Assignees
Labels

Comments

@3add3287
Copy link

3add3287 commented Jan 7, 2020

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

@tkrajina tkrajina added the bug label Jan 8, 2020
@tkrajina tkrajina self-assigned this Jan 8, 2020
tkrajina added a commit that referenced this issue Aug 14, 2020
ekspla added a commit to ekspla/gpxpy that referenced this issue Mar 23, 2021
Issue tkrajina#182
Support for TZ unaware timestamps.
Issue tkrajina#190
Support for cloned GPX (using deepcopy).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants