Skip to content
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

Fix #403 #1002

Merged
merged 3 commits into from Oct 21, 2022
Merged

Fix #403 #1002

merged 3 commits into from Oct 21, 2022

Conversation

Baviaan
Copy link
Contributor

@Baviaan Baviaan commented Oct 19, 2021

The parse function only works with naive times, so this provides timezone information to compute the offset from utc and provide _correct_for_time_frame with the utc time instead of local time as _correct_for_time_frame checks if the time has passed in utc.

This fixes #403

dateparser/date_parser.py Show resolved Hide resolved
dateparser/parser.py Outdated Show resolved Hide resolved
@Gallaecio
Copy link
Member

Could you please include a test for the fix?

@codecov
Copy link

codecov bot commented Oct 19, 2021

Codecov Report

Merging #1002 (50c3872) into master (8af4f29) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1002   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files         234      234           
  Lines        2694     2697    +3     
=======================================
+ Hits         2648     2651    +3     
  Misses         46       46           
Impacted Files Coverage Δ
dateparser/date_parser.py 93.75% <100.00%> (ø)
dateparser/parser.py 99.01% <100.00%> (+<0.01%) ⬆️

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 8af4f29...50c3872. Read the comment docs.

@Baviaan
Copy link
Contributor Author

Baviaan commented Oct 19, 2021

Thanks for the comments.

  • I have renamed ptz to tz.
  • I passed tz to _correct_for_time_frame to do the shift inside the method. (This looks much better indeed!)
  • I have added two tests that fail on master but pass with these fixes. (One for 'future' and for 'past' prefer_dates_from setting.) I wasn't sure where to put them, they're currently at the bottom of the test_date_parser.py file.

Copy link
Member

@Gallaecio Gallaecio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Returned datetime skips a day with time+timezone input and PREFER_DATES_FROM = 'future'
3 participants