Пример #1
0
 def toPy(xmlValue):
     if xmlValue is None:
         return None
     return isoduration.parse_duration(xmlValue)
Пример #2
0
 def test_parseDuration(self):
     self.assertEqual(parse_duration('P0Y0M0DT0H0M1S'), 1)
     self.assertEqual(parse_duration('P0Y0M0DT0H1M0S'), 60)
     self.assertEqual(parse_duration('P0Y0M0DT0H1M1S'), 61)
     self.assertEqual(parse_duration('P0Y0M0DT0H1M61S'), 121)
     self.assertEqual(parse_duration('P0Y0M3DT5H13M17S'),
                      3600 * 24 * 3 + 3600 * 5 + 60 * 13 + 17)
     self.assertEqual(parse_duration('-P0Y0M3DT5H13M17S'),
                      (3600 * 24 * 3 + 3600 * 5 + 60 * 13 + 17) * -1)
     self.assertEqual(parse_duration('P0Y0M0DT0H0M0.1S'), 0.1)
     # some shorter representations:
     self.assertEqual(parse_duration('PT0H0M1S'), 1)
     self.assertEqual(parse_duration('PT1S'), 1)
     self.assertEqual(parse_duration('PT1M'), 60)
     self.assertEqual(parse_duration('P0DT1M1S'), 61)
     self.assertEqual(parse_duration('P3DT5H13M17S'),
                      3600 * 24 * 3 + 3600 * 5 + 60 * 13 + 17)
     self.assertEqual(parse_duration('P3D'), 3600 * 24 * 3)