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 custom-formats with timezone #840

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

noviluni
Copy link
Collaborator

@noviluni noviluni commented Nov 23, 2020

Fix ValueError when parsing a date string that already contains timezone info with the custom-formats parser.

fixes: #376, closes: #375

@noviluni noviluni force-pushed the fix_custom_formats_with_timezone branch from e9359fe to b3ab812 Compare November 23, 2020 09:35
@codecov
Copy link

codecov bot commented Nov 23, 2020

Codecov Report

Merging #840 (b3ab812) into master (939e722) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #840   +/-   ##
=======================================
  Coverage   98.33%   98.34%           
=======================================
  Files         231      231           
  Lines        2590     2594    +4     
=======================================
+ Hits         2547     2551    +4     
  Misses         43       43           
Impacted Files Coverage Δ
dateparser/utils/__init__.py 96.18% <100.00%> (+0.12%) ⬆️

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 939e722...b3ab812. Read the comment docs.

Comment on lines +142 to +146
if (
not settings.RETURN_AS_TIMEZONE_AWARE
or (settings.RETURN_AS_TIMEZONE_AWARE
and 'default' == settings.RETURN_AS_TIMEZONE_AWARE and not is_originally_aware)
):
Copy link
Member

Choose a reason for hiding this comment

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

💄

Suggested change
if (
not settings.RETURN_AS_TIMEZONE_AWARE
or (settings.RETURN_AS_TIMEZONE_AWARE
and 'default' == settings.RETURN_AS_TIMEZONE_AWARE and not is_originally_aware)
):
if (
not settings.RETURN_AS_TIMEZONE_AWARE
or (
not is_originally_aware
and settings.RETURN_AS_TIMEZONE_AWARE == 'default'
)
):

@@ -235,3 +242,15 @@ def setup_logging():
},
}
logging.config.dictConfig(config)


def is_aware(date_obj):
Copy link
Member

Choose a reason for hiding this comment

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

💄 is_tz_aware or has_tz?

self.then_date_was_parsed()
self.then_parsed_period_is('day')
self.then_parsed_date_is(expected_result)

Copy link
Member

Choose a reason for hiding this comment

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

Are these tests complete enough?

Given the changes I would expect a test where the date contains a timezone, settings specify a different timezone, and we check that the parsed timezone is the one from the input string, and not the one from the settings.

Also a test about the change to if settings.RETURN_AS_TIMEZONE_AWARE is not True:.

@noviluni noviluni added this to the 1.1.0 milestone Nov 25, 2020
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.

Unable to use date_formats argument if timezone already found Unable to parse date with UTC offset
2 participants