瀏覽代碼

Handle the 'Z' time zone designator in ISO 8601 time stamps

Sending a task message with an eta value using the Z time zone designator currently results in an error such as:

InvalidTaskError: invalid eta value '2014-02-09T02:17:06.007Z': tzinfo argument must be None or of a tzinfo subclass, not type 'str'
Martin Davidsson 11 年之前
父節點
當前提交
63085251af
共有 2 個文件被更改,包括 6 次插入1 次删除
  1. 3 0
      celery/tests/utils/test_timeutils.py
  2. 3 1
      celery/utils/iso8601.py

+ 3 - 0
celery/tests/utils/test_timeutils.py

@@ -66,6 +66,9 @@ class test_iso8601(Case):
         iso2 = iso.replace('+00:00', '+01:00')
         d2 = parse_iso8601(iso2)
         self.assertEqual(d2.tzinfo._minutes, +60)
+        iso3 = iso.replace('+00:00', 'Z')
+        d3 = parse_iso8601(iso3)
+        self.assertEqual(d3.tzinfo, pytz.UTC)
 
 
 class test_timeutils(Case):

+ 3 - 1
celery/utils/iso8601.py

@@ -59,7 +59,9 @@ def parse_iso8601(datestring):
         raise ValueError('unable to parse date string %r' % datestring)
     groups = m.groupdict()
     tz = groups['timezone']
-    if tz and tz != 'Z':
+    if tz == 'Z':
+      tz = FixedOffset(0)
+    elif tz:
         m = TIMEZONE_REGEX.match(tz)
         prefix, hours, minutes = m.groups()
         hours, minutes = int(hours), int(minutes)