这是indexloc提供的服务,不要输入任何密码
Skip to content

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

Merged
merged 1 commit into from
Apr 24, 2020

Conversation

Thunderbottom
Copy link
Contributor

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 data 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 the support for python2.7 has now been dropped, this can safely be included in the package.

Fixes #185

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 14, 2020
@jpoehnelt
Copy link
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 <chinmaydpai@gmail.com>
@codecov
Copy link

codecov bot commented Mar 24, 2020

Codecov Report

Merging #350 into master will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
googlemaps/convert.py 96.66% <100.00%> (-0.03%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c5bec1...b38173a. Read the comment docs.

@Thunderbottom
Copy link
Contributor Author

Thunderbottom commented Apr 24, 2020

this has been rebased with the updated build, I guess it's good to go.

@jpoehnelt jpoehnelt merged commit fc69668 into googlemaps:master 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))
@googlemaps-bot
Copy link
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement. released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timezones are ignored when converting datetimes
4 participants