-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: use timezone-aware timestamp() instead of timetuple() #350
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
Conversation
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 <chinmaydpai@gmail.com>
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.
|
this has been rebased with the updated build, I guess it's good to go. |
## [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))
🎉 This PR is included in version 4.2.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
## [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))
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