You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2018/02/28 11:28:11 UTC

[GitHub] DaanHoogland closed pull request #2392: dateutil: constistency of tzdate input and output

DaanHoogland closed pull request #2392: dateutil: constistency of tzdate input and output
URL: https://github.com/apache/cloudstack/pull/2392
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/utils/src/main/java/com/cloud/utils/DateUtil.java b/utils/src/main/java/com/cloud/utils/DateUtil.java
index 7787e1be3ba..9f046d11446 100644
--- a/utils/src/main/java/com/cloud/utils/DateUtil.java
+++ b/utils/src/main/java/com/cloud/utils/DateUtil.java
@@ -38,10 +38,14 @@ public static Date currentGMTTime() {
         return new Date();
     }
 
-    // yyyy-MM-ddTHH:mm:ssZxxxx
+    // yyyy-MM-ddTHH:mm:ssZZZZ or yyyy-MM-ddTHH:mm:ssZxxxx
     public static Date parseTZDateString(String str) throws ParseException {
-        DateFormat dfParse = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'Z");
-        return dfParse.parse(str);
+        try {
+            return s_outputFormat.parse(str);
+        } catch (ParseException e) {
+            final DateFormat dfParse = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'Z");
+            return dfParse.parse(str);
+        }
     }
 
     public static Date parseDateString(TimeZone tz, String dateString) {
diff --git a/utils/src/test/java/com/cloud/utils/DateUtilTest.java b/utils/src/test/java/com/cloud/utils/DateUtilTest.java
index ba88505f04d..190adeab2db 100644
--- a/utils/src/test/java/com/cloud/utils/DateUtilTest.java
+++ b/utils/src/test/java/com/cloud/utils/DateUtilTest.java
@@ -27,6 +27,9 @@
 
 import com.cloud.utils.DateUtil.IntervalType;
 
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
 
 public class DateUtilTest {
 
@@ -44,17 +47,25 @@ public static void main(String[] args) {
         if (args.length == 2) {
             System.out.println("Next run time: " + DateUtil.getNextRunTime(IntervalType.getIntervalType(args[0]), args[1], "GMT", time).toString());
         }
+    }
 
-        time = new Date();
+    @Test
+    public void zonedTimeFormatLegacy() throws ParseException {
+        Date time = new Date();
         DateFormat dfDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'Z");
         String str = dfDate.format(time);
-        System.out.println("Formated TZ time string : " + str);
-        try {
-            Date dtParsed = DateUtil.parseTZDateString(str);
-            System.out.println("Parsed TZ time string : " + dtParsed.toString());
-        } catch (ParseException e) {
-            System.err.println("Parsing failed\n string : " + str + "\nexception :" + e.getLocalizedMessage());
-        }
+        Date dtParsed = DateUtil.parseTZDateString(str);
+
+        assertEquals(time.toString(), dtParsed.toString());
     }
 
+    @Test
+    public void zonedTimeFormat() throws ParseException {
+        Date time = new Date();
+        DateFormat dfDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+        String str = dfDate.format(time);
+        Date dtParsed = DateUtil.parseTZDateString(str);
+
+        assertEquals(time.toString(), dtParsed.toString());
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services