use of java.time.chrono.ChronoZonedDateTime in project jdk8u_jdk by JetBrains.
the class TestFormatter method test.
@Test(dataProvider = "calendarsByLocale")
public void test(String calendarLocale) {
failure = 0;
int N = 12;
//locales = Locale.getAvailableLocales();
Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.FRENCH, Locale.JAPANESE, Locale.CHINESE };
Random r = new Random();
Locale calLocale = Locale.forLanguageTag(calendarLocale);
Chronology chrono = Chronology.ofLocale(calLocale);
ChronoLocalDate now = chrono.dateNow();
ChronoLocalDateTime<?> ldt0 = now.atTime(LocalTime.now());
ChronoZonedDateTime<?> zdt0 = ldt0.atZone(ZoneId.systemDefault());
ChronoZonedDateTime<?>[] zdts = new ChronoZonedDateTime<?>[] { zdt0, zdt0.withZoneSameLocal(ZoneId.of("UTC")), zdt0.withZoneSameLocal(ZoneId.of("GMT")), zdt0.withZoneSameLocal(ZoneId.of("UT")) };
while (N-- > 0) {
for (ChronoZonedDateTime<?> zdt : zdts) {
zdt = zdt.with(ChronoField.DAY_OF_YEAR, (r.nextInt(365) + 1)).with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
Instant instant = zdt.toInstant();
Calendar cal = Calendar.getInstance(calLocale);
cal.setTimeInMillis(instant.toEpochMilli());
cal.setTimeZone(TimeZone.getTimeZone(zdt.getZone()));
for (Locale locale : locales) {
for (String fmtStr : fmtStrDate) {
testDate(fmtStr, locale, zdt, cal);
}
for (String fmtStr : fmtStrTime) {
testTime(fmtStr, locale, zdt, cal);
}
testZoneId(locale, zdt, cal);
testInstant(locale, instant, zdt, cal);
}
}
}
if (verbose) {
if (failure != 0) {
System.out.println("Total " + failure + "/" + total + " tests failed");
} else {
System.out.println("All tests (" + total + ") PASSED");
}
}
assertEquals(failure, 0);
}
use of java.time.chrono.ChronoZonedDateTime in project jdk8u_jdk by JetBrains.
the class TestFormatter method testInstant.
private void testInstant(Locale locale, Instant instant, ChronoZonedDateTime<?> zdt, Calendar cal) {
String fmtStr = "s:[%ts] s:[%1$Ts] Q:[%1$tQ] Q:[%1$TQ]";
printFmtStr(locale, fmtStr);
String expected = test(fmtStr, locale, null, cal);
test(fmtStr, locale, expected, instant);
test(fmtStr, locale, expected, zdt);
if (zdt instanceof ZonedDateTime) {
OffsetDateTime odt = ((ZonedDateTime) zdt).toOffsetDateTime();
test(fmtStr, locale, expected, odt);
}
}
use of java.time.chrono.ChronoZonedDateTime in project jdk8u_jdk by JetBrains.
the class TestFormatter method testZoneId.
private void testZoneId(Locale locale, ChronoZonedDateTime<?> zdt, Calendar cal) {
String fmtStr = "z:[%tz] z:[%1$Tz] Z:[%1$tZ] Z:[%1$TZ]";
printFmtStr(locale, fmtStr);
String expected = toZoneIdStr(test(fmtStr, locale, null, cal));
test(fmtStr, locale, expected, zdt);
// get a new cal with fixed tz
Calendar cal0 = Calendar.getInstance();
cal0.setTimeInMillis(zdt.toInstant().toEpochMilli());
cal0.setTimeZone(TimeZone.getTimeZone("GMT" + zdt.getOffset().getId()));
expected = toZoneOffsetStr(test(fmtStr, locale, null, cal0));
if (zdt instanceof ZonedDateTime) {
OffsetDateTime odt = ((ZonedDateTime) zdt).toOffsetDateTime();
test(fmtStr, locale, expected, odt);
test(fmtStr, locale, expected, odt.toOffsetTime());
}
// datetime + zid
fmtStr = "c:[%tc] c:[%1$Tc]";
printFmtStr(locale, fmtStr);
expected = toZoneIdStr(test(fmtStr, locale, null, cal));
test(fmtStr, locale, expected, zdt);
}
use of java.time.chrono.ChronoZonedDateTime in project jdk8u_jdk by JetBrains.
the class TCKChronoZonedDateTime method test_zonedDateTime_comparisons.
//-----------------------------------------------------------------------
// isBefore, isAfter, isEqual, timeLineOrder() test a Chronology against the other Chronos
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_zonedDateTime_comparisons(Chronology chrono) {
List<ChronoZonedDateTime<?>> dates = new ArrayList<>();
ChronoZonedDateTime<?> date = chrono.date(LocalDate.of(2013, 1, 1)).atTime(LocalTime.MIN).atZone(ZoneOffset.UTC);
// Insert dates in order, no duplicates
dates.add(date.minus(1, ChronoUnit.YEARS));
dates.add(date.minus(1, ChronoUnit.MONTHS));
dates.add(date.minus(1, ChronoUnit.WEEKS));
dates.add(date.minus(1, ChronoUnit.DAYS));
dates.add(date.minus(1, ChronoUnit.HOURS));
dates.add(date.minus(1, ChronoUnit.MINUTES));
dates.add(date.minus(1, ChronoUnit.SECONDS));
dates.add(date.minus(1, ChronoUnit.NANOS));
dates.add(date);
dates.add(date.plus(1, ChronoUnit.NANOS));
dates.add(date.plus(1, ChronoUnit.SECONDS));
dates.add(date.plus(1, ChronoUnit.MINUTES));
dates.add(date.plus(1, ChronoUnit.HOURS));
dates.add(date.plus(1, ChronoUnit.DAYS));
dates.add(date.plus(1, ChronoUnit.WEEKS));
dates.add(date.plus(1, ChronoUnit.MONTHS));
dates.add(date.plus(1, ChronoUnit.YEARS));
// Check these dates against the corresponding dates for every calendar
for (Chronology[] clist : data_of_calendars()) {
List<ChronoZonedDateTime<?>> otherDates = new ArrayList<>();
//clist[0];
Chronology chrono2 = IsoChronology.INSTANCE;
for (ChronoZonedDateTime<?> d : dates) {
otherDates.add(chrono2.date(d).atTime(d.toLocalTime()).atZone(d.getZone()));
}
// Now compare the sequence of original dates with the sequence of converted dates
for (int i = 0; i < dates.size(); i++) {
ChronoZonedDateTime<?> a = dates.get(i);
for (int j = 0; j < otherDates.size(); j++) {
ChronoZonedDateTime<?> b = otherDates.get(j);
int cmp = ChronoZonedDateTime.timeLineOrder().compare(a, b);
if (i < j) {
assertTrue(cmp < 0, a + " compare " + b);
assertEquals(a.isBefore(b), true, a + " isBefore " + b);
assertEquals(a.isAfter(b), false, a + " ifAfter " + b);
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
} else if (i > j) {
assertTrue(cmp > 0, a + " compare " + b);
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
assertEquals(a.isAfter(b), true, a + " ifAfter " + b);
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
} else {
assertTrue(cmp == 0, a + " compare " + b);
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
assertEquals(a.isAfter(b), false, a + " ifAfter " + b);
assertEquals(a.isEqual(b), true, a + " isEqual " + b);
}
}
}
}
}
use of java.time.chrono.ChronoZonedDateTime in project jdk8u_jdk by JetBrains.
the class TCKChronoZonedDateTime method test_from_TemporalAccessor.
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_from_TemporalAccessor(Chronology chrono) {
ZonedDateTime refDateTime = ZonedDateTime.of(2013, 1, 1, 12, 30, 0, 0, ZoneId.of("Europe/Paris"));
ChronoZonedDateTime<?> dateTime = chrono.zonedDateTime(refDateTime);
ChronoZonedDateTime<?> test1 = ChronoZonedDateTime.from(dateTime);
assertEquals(test1, dateTime);
}
Aggregations