def getPyValueFromNode(self, node): try: node = self._getElementbyChildNamesList(node, self._subElementNames, createMissingNodes=False) if node is not None: date_string = node.text return isoduration.parse_date_time(date_string) except ElementNotFoundException: return None
def test_parse_date_time(self): self.assertEqual(parse_date_time('2015-05-25'), date(2015, 5, 25)) self.assertEqual(parse_date_time('20150525'), date(2015, 5, 25)) self.assertEqual(parse_date_time('2015-05-25T14:45:00'), datetime(2015, 5, 25, 14, 45, 00)) self.assertEqual(parse_date_time('2015-05-25 14:45:00', strict=False), datetime(2015, 5, 25, 14, 45, 00)) self.assertEqual(parse_date_time('2015-05-25 14:45:00'), date(2015, 5, 25)) result = parse_date_time('2015-05-25T14:45:00+01:00') self.assertEqual(result.hour, 14) self.assertEqual(result.tzinfo.utcoffset(0).seconds, 3600) self.assertEqual(parse_date_time('2015-05'), GYearMonth(2015, 5)) self.assertEqual(parse_date_time('2015'), GYear(2015))
def mk_value_object(date_string): return isoduration.parse_date_time(date_string)