fix: use timezone-aware timestamp() instead of timetuple()#350
Merged
jpoehnelt merged 1 commit intogooglemaps:masterfrom Apr 24, 2020
Merged
fix: use timezone-aware timestamp() instead of timetuple()#350jpoehnelt merged 1 commit intogooglemaps:masterfrom
jpoehnelt merged 1 commit intogooglemaps:masterfrom
Conversation
Contributor
|
I merged the doc fix #351, mind rebasing? |
fixes issue where convert.time ignores timezone in the datetime object.
current implementation:
times = [
datetime(2020, 3, 14, 8, 0, tzinfo=timezone.utc),
datetime(2020, 3, 14, 9, 0, tzinfo=timezone(timedelta(hours=1))),
datetime(2020, 3, 14, 8, 0, tzinfo=timezone(timedelta(hours=1)))
]
for time in times:
print(convert.time(time))
output:
1584153000
1584156600
1584153000
technically, as @atollena describes, the first two times should be
considered to be the same, whereas the third datetime instance is
expected be an hour behind the first two instances. but by using
timetuple(), the specified timezone is ignored. so, using the
timestamp() method instead of timetuple() ensures that the specified
timezone is respected:
new implementation (assuming the same list of times from before):
for time in times:
print(convert.time(time))
output:
1584172800
1584172800
1584169200
here, the specified timezone data is respected, and as expected the
third datetime instance is 3600 seconds behind the first two instances.
since python2 support has now been dropped, this can safely be included
in the package.
Signed-off-by: Chinmay D. Pai <[email protected]>
8e225a9 to
b38173a
Compare
Codecov Report
@@ Coverage Diff @@
## master #350 +/- ##
==========================================
- Coverage 89.32% 89.30% -0.02%
==========================================
Files 13 13
Lines 721 720 -1
==========================================
- Hits 644 643 -1
Misses 77 77
Continue to review full report at Codecov.
|
Contributor
Author
|
this has been rebased with the updated build, I guess it's good to go. |
jpoehnelt
approved these changes
Apr 24, 2020
googlemaps-bot
pushed a commit
that referenced
this pull request
Apr 24, 2020
## [4.2.2](v4.2.1...v4.2.2) (2020-04-24) ### Bug Fixes * use timezone-aware timestamp() instead of timetuple() ([#350](#350)) ([fc69668](fc69668))
Contributor
|
🎉 This PR is included in version 4.2.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Marir19950304
pushed a commit
to Marir19950304/Google_map
that referenced
this pull request
Jan 25, 2022
## [4.2.2](googlemaps/google-maps-services-python@v4.2.1...v4.2.2) (2020-04-24) ### Bug Fixes * use timezone-aware timestamp() instead of timetuple() ([#350](googlemaps/google-maps-services-python#350)) ([fc69668](googlemaps/google-maps-services-python@fc69668))
This file contains hidden or 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
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.
fixes issue where
convert.time()ignores timezone in the datetime object.technically, as @atollena describes, the first two times should be considered to be the same, whereas the third datetime instance is expected be an hour behind the first two instances. but by using
timetuple(), the specified timezone is ignored. so using thetimestamp()method instead oftimetuple()ensures that the specified timezone data is respected:here, the specified timezone data is respected, and as expected the third datetime instance is 3600 seconds behind the first two instances.
since the support for python2.7 has now been dropped, this can safely be included in the package.
Fixes #185