def date_resolver(property, value, language, **kwargs): """ Resolves dates """ value = value.lower().replace('(circa)', '').replace('(probable)', '') \ .replace('(presumed)', '').replace('c.', '').strip() if not value: return '' try: res = datetime.parse(value) return format_date(res.get('year'), res.get('month'), res.get('day')) except ValueError: logger.debug('cannot parse date ' + value) return ''
def test_fallbacks(self): self.assertEqual(datetime.parse('b.c. 123'), {'year': -123, 'day': None, 'month': None}) self.assertEqual(datetime.parse('123Bc'), {'year': -123, 'day': None, 'month': None})
def test_simply_year(self): self.assertEqual(datetime.parse('1863'), {'year': 1863, 'month': None, 'day': None})
def test_simple_date(self): self.assertEqual(datetime.parse('24/2/2016'), {'year': 2016, 'month': 2, 'day': 24})