Bläddra i källkod

HUE-6604 [oozie] Fix timestamp conversion to server timezone

When getting the server timezone offset, earlier Hue ignored the case
where it could be '-XXXX'. New approach handles this in a more generic way.
krish 8 år sedan
förälder
incheckning
46fb1416a7
2 ändrade filer med 4 tillägg och 5 borttagningar
  1. 2 2
      apps/oozie/src/oozie/tests.py
  2. 2 3
      apps/oozie/src/oozie/utils.py

+ 2 - 2
apps/oozie/src/oozie/tests.py

@@ -3847,11 +3847,11 @@ class TestUtils(OozieMockBase):
     assert_equal(convert_to_server_timezone('2015-07-01T10:10', local_tz='Europe/Paris', server_tz='UTC', user='test'), u'2015-07-01T08:10Z')
     # To GMT(+/-)####
     assert_equal(convert_to_server_timezone('2015-07-01T10:10', local_tz='Asia/Jayapura', server_tz='GMT+0800', user='test'), u'2015-07-01T09:10+0800')
-    assert_equal(convert_to_server_timezone('2015-07-01T10:10', local_tz='Australia/LHI', server_tz='GMT-0530', user='test'), u'2015-06-30T18:10+0530')
+    assert_equal(convert_to_server_timezone('2015-07-01T10:10', local_tz='Australia/LHI', server_tz='GMT-0530', user='test'), u'2015-06-30T18:10-0530')
     # Previously created coordinators might have 'Z' appended, we consider them as UTC local time
     assert_equal(convert_to_server_timezone('2015-07-01T10:10Z', local_tz='America/Los_Angeles', server_tz='UTC', user='test'), u'2015-07-01T10:10Z')
     assert_equal(convert_to_server_timezone('2015-07-01T10:10Z', local_tz='Asia/Jayapura', server_tz='GMT+0800', user='test'), u'2015-07-01T18:10+0800')
-    assert_equal(convert_to_server_timezone('2015-07-01T10:10Z', local_tz='Australia/LHI', server_tz='GMT-0530', user='test'), u'2015-07-01T04:40+0530')
+    assert_equal(convert_to_server_timezone('2015-07-01T10:10Z', local_tz='Australia/LHI', server_tz='GMT-0530', user='test'), u'2015-07-01T04:40-0530')
 
 
 # Utils

+ 2 - 3
apps/oozie/src/oozie/utils.py

@@ -192,12 +192,11 @@ def convert_to_server_timezone(date, local_tz='UTC', server_tz=None, user=DEFAUL
     date_local_tz = date_local_tz.replace(tzinfo=tz.gettz(local_tz))
     date_server_tz = date_local_tz.astimezone(tz.gettz(server_tz))
 
-    date_server_tz = date_server_tz.strftime('%Y-%m-%dT%H:%M')
     # Oozie timezone is either UTC or GMT(+/-)####
     if 'UTC' == server_tz:
-      return date_server_tz + u'Z'
+      return date_server_tz.strftime('%Y-%m-%dT%H:%M') + u'Z'
     else:
-      return date_server_tz + u'+' + re.split('[+-]', server_tz)[1]
+      return date_server_tz.strftime('%Y-%m-%dT%H:%M') + date_server_tz.strftime('%z')
   except TypeError, ValueError:
     LOG.error("Failed to convert Oozie timestamp: %s" % date)
   return None