Search in sources :

Example 1 with ChronoZonedDateTime

use of java.time.chrono.ChronoZonedDateTime in project jdk8u_jdk by JetBrains.

the class TestUmmAlQuraChronology method test_Instant_zonedDateTime.

//-----------------------------------------------------------------------
// zonedDateTime(Instant, ZoneId )
//-----------------------------------------------------------------------
@Test
public void test_Instant_zonedDateTime() {
    OffsetDateTime offsetDateTime = OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO);
    ZonedDateTime zonedDateTime = ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH);
    ChronoZonedDateTime<HijrahDate> result = HijrahChronology.INSTANCE.zonedDateTime(offsetDateTime.toInstant(), offsetDateTime.getOffset());
    assertEquals(result.toLocalDate(), HijrahChronology.INSTANCE.date(1433, 4, 7));
    assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
    result = HijrahChronology.INSTANCE.zonedDateTime(zonedDateTime.toInstant(), zonedDateTime.getOffset());
    assertEquals(result.toLocalDate(), HijrahChronology.INSTANCE.date(1433, 4, 7));
    assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
}
Also used : HijrahDate(java.time.chrono.HijrahDate) OffsetDateTime(java.time.OffsetDateTime) ZonedDateTime(java.time.ZonedDateTime) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) Test(org.testng.annotations.Test)

Example 2 with ChronoZonedDateTime

use of java.time.chrono.ChronoZonedDateTime in project jdk8u_jdk by JetBrains.

the class TCKChronoZonedDateTimeSerialization method test_ChronoZonedDateTimeSerialization.

//-----------------------------------------------------------------------
// Test Serialization of ISO via chrono API
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_ChronoZonedDateTimeSerialization(Chronology chrono) throws Exception {
    ZonedDateTime ref = LocalDate.of(2013, 1, 5).atTime(12, 1, 2, 3).atZone(ZoneId.of("GMT+01:23"));
    ChronoZonedDateTime<?> original = chrono.date(ref).atTime(ref.toLocalTime()).atZone(ref.getZone());
    assertSerializable(original);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 3 with ChronoZonedDateTime

use of java.time.chrono.ChronoZonedDateTime in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method data_format_withZone_withChronology.

//-----------------------------------------------------------------------
// format
//-----------------------------------------------------------------------
@DataProvider(name = "formatWithZoneWithChronology")
Object[][] data_format_withZone_withChronology() {
    YearMonth ym = YearMonth.of(2008, 6);
    LocalDate ld = LocalDate.of(2008, 6, 30);
    LocalTime lt = LocalTime.of(11, 30);
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 11, 30);
    OffsetTime ot = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE);
    OffsetDateTime odt = OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PONE);
    ZonedDateTime zdt = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS);
    ChronoZonedDateTime<ThaiBuddhistDate> thaiZdt = ThaiBuddhistChronology.INSTANCE.zonedDateTime(zdt);
    Instant instant = Instant.ofEpochSecond(3600);
    return new Object[][] { { null, null, DayOfWeek.MONDAY, "::::" }, { null, null, ym, "2008::::ISO" }, { null, null, ld, "2008::::ISO" }, { null, null, lt, ":11:::" }, { null, null, ldt, "2008:11:::ISO" }, { null, null, ot, ":11:+01:00::" }, { null, null, odt, "2008:11:+01:00::ISO" }, { null, null, zdt, "2008:11:+02:00:Europe/Paris:ISO" }, { null, null, instant, "::::" }, { IsoChronology.INSTANCE, null, DayOfWeek.MONDAY, "::::ISO" }, { IsoChronology.INSTANCE, null, ym, "2008::::ISO" }, { IsoChronology.INSTANCE, null, ld, "2008::::ISO" }, { IsoChronology.INSTANCE, null, lt, ":11:::ISO" }, { IsoChronology.INSTANCE, null, ldt, "2008:11:::ISO" }, { IsoChronology.INSTANCE, null, ot, ":11:+01:00::ISO" }, { IsoChronology.INSTANCE, null, odt, "2008:11:+01:00::ISO" }, { IsoChronology.INSTANCE, null, zdt, "2008:11:+02:00:Europe/Paris:ISO" }, { IsoChronology.INSTANCE, null, instant, "::::ISO" }, { null, ZONE_PARIS, DayOfWeek.MONDAY, ":::Europe/Paris:" }, { null, ZONE_PARIS, ym, "2008:::Europe/Paris:ISO" }, { null, ZONE_PARIS, ld, "2008:::Europe/Paris:ISO" }, { null, ZONE_PARIS, lt, ":11::Europe/Paris:" }, { null, ZONE_PARIS, ldt, "2008:11::Europe/Paris:ISO" }, { null, ZONE_PARIS, ot, ":11:+01:00:Europe/Paris:" }, { null, ZONE_PARIS, odt, "2008:12:+02:00:Europe/Paris:ISO" }, { null, ZONE_PARIS, zdt, "2008:11:+02:00:Europe/Paris:ISO" }, { null, ZONE_PARIS, instant, "1970:02:+01:00:Europe/Paris:ISO" }, { null, OFFSET_PTHREE, DayOfWeek.MONDAY, ":::+03:00:" }, { null, OFFSET_PTHREE, ym, "2008:::+03:00:ISO" }, { null, OFFSET_PTHREE, ld, "2008:::+03:00:ISO" }, { null, OFFSET_PTHREE, lt, ":11::+03:00:" }, { null, OFFSET_PTHREE, ldt, "2008:11::+03:00:ISO" }, // offset and zone clash
    { null, OFFSET_PTHREE, ot, null }, { null, OFFSET_PTHREE, odt, "2008:13:+03:00:+03:00:ISO" }, { null, OFFSET_PTHREE, zdt, "2008:12:+03:00:+03:00:ISO" }, { null, OFFSET_PTHREE, instant, "1970:04:+03:00:+03:00:ISO" }, // not a complete date
    { ThaiBuddhistChronology.INSTANCE, null, DayOfWeek.MONDAY, null }, // not a complete date
    { ThaiBuddhistChronology.INSTANCE, null, ym, null }, { ThaiBuddhistChronology.INSTANCE, null, ld, "2551::::ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, null, lt, ":11:::ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, null, ldt, "2551:11:::ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, null, ot, ":11:+01:00::ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, null, odt, "2551:11:+01:00::ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, null, zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, null, instant, "::::ThaiBuddhist" }, // not a complete date
    { ThaiBuddhistChronology.INSTANCE, null, DayOfWeek.MONDAY, null }, // not a complete date
    { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ym, null }, { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ld, "2551:::Europe/Paris:ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, lt, ":11::Europe/Paris:ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ldt, "2551:11::Europe/Paris:ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ot, ":11:+01:00:Europe/Paris:ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, odt, "2551:12:+02:00:Europe/Paris:ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, instant, "2513:02:+01:00:Europe/Paris:ThaiBuddhist" }, { null, ZONE_PARIS, thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist" }, { ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist" }, { IsoChronology.INSTANCE, ZONE_PARIS, thaiZdt, "2008:11:+02:00:Europe/Paris:ISO" } };
}
Also used : LocalDateTime(java.time.LocalDateTime) ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) YearMonth(java.time.YearMonth) LocalTime(java.time.LocalTime) OffsetDateTime(java.time.OffsetDateTime) ZonedDateTime(java.time.ZonedDateTime) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) OffsetTime(java.time.OffsetTime) Instant(java.time.Instant) LocalDate(java.time.LocalDate) DataProvider(org.testng.annotations.DataProvider)

