Skip to content

Commit

Permalink
Fix bug in date parsing #154
Browse files Browse the repository at this point in the history
We were using two default dates during date parsing, but one of them
had a month of 02 (February). When parsing a date that is just a day
of the month, like "30", the Python datetime library would throw an
exception against the default date, because there's no day 30 in
February.
  • Loading branch information
davidmegginson committed May 11, 2018
1 parent 11b94e7 commit c7d23ac
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2018-05-11 Release 4.7.1
- hotfix for bug in date parsing

2018-04-30 Release 4.7
- remove obsolete Python2 compatibility code
- added source_row_number and source_column_number to support validation
Expand Down
2 changes: 1 addition & 1 deletion hxl/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

DEFAULT_DATE_1 = datetime.date(2015, 1, 1)

DEFAULT_DATE_2 = datetime.date(2016, 2, 2)
DEFAULT_DATE_2 = datetime.date(2016, 3, 3)

def normalise(s, col=None):
"""Intelligently normalise a value, optionally using the HXL hashtag for hints"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
raise RuntimeError("libhxl requires Python 3 or higher")

setup(name='libhxl',
version='4.7',
version='4.7.1',
description='Python support for the Humanitarian Exchange Language (HXL).',
author='David Megginson',
author_email='[email protected]',
Expand Down
3 changes: 3 additions & 0 deletions tests/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ def test_normalise_other_date(self):
self.assertEqual('2008-01-20', hxl.datatypes.normalise_date('01-20-2008'))
self.assertEqual('2008-01-20', hxl.datatypes.normalise_date('20-01-2008'))
self.assertEqual('2008-01', hxl.datatypes.normalise_date('Jan 2008'))

# test no exception
hxl.datatypes.normalise_date('30')

0 comments on commit c7d23ac

Please sign in to comment.