-
Notifications
You must be signed in to change notification settings - Fork 225
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
Add subsecond and timezone support #160
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Combining the Z suffix (for UTC) with a timezone offset makes no sense. Note that this did not cause the tests to fail because the time parsing code strips both anyway but the tests should use a valid syntax. Signed-off-by: Francois Gouget <fgouget@free.fr>
Signed-off-by: Francois Gouget <fgouget@free.fr>
Signed-off-by: Francois Gouget <fgouget@free.fr>
Test the timestamp parsing function through TimeConverter class which is the actual interface used by gpxpy. This allows testing the conversion of DateTime objects back to strings. Remove the code that's stripping the trailing 'Z' from the test strings: it's shorter and clearer to just add the relevant tests. For each timestamp store the actual DateTime components we're expecting so we can more precisely check the result of the conversion. Add more variants of the timestamp formats we want to support. Signed-off-by: Francois Gouget <fgouget@free.fr>
The time parsing code was losing the second decimals. When the GPX file is used to interpolate the position of photos based on their timestamp this can lead to a loss of precision proportional to the speed at which the camera is moving, that is as much as 30 meters at highway speeds. Only drop the '+HH:MM' and 'Z' timezone specifications when they are at the end of the string and truncate the second decimals to microsecond precision to accomodate datetime's strptime() function. Modify test_parse_time() so it verifies the returned datetime object, including the second decimals unlike test_long_timestamps()! Modify TimeConverter.to_string() so it preserves the sub-second data but preserves the old format if none is specified. Signed-off-by: Francois Gouget <fgouget@free.fr>
It has simply been renamed to assertEqual(). Signed-off-by: Francois Gouget <fgouget@free.fr>
Applications that use GPX files to geolocalize other data (e.g. photos) based on the timestamps must know which timezone each of them is basedi on. So return the timezone information if specified in the timestamp. Note that this changes the gpxpy API in that timezone aware DateTime objects cannot be directly compared with naive DateTime objects. This means applications that only dealt with naive DateTime objects will now need to at least be ready to strip the tzinfo field of DateTime objects returned by gpxpy. Signed-off-by: Francois Gouget <fgouget@free.fr>
4 similar comments
Implemented in #152 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This branch includes my previous subsecond support and adds support for returning the TimeZone information in the DateTime objects.
As noted in the commit this means gpxpy may now return timezone aware DateTime objects which means applications that try to mix them with naive DateTime objects will need to be modified.
Another approach with less potential for breaking applications would be to systematically do the conversion to UTC and keep returning naive DateTime objects. But this means the application would still not know what timezone was initially used.
Or one could make this configurable so only timezone aware applications get timezone aware DateTime objects. But this would require more drastic changes to the architecture so TimeConvert can know what to do.