Skip to content

Commit

Permalink
Support for timestamps missing the fraction of a second
Browse files Browse the repository at this point in the history
  • Loading branch information
fortysix2ahead committed Oct 21, 2022
1 parent 0cbfb7b commit 93494a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions tcxreader/tcxreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ def trackpoint_parser(self, tcx_point:TCXTrackPoint, trackpoint):
index = 0
for trackpoint_data in trackpoint:
if trackpoint_data.tag == GARMIN_XML_SCHEMA + 'Time':
tcx_point.time = datetime.datetime.strptime(
trackpoint_data.text, '%Y-%m-%dT%H:%M:%S.%fZ')
try:
tcx_point.time = datetime.datetime.strptime(
trackpoint_data.text, '%Y-%m-%dT%H:%M:%S.%fZ' )
except ValueError:
tcx_point.time = datetime.datetime.strptime(
trackpoint_data.text, '%Y-%m-%dT%H:%M:%SZ' )
elif trackpoint_data.tag == GARMIN_XML_SCHEMA + 'Position':
for position in trackpoint_data:
if position.tag == GARMIN_XML_SCHEMA + "LatitudeDegrees":
Expand Down
2 changes: 1 addition & 1 deletion tcxreader/tests/data/sup_activity_1.tcx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</Extensions>
</Trackpoint>
<Trackpoint>
<Time>2022-07-16T16:08:39.000Z</Time>
<Time>2022-07-16T16:08:39Z</Time>
<Position>
<LatitudeDegrees>46.637007063254714</LatitudeDegrees>
<LongitudeDegrees>16.168354768306017</LongitudeDegrees>
Expand Down

0 comments on commit 93494a6

Please sign in to comment.