Example 4 with ChronoZonedDateTime

use of java.time.chrono.ChronoZonedDateTime 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)

Example 5 with ChronoZonedDateTime

use of java.time.chrono.ChronoZonedDateTime in project j2objc by google.

the class TCKDateTimeFormatter method data_format_withZone_withChronology.

// -----------------------------------------------------------------------
// format
// -----------------------------------------------------------------------
@DataProvider
public static Object[][] data_format_withZone_withChronology() {
    YearMonth ym = YearMonth.of(2008, 6);
    LocalDate ld = LocalDate.of(2008, 6, 30);
    LocalTime lt = LocalTime.of(11, 30);
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 11, 30);
    OffsetTime ot = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE);
    OffsetDateTime odt = OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PONE);
    ZonedDateTime zdt = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS);
    /* J2ObjC removed: Only "gregorian" and "julian" calendars are supported.
        ChronoZonedDateTime<ThaiBuddhistDate> thaiZdt = ThaiBuddhistChronology.INSTANCE.zonedDateTime(zdt); */
    Instant instant = Instant.ofEpochSecond(3600);
    return new Object[][] { { null, null, DayOfWeek.MONDAY, "::::" }, { null, null, ym, "2008::::ISO" }, { null, null, ld, "2008::::ISO" }, { null, null, lt, ":11:::" }, { null, null, ldt, "2008:11:::ISO" }, { null, null, ot, ":11:+01:00::" }, { null, null, odt, "2008:11:+01:00::ISO" }, { null, null, zdt, "2008:11:+02:00:Europe/Paris:ISO" }, { null, null, instant, "::::" }, { IsoChronology.INSTANCE, null, DayOfWeek.MONDAY, "::::ISO" }, { IsoChronology.INSTANCE, null, ym, "2008::::ISO" }, { IsoChronology.INSTANCE, null, ld, "2008::::ISO" }, { IsoChronology.INSTANCE, null, lt, ":11:::ISO" }, { IsoChronology.INSTANCE, null, ldt, "2008:11:::ISO" }, { IsoChronology.INSTANCE, null, ot, ":11:+01:00::ISO" }, { IsoChronology.INSTANCE, null, odt, "2008:11:+01:00::ISO" }, { IsoChronology.INSTANCE, null, zdt, "2008:11:+02:00:Europe/Paris:ISO" }, { IsoChronology.INSTANCE, null, instant, "::::ISO" }, { null, ZONE_PARIS, DayOfWeek.MONDAY, ":::Europe/Paris:" }, { null, ZONE_PARIS, ym, "2008:::Europe/Paris:ISO" }, { null, ZONE_PARIS, ld, "2008:::Europe/Paris:ISO" }, { null, ZONE_PARIS, lt, ":11::Europe/Paris:" }, { null, ZONE_PARIS, ldt, "2008:11::Europe/Paris:ISO" }, { null, ZONE_PARIS, ot, ":11:+01:00:Europe/Paris:" }, { null, ZONE_PARIS, odt, "2008:12:+02:00:Europe/Paris:ISO" }, { null, ZONE_PARIS, zdt, "2008:11:+02:00:Europe/Paris:ISO" }, { null, ZONE_PARIS, instant, "1970:02:+01:00:Europe/Paris:ISO" }, { null, OFFSET_PTHREE, DayOfWeek.MONDAY, ":::+03:00:" }, { null, OFFSET_PTHREE, ym, "2008:::+03:00:ISO" }, { null, OFFSET_PTHREE, ld, "2008:::+03:00:ISO" }, { null, OFFSET_PTHREE, lt, ":11::+03:00:" }, { null, OFFSET_PTHREE, ldt, "2008:11::+03:00:ISO" }, // offset and zone clash
    { null, OFFSET_PTHREE, ot, null }, { null, OFFSET_PTHREE, odt, "2008:13:+03:00:+03:00:ISO" }, { null, OFFSET_PTHREE, zdt, "2008:12:+03:00:+03:00:ISO" }, { null, OFFSET_PTHREE, instant, "1970:04:+03:00:+03:00:ISO" } /* J2ObjC removed: Only "gregorian" and "julian" calendars are supported.
                {ThaiBuddhistChronology.INSTANCE, null, DayOfWeek.MONDAY, null},  // not a complete date
                {ThaiBuddhistChronology.INSTANCE, null, ym, null},  // not a complete date
                {ThaiBuddhistChronology.INSTANCE, null, ld, "2551::::ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, null, lt, ":11:::ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, null, ldt, "2551:11:::ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, null, ot, ":11:+01:00::ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, null, odt, "2551:11:+01:00::ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, null, zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, null, instant, "::::ThaiBuddhist"},

                {ThaiBuddhistChronology.INSTANCE, null, DayOfWeek.MONDAY, null},  // not a complete date
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ym, null},  // not a complete date
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ld, "2551:::Europe/Paris:ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, lt, ":11::Europe/Paris:ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ldt, "2551:11::Europe/Paris:ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ot, ":11:+01:00:Europe/Paris:ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, odt, "2551:12:+02:00:Europe/Paris:ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, instant, "2513:02:+01:00:Europe/Paris:ThaiBuddhist"},

                {null, ZONE_PARIS, thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"},
                {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"},
                {IsoChronology.INSTANCE, ZONE_PARIS, thaiZdt, "2008:11:+02:00:Europe/Paris:ISO"},
                 */
    };
}
Also used : LocalDateTime(java.time.LocalDateTime) YearMonth(java.time.YearMonth) LocalTime(java.time.LocalTime) OffsetDateTime(java.time.OffsetDateTime) ZonedDateTime(java.time.ZonedDateTime) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) OffsetTime(java.time.OffsetTime) Instant(java.time.Instant) LocalDate(java.time.LocalDate) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)23 ZonedDateTime (java.time.ZonedDateTime)15 OffsetDateTime (java.time.OffsetDateTime)10 Test (org.testng.annotations.Test)7 Instant (java.time.Instant)5 LocalTime (java.time.LocalTime)5 ChronoLocalDate (java.time.chrono.ChronoLocalDate)5 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)4 Chronology (java.time.chrono.Chronology)4 Test (org.junit.Test)4 DateTimeException (java.time.DateTimeException)3 LocalDateTime (java.time.LocalDateTime)3 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)3 TemporalAccessor (java.time.temporal.TemporalAccessor)3 TemporalField (java.time.temporal.TemporalField)3 Entry (java.util.Map.Entry)3 LocalDate (java.time.LocalDate)2 OffsetTime (java.time.OffsetTime)2 YearMonth (java.time.YearMonth)2 IsoChronology (java.time.chrono.IsoChronology)2