use of java.time.chrono.ChronoLocalDateTime in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDateTime method test_from_TemporalAccessor.
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_from_TemporalAccessor(Chronology chrono) {
LocalDateTime refDateTime = LocalDateTime.of(2013, 1, 1, 12, 30);
ChronoLocalDateTime<?> dateTime = chrono.localDateTime(refDateTime);
ChronoLocalDateTime<?> test1 = ChronoLocalDateTime.from(dateTime);
assertEquals(test1, dateTime);
ChronoLocalDateTime<?> test2 = ChronoLocalDateTime.from(dateTime.atZone(ZoneOffset.UTC));
assertEquals(test2, dateTime);
}
use of java.time.chrono.ChronoLocalDateTime in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDateTimeSerialization method test_ChronoLocalDateTimeSerialization.
//-----------------------------------------------------------------------
// Test Serialization of ChronoLocalDateTime
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_ChronoLocalDateTimeSerialization(Chronology chrono) throws Exception {
LocalDateTime ref = LocalDate.of(2013, 1, 5).atTime(12, 1, 2, 3);
ChronoLocalDateTime<?> original = chrono.date(ref).atTime(ref.toLocalTime());
assertSerializable(original);
}
use of java.time.chrono.ChronoLocalDateTime in project jdk8u_jdk by JetBrains.
the class TestChronoLocalDate method test_date_checkGenerics_chronoLocalDateTime1.
public void test_date_checkGenerics_chronoLocalDateTime1() {
LocalDateTime now = LocalDateTime.now();
Chronology chrono = ThaiBuddhistChronology.INSTANCE;
ChronoLocalDateTime<?> ldt = chrono.localDateTime(now);
ldt = processCLDT(ldt);
}
use of java.time.chrono.ChronoLocalDateTime in project jdk8u_jdk by JetBrains.
the class TestChronoLocalDate method test_date_checkGenerics_chronoLocalDateTime2.
public void test_date_checkGenerics_chronoLocalDateTime2() {
LocalDateTime now = LocalDateTime.now();
Chronology chrono = ThaiBuddhistChronology.INSTANCE;
ChronoLocalDateTime<? extends ChronoLocalDate> ldt = chrono.localDateTime(now);
ldt = processCLDT(ldt);
}
use of java.time.chrono.ChronoLocalDateTime in project jdk8u_jdk by JetBrains.
the class Parsed method resolveFields.
//-----------------------------------------------------------------------
private void resolveFields() {
// resolve ChronoField
resolveInstantFields();
resolveDateFields();
resolveTimeFields();
// any lenient date resolution should return epoch-day
if (fieldValues.size() > 0) {
int changedCount = 0;
outer: while (changedCount < 50) {
for (Map.Entry<TemporalField, Long> entry : fieldValues.entrySet()) {
TemporalField targetField = entry.getKey();
TemporalAccessor resolvedObject = targetField.resolve(fieldValues, this, resolverStyle);
if (resolvedObject != null) {
if (resolvedObject instanceof ChronoZonedDateTime) {
ChronoZonedDateTime<?> czdt = (ChronoZonedDateTime<?>) resolvedObject;
if (zone == null) {
zone = czdt.getZone();
} else if (zone.equals(czdt.getZone()) == false) {
throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: " + zone);
}
resolvedObject = czdt.toLocalDateTime();
}
if (resolvedObject instanceof ChronoLocalDateTime) {
ChronoLocalDateTime<?> cldt = (ChronoLocalDateTime<?>) resolvedObject;
updateCheckConflict(cldt.toLocalTime(), Period.ZERO);
updateCheckConflict(cldt.toLocalDate());
changedCount++;
// have to restart to avoid concurrent modification
continue outer;
}
if (resolvedObject instanceof ChronoLocalDate) {
updateCheckConflict((ChronoLocalDate) resolvedObject);
changedCount++;
// have to restart to avoid concurrent modification
continue outer;
}
if (resolvedObject instanceof LocalTime) {
updateCheckConflict((LocalTime) resolvedObject, Period.ZERO);
changedCount++;
// have to restart to avoid concurrent modification
continue outer;
}
throw new DateTimeException("Method resolve() can only return ChronoZonedDateTime, " + "ChronoLocalDateTime, ChronoLocalDate or LocalTime");
} else if (fieldValues.containsKey(targetField) == false) {
changedCount++;
// have to restart to avoid concurrent modification
continue outer;
}
}
break;
}
if (changedCount == 50) {
// catch infinite loops
throw new DateTimeException("One of the parsed fields has an incorrectly implemented resolve method");
}
// if something changed then have to redo ChronoField resolve
if (changedCount > 0) {
resolveInstantFields();
resolveDateFields();
resolveTimeFields();
}
}
}
Aggregations