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

bug fix and possible fix for #11 #18

Merged
merged 7 commits into from Feb 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions dateparser/date.py
Expand Up @@ -165,7 +165,7 @@ def _try_dateutil_parser(self):
try:
date_obj = date_parser.parse(self._get_translated_date())
return {
'date_obj': date_obj.replace(tzinfo=None),
'date_obj': date_obj,
'period': 'day',
}
except ValueError:
Expand All @@ -175,7 +175,11 @@ def _try_given_formats(self):
if not self.date_formats:
return

return parse_with_formats(self._get_translated_date_with_formatting(), self.date_formats)
date_formats = self.date_formats
if not isinstance(self.date_formats, (list, tuple, collections.Set)):
date_formats = [self.date_formats]

return parse_with_formats(self._get_translated_date_with_formatting(), date_formats)

def _try_hardcoded_formats(self):
hardcoded_date_formats = [
Expand Down
5 changes: 5 additions & 0 deletions tests/test_date.py
Expand Up @@ -276,6 +276,11 @@ def test_should_enable_redetection_for_multiple_languages(self):
date_data = parser.get_date_data(date_string)
self.assertEqual(correct_date.date(), date_data['date_obj'].date())

def test_get_date_data_should_not_strip_timezone_info(self):
date_string_with_tz_info = '2014-10-09T17:57:39+00:00'
date_data = self.parser.get_date_data(date_string_with_tz_info)
self.assertTrue(hasattr(date_data['date_obj'], 'tzinfo'))

def test_should_parse_date_with_timezones_using_format(self):
date_string = "2014/11/17 14:56 EDT"
date_format = "%Y/%m/%d %H:%M EDT"
Expand Down