Skip to content

remove timezone part from date string - #77

Merged
tkrajina merged 4 commits into
tkrajina:masterfrom
sjol:date_parse_fix
Dec 16, 2016
Merged

tkrajina merged 4 commits into
tkrajina:masterfrom
sjol:date_parse_fix

Conversation

@sjol

@sjol sjol commented Dec 1, 2016

Copy link
Copy Markdown
Contributor

passed unit tests on python2.7 (I don't have 3 currently installed)

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.04%) to 84.745% when pulling 1035014 on sjol:date_parse_fix into beb884f on tkrajina:master.

1 similar comment
@coveralls

coveralls commented Dec 1, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.04%) to 84.745% when pulling 1035014 on sjol:date_parse_fix into beb884f on tkrajina:master.

@coveralls

coveralls commented Dec 1, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.04%) to 84.745% when pulling 162fafd on sjol:date_parse_fix into beb884f on tkrajina:master.

@tkrajina

tkrajina commented Dec 1, 2016

Copy link
Copy Markdown
Owner

Yes, that makes sense, thanks!

There are just a few changes I'd add here. First, what if instead of 2014-02-02T10:03:18Z the date string in the GPX is 2014-2-2T10:3:18Z (without leading zeros in two-digit numbers). In that case your [0:18] index will not work as expected.

And, another thing, add a test in test.py. Something like:

    def test_remove_timezone_from_timestamp(self):
        xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
        xml += '<gpx>\n'
        xml += '<trk>\n'
        xml += '<trkseg>\n'
        xml += '<trkpt lat="35.794159" lon="-5.832745"><time>2014-02-02T10:23:18Z-TIMEZONE_ARTIFACT_HERE</time></trkpt>\n'
        xml += '</trkseg></trk></gpx>\n'
        gpx = mod_gpxpy.parse(xml, parser=self.get_parser_type())
        self.assertEquals(gpx.tracks[0].segments[0].points[0].time, ...)

@sjol

sjol commented Dec 1, 2016

Copy link
Copy Markdown
Contributor Author

Cool, I'll take a look at adding the test as well.

Not sure if checking for digits without leading zeros, as this is not correct according to https://www.w3.org/TR/xmlschema-2/#isoformats, which I think is what GPX is based.

If we do want support it, I think only a regex could help us, but that might be a bit slow.

@coveralls

coveralls commented Dec 2, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.07%) to 84.853% when pulling 91465c1 on sjol:date_parse_fix into beb884f on tkrajina:master.

1 similar comment
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.07%) to 84.853% when pulling 91465c1 on sjol:date_parse_fix into beb884f on tkrajina:master.

@coveralls

coveralls commented Dec 2, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.07%) to 84.853% when pulling 75fbf58 on sjol:date_parse_fix into beb884f on tkrajina:master.

@sjol

sjol commented Dec 5, 2016

Copy link
Copy Markdown
Contributor Author

This should be ready for merging now. Don't know if the regular expression affects performance a lot, but at least it should only be invoked when the time string is shorter than the expected length of 19.

With this PR it works for the gpx files produced by the very useful gps tracking app LD-log.

@tkrajina
tkrajina merged commit 5ea43e5 into tkrajina:master Dec 16, 2016
@tkrajina

Copy link
Copy Markdown
Owner

Merged, thanks!

@sjol
sjol deleted the date_parse_fix branch December 16, 2016 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants