rafaelweingartner closed pull request #3003: make sure no time skew can 
interfere with comparison
URL: https://github.com/apache/cloudstack/pull/3003
 
 
   

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/test/java/com/cloud/utils/DateUtilTest.java 
b/utils/src/test/java/com/cloud/utils/DateUtilTest.java
index 428666f0736..98b4d11c9d7 100644
--- a/utils/src/test/java/com/cloud/utils/DateUtilTest.java
+++ b/utils/src/test/java/com/cloud/utils/DateUtilTest.java
@@ -21,13 +21,14 @@
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.ZoneId;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.TimeZone;
 
 import java.time.format.DateTimeFormatter;
 import java.time.OffsetDateTime;
-import java.time.ZoneOffset;
 
 import com.cloud.utils.DateUtil.IntervalType;
 
@@ -74,8 +75,9 @@ public void zonedTimeFormat() throws ParseException {
 
     @Test
     public void zonedTimeFormatIsoOffsetDateTime() throws ParseException {
-        Date time = new Date();
-        String str = 
OffsetDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
+        Instant moment = Instant.now();
+        Date time = Date.from(moment);
+        String str = OffsetDateTime.ofInstant(moment, 
ZoneId.systemDefault()).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
 
         Date dtParsed = DateUtil.parseTZDateString(str);
 
@@ -84,8 +86,9 @@ public void zonedTimeFormatIsoOffsetDateTime() throws 
ParseException {
 
     @Test
     public void zonedTimeFormatIsoInstant() throws ParseException {
-        Date time = new Date();
-        String str = 
OffsetDateTime.now().format(DateTimeFormatter.ISO_INSTANT);
+        Instant moment = Instant.now();
+        Date time = Date.from(moment);
+        String str = OffsetDateTime.ofInstant(moment, 
ZoneId.systemDefault()).format(DateTimeFormatter.ISO_INSTANT);
 
         Date dtParsed = DateUtil.parseTZDateString(str);
 
@@ -94,9 +97,10 @@ public void zonedTimeFormatIsoInstant() throws 
ParseException {
 
     @Test
     public void zonedTimeFormatIsoOffsetDateTimeMs() throws ParseException {
-        Date time = new Date();
+        Instant moment = Instant.now();
+        Date time = Date.from(moment);
         DateTimeFormatter formatter = 
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSX");
-        String str = OffsetDateTime.now().format(formatter);
+        String str = OffsetDateTime.ofInstant(moment, 
ZoneId.systemDefault()).format(formatter);
 
         Date dtParsed = DateUtil.parseTZDateString(str);
 
@@ -105,9 +109,10 @@ public void zonedTimeFormatIsoOffsetDateTimeMs() throws 
ParseException {
 
     @Test
     public void zonedTimeFormatIsoInstantMs() throws ParseException {
-        Date time = new Date();
+        Instant moment = Instant.now();
+        Date time = Date.from(moment);
         DateTimeFormatter formatter = 
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
-        String str = OffsetDateTime.now(ZoneOffset.UTC).format(formatter);
+        String str = OffsetDateTime.ofInstant(moment, 
ZoneId.of("UTC")).format(formatter);
 
         Date dtParsed = DateUtil.parseTZDateString(str);
 
@@ -116,9 +121,10 @@ public void zonedTimeFormatIsoInstantMs() throws 
ParseException {
 
     @Test
     public void zonedTimeFormatIsoNoColonZMs() throws ParseException {
-        Date time = new Date();
+        Instant moment = Instant.now();
+        Date time = Date.from(moment);
         DateTimeFormatter formatter = 
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ");
-        String str = OffsetDateTime.now().format(formatter);
+        String str = OffsetDateTime.ofInstant(moment, 
ZoneId.systemDefault()).format(formatter);
 
         Date dtParsed = DateUtil.parseTZDateString(str);
 


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to