Search in sources :

Example 1 with ChronoLocalDateTime

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) Test(org.testng.annotations.Test)

Example 2 with ChronoLocalDateTime

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);
}
Also used : ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 3 with ChronoLocalDateTime

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);
}
Also used : ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalDateTime(java.time.LocalDateTime) Chronology(java.time.chrono.Chronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology)

Example 4 with ChronoLocalDateTime

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);
}
Also used : ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalDateTime(java.time.LocalDateTime) Chronology(java.time.chrono.Chronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology)

Example 5 with ChronoLocalDateTime

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();
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) Entry(java.util.Map.Entry) TemporalField(java.time.temporal.TemporalField) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalTime(java.time.LocalTime) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime)

Aggregations

ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)6 LocalDateTime (java.time.LocalDateTime)4 Chronology (java.time.chrono.Chronology)3 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)3 Test (org.testng.annotations.Test)3 DateTimeException (java.time.DateTimeException)1 LocalTime (java.time.LocalTime)1 ChronoLocalDate (java.time.chrono.ChronoLocalDate)1 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)1 HijrahChronology (java.time.chrono.HijrahChronology)1 IsoChronology (java.time.chrono.IsoChronology)1 JapaneseChronology (java.time.chrono.JapaneseChronology)1 MinguoChronology (java.time.chrono.MinguoChronology)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 TemporalField (java.time.temporal.TemporalField)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 AbstractTCKTest (tck.java.time.AbstractTCKTest)1