You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ra...@apache.org on 2018/11/07 12:04:55 UTC
[cloudstack] branch master updated: make sure no time skew can
interfere with comparison (#3003)
This is an automated email from the ASF dual-hosted git repository.
rafael pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/master by this push:
new 604d2d1 make sure no time skew can interfere with comparison (#3003)
604d2d1 is described below
commit 604d2d1bd2f183482ee66731eb0ae8cd6e55cfc8
Author: dahn <da...@gmail.com>
AuthorDate: Wed Nov 7 12:04:40 2018 +0000
make sure no time skew can interfere with comparison (#3003)
* make sure no time skew can interfere with comparison
* import
---
.../test/java/com/cloud/utils/DateUtilTest.java | 28 +++++++++++++---------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/utils/src/test/java/com/cloud/utils/DateUtilTest.java b/utils/src/test/java/com/cloud/utils/DateUtilTest.java
index 428666f..98b4d11 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 @@ package com.cloud.utils;
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 class DateUtilTest {
@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 class DateUtilTest {
@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 class DateUtilTest {
@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 class DateUtilTest {
@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 class DateUtilTest {
@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);