Commits

Mike Fogel  committed 509602b

iso8601_repr: doctest fix & don't rely on dict key order

The doctest was off from what's described on the wikipedia link.
The formatting relied on dictionary key order, which is not gauranteed.

  • Participants
  • Parent commits 760bb35

Comments (0)

Files changed (1)

File timedelta/helpers.py

 
     >>> from datetime import timedelta as td
     >>> iso8601_repr(td(days=1, hours=2, minutes=3, seconds=4))
-    'P1DT2HM3S4'
+    'P1DT2H3M4S'
     """
     years = timedelta.days / 365
     weeks = (timedelta.days % 365) / 7
     minutes = (timedelta.seconds % 3600) / 60
     seconds = timedelta.seconds % 60
 
-    formatting = {'P': {'Y': years,
-                        'W': weeks,
-                        'D': days
-                        },
-                  'T': {'H': hours,
-                        'M': minutes,
-                        'S': seconds
-                        }
-                  }
+    formatting = (
+        ('P', (
+            ('Y', years),
+            ('W', weeks),
+            ('D', days),
+        )),
+        ('T', (
+            ('H', hours),
+            ('M', minutes),
+            ('S', seconds),
+        )),
+      )
 
     result = ''
-    for category, subcats  in formatting.items():
+    for category, subcats in formatting:
         result += category
-        for format, value in subcats.items():
+        for format, value in subcats:
             if value:
                 result += '%d%c' % (value, format)