Skip to content

Commit

Permalink
Merge pull request #200 from cshowe/case_insensitive_month_match
Browse files Browse the repository at this point in the history
Case insensitive month match. Thanks @cshowe
  • Loading branch information
andrewelkins committed Feb 26, 2015
2 parents 0f8535b + b548972 commit 59a22a3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
7 changes: 4 additions & 3 deletions arrow/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class DateTimeParser(object):
_INPUT_RE_MAP = {
'YYYY': _FOUR_DIGIT_RE,
'YY': _TWO_DIGIT_RE,
'MMMM': re.compile('({0})'.format('|'.join(calendar.month_name[1:]))),
'MMM': re.compile('({0})'.format('|'.join(calendar.month_abbr[1:]))),
'MMMM': re.compile('({0})'.format('|'.join(calendar.month_name[1:])), re.IGNORECASE),
'MMM': re.compile('({0})'.format('|'.join(calendar.month_abbr[1:])), re.IGNORECASE),
'MM': _TWO_DIGIT_RE,
'M': _ONE_OR_TWO_DIGIT_RE,
'DD': _TWO_DIGIT_RE,
Expand Down Expand Up @@ -164,7 +164,8 @@ def _parse_token(self, token, value, parts):
parts['year'] = 1900 + value if value > 68 else 2000 + value

elif token in ['MMMM', 'MMM']:
parts['month'] = self.locale.month_number(value)
parts['month'] = self.locale.month_number(value.capitalize())

elif token in ['MM', 'M']:
parts['month'] = int(value)

Expand Down
50 changes: 50 additions & 0 deletions tests/parser_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,53 @@ def test_parse_fails(self):

with assertRaises(parser.ParserError):
self.parser.parse('fail')


class DateTimeParserMonthNameTests(Chai):

def setUp(self):
super(DateTimeParserMonthNameTests, self).setUp()

self.parser = parser.DateTimeParser('en_us')

def test_shortmonth_capitalized(self):

assertEqual(
self.parser.parse('2013-Jan-01', 'YYYY-MMM-DD'),
datetime(2013, 1, 1)
)

def test_shortmonth_allupper(self):

assertEqual(
self.parser.parse('2013-JAN-01', 'YYYY-MMM-DD'),
datetime(2013, 1, 1)
)

def test_shortmonth_alllower(self):

assertEqual(
self.parser.parse('2013-jan-01', 'YYYY-MMM-DD'),
datetime(2013, 1, 1)
)

def test_month_capitalized(self):

assertEqual(
self.parser.parse('2013-January-01', 'YYYY-MMMM-DD'),
datetime(2013, 1, 1)
)

def test_month_allupper(self):

assertEqual(
self.parser.parse('2013-JANUARY-01', 'YYYY-MMMM-DD'),
datetime(2013, 1, 1)
)

def test_month_alllower(self):

assertEqual(
self.parser.parse('2013-january-01', 'YYYY-MMMM-DD'),
datetime(2013, 1, 1)
)

0 comments on commit 59a22a3

Please sign in to comment.