mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
make sure no time skew can interfere with comparison (#3003)
* make sure no time skew can interfere with comparison * import
This commit is contained in:
parent
077e692dbb
commit
604d2d1bd2
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user