Commits

Mike Fogel committed 31421a9

expanding parse() to cover serialization format

Comments (0)

Files changed (2)

timedelta/helpers.py

     >>> parse("2 days")
     datetime.timedelta(2)
     """
-    # This is the format we sometimes get from Postgres.
-    d = re.match(r'((?P<days>\d+) days? )?(?P<hours>\d+):'
+    # This is the format we get from sometimes Postgres, and from serialization
+    d = re.match(r'((?P<days>\d+) days?,? )?(?P<hours>\d+):'
                  r'(?P<minutes>\d+)(:(?P<seconds>\d+))?',
                  unicode(string))
     if d: 

timedelta/tests.py

         >>> t = TimedeltaFormField()
         >>> t.clean('1 day')
         datetime.timedelta(1)
+        >>> t.clean('1 day, 0:00:00')
+        datetime.timedelta(1)
+        >>> t.clean('5 day, 8:42:42')
+        datetime.timedelta(5, 31362)
         >>> t.clean('1 days')
         datetime.timedelta(1)
         >>> t.clean('1 second')
         Decimal('5')
         >>> decimal_hours(datetime.timedelta(hours=9, minutes=20))
         Decimal('9.333333333333333333333333333')
-        """
+        """