Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreystarr committed Jan 31, 2014
2 parents 9dc3e05 + bf34f32 commit 5db408c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dateinfer/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ examples:
- 6/3/85
...
---
name: Little Endian
format: "%d/%m/%Y"
examples:
- 13/1/2012
...
---
name: MLA (dd mmm yyyy)
format: "%d %B %Y"
examples:
Expand Down
3 changes: 3 additions & 0 deletions dateinfer/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
If(Contains(MonthNum, MonthTextShort), Swap(MonthNum, DayOfMonth)),
If(Sequence(MonthNum, '.', Hour12), SwapSequence([MonthNum, '.', Hour12], [MonthNum, KeepOriginal, DayOfMonth])),
If(Sequence(MonthNum, '.', Hour24), SwapSequence([MonthNum, '.', Hour24], [MonthNum, KeepOriginal, DayOfMonth])),
If(Sequence(Hour12, '.', MonthNum), SwapSequence([Hour24, '.', MonthNum], [DayOfMonth, KeepOriginal, MonthNum])),
If(Sequence(Hour24, '.', MonthNum), SwapSequence([Hour24, '.', MonthNum], [DayOfMonth, KeepOriginal, MonthNum])),
If(Duplicate(MonthNum), Swap(MonthNum, DayOfMonth)),
If(Sequence(F('+'), Year4), SwapSequence([F('+'), Year4], [UTCOffset, None])),
If(Sequence(F('-'), Year4), SwapSequence([F('+'), Year4], [UTCOffset, None]))
]
Expand Down
14 changes: 14 additions & 0 deletions dateinfer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ def testFormat(self):
return test_case


class TestAmbiguousDateCases(unittest.TestCase):
"""
TestCase for tests which results are ambiguous but can be assumed to fall in a small set of possibilities.
"""
def testAmbg1(self):
self.assertIn(infer.infer(['1/1/2012']), ['%m/%d/%Y', '%d/%m/%Y'])

def testAmbg2(self):
# Note: as described in Issue #5 (https://github.com/jeffreystarr/dateinfer/issues/5), the result
# should be %d/%m/%Y as the more likely choice. However, at this point, we will allow %m/%d/%Y.
self.assertIn(infer.infer(['04/12/2012', '05/12/2012', '06/12/2012', '07/12/2012']),
['%d/%m/%Y', '%m/%d/%Y'])


class TestMode(unittest.TestCase):
def testMode(self):
self.assertEqual(5, infer._mode([1, 3, 4, 5, 6, 5, 2, 5, 3]))
Expand Down

0 comments on commit 5db408c

Please sign in to comment.