java.time.chrono.ChronoLocalDateTime Java Examples

The following examples show how to use java.time.chrono.ChronoLocalDateTime. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TCKChronoLocalDateTime.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.plus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt
                        + ", can not be cast to " + cdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example #2
Source File: TCKChronoLocalDateTime.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.plus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt
                        + ", can not be cast to " + cdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example #3
Source File: TCKChronoLocalDateTime.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.minus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException" + cdt.getClass()
                        + ", can not be cast to " + cdt2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.minus(1, adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example #4
Source File: TCKChronoLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalField adjuster = new FixedTemporalField(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.with(adjuster, 1);
                Assert.fail("TemporalField doWith() should have thrown a ClassCastException" + cdt.getClass()
                        + ", can not be cast to " + cdt2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.with(adjuster, 1);
            assertEquals(result, cdt2, "TemporalField doWith() failed to replace date");
        }
    }
}
 
Example #5
Source File: TCKChronoLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalAdjuster adjuster = new FixedAdjuster(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.with(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException, "
                        + "required: " + cdt + ", supplied: " + cdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.with(adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example #6
Source File: TCKMinguoChronology.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
@Test(dataProvider="samples")
public void test_MinguoDate(MinguoDate minguoDate, LocalDate iso) {
    MinguoDate hd = minguoDate;
    ChronoLocalDateTime<MinguoDate> hdt = hd.atTime(LocalTime.NOON);
    ZoneOffset zo = ZoneOffset.ofHours(1);
    ChronoZonedDateTime<MinguoDate> hzdt = hdt.atZone(zo);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    hdt = hdt.plus(1, ChronoUnit.NANOS);
    ChronoLocalDateTime<MinguoDate> a2 = hzdt.toLocalDateTime();
    MinguoDate a3 = a2.toLocalDate();
    MinguoDate a5 = hzdt.toLocalDate();
    //System.out.printf(" d: %s, dt: %s; odt: %s; zodt: %s; a4: %s%n", date, hdt, hodt, hzdt, a5);
}
 
Example #7
Source File: TCKChronoLocalDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalAdjuster adjuster = new FixedAdjuster(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.with(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException, "
                        + "required: " + cdt + ", supplied: " + cdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.with(adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example #8
Source File: TCKMinguoChronology.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
@Test(dataProvider="samples")
public void test_MinguoDate(MinguoDate minguoDate, LocalDate iso) {
    MinguoDate hd = minguoDate;
    ChronoLocalDateTime<MinguoDate> hdt = hd.atTime(LocalTime.NOON);
    ZoneOffset zo = ZoneOffset.ofHours(1);
    ChronoZonedDateTime<MinguoDate> hzdt = hdt.atZone(zo);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    hdt = hdt.plus(1, ChronoUnit.NANOS);
    ChronoLocalDateTime<MinguoDate> a2 = hzdt.toLocalDateTime();
    MinguoDate a3 = a2.toLocalDate();
    MinguoDate a5 = hzdt.toLocalDate();
    //System.out.printf(" d: %s, dt: %s; odt: %s; zodt: %s; a4: %s%n", date, hdt, hodt, hzdt, a5);
}
 
Example #9
Source File: TCKChronoLocalDateTime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.plus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt
                        + ", can not be cast to " + cdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example #10
Source File: TestExampleCode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void HijrahExample1() {
    HijrahDate hd2 = HijrahChronology.INSTANCE.date(1200, 1, 1);

    ChronoLocalDateTime<HijrahDate> hdt = hd2.atTime(LocalTime.MIDNIGHT);
    ChronoZonedDateTime<HijrahDate> zhdt = hdt.atZone(ZoneId.of("GMT"));
    HijrahDate hd3 = zhdt.toLocalDate();
    ChronoLocalDateTime<HijrahDate> hdt2 = zhdt.toLocalDateTime();
    HijrahDate hd4 = hdt2.toLocalDate();

    HijrahDate hd5 = next(hd2);
}
 
Example #11
Source File: TestUmmAlQuraChronology.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="chronoDateTimes")
public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
    HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
    ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.US);
    assertEquals(df.format(hdt), expected);
}
 
Example #12
Source File: TestUmmAlQuraChronology.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="chronoDateTimes")
public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
    HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
    ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.US);
    assertEquals(df.format(hdt), expected);
}
 
Example #13
Source File: TCKDateTimeParseResolver.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoLocalDateTime_overrideChrono_wrongChrono() {
    ChronoLocalDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
    f = f.withChronology(MinguoChronology.INSTANCE);
    f.parse("1234567890");
}
 
Example #14
Source File: TestExampleCode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void HijrahExample1() {
    HijrahDate hd2 = HijrahChronology.INSTANCE.date(1200, 1, 1);

    ChronoLocalDateTime<HijrahDate> hdt = hd2.atTime(LocalTime.MIDNIGHT);
    ChronoZonedDateTime<HijrahDate> zhdt = hdt.atZone(ZoneId.of("GMT"));
    HijrahDate hd3 = zhdt.toLocalDate();
    ChronoLocalDateTime<HijrahDate> hdt2 = zhdt.toLocalDateTime();
    HijrahDate hd4 = hdt2.toLocalDate();

    HijrahDate hd5 = next(hd2);
}
 
Example #15
Source File: TestUmmAlQuraChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="chronoDateTimes")
public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
    HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
    ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.US);
    assertEquals(df.format(hdt), expected);
}
 
Example #16
Source File: TCKChronoLocalDateTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #17
Source File: TestUmmAlQuraChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="chronoDateTimes")
public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
    HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
    ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.US);
    assertEquals(df.format(hdt), expected);
}
 
Example #18
Source File: TCKMinguoChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test()
public void test_MinguoChrono() {
    MinguoDate h1 = MinguoChronology.INSTANCE.date(MinguoEra.ROC, 1, 2, 3);
    MinguoDate h2 = h1;
    ChronoLocalDateTime<MinguoDate> h3 = h2.atTime(LocalTime.NOON);
    @SuppressWarnings("unused")
    ChronoZonedDateTime<MinguoDate> h4 = h3.atZone(ZoneOffset.UTC);
}
 
Example #19
Source File: TCKDateTimeParseResolver.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoLocalDateTime_overrideChrono_wrongChrono() {
    ChronoLocalDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
    f = f.withChronology(MinguoChronology.INSTANCE);
    f.parse("1234567890");
}
 
Example #20
Source File: TestUmmAlQuraChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="chronoDateTimes")
public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
    HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
    ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.US);
    assertEquals(df.format(hdt), expected);
}
 
Example #21
Source File: TestExampleCode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void HijrahExample1() {
    HijrahDate hd2 = HijrahChronology.INSTANCE.date(1200, 1, 1);

    ChronoLocalDateTime<HijrahDate> hdt = hd2.atTime(LocalTime.MIDNIGHT);
    ChronoZonedDateTime<HijrahDate> zhdt = hdt.atZone(ZoneId.of("GMT"));
    HijrahDate hd3 = zhdt.toLocalDate();
    ChronoLocalDateTime<HijrahDate> hdt2 = zhdt.toLocalDateTime();
    HijrahDate hd4 = hdt2.toLocalDate();

    HijrahDate hd5 = next(hd2);
}
 
Example #22
Source File: TCKMinguoChronology.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test()
public void test_MinguoChrono() {
    MinguoDate h1 = MinguoChronology.INSTANCE.date(MinguoEra.ROC, 1, 2, 3);
    MinguoDate h2 = h1;
    ChronoLocalDateTime<MinguoDate> h3 = h2.atTime(LocalTime.NOON);
    @SuppressWarnings("unused")
    ChronoZonedDateTime<MinguoDate> h4 = h3.atZone(ZoneOffset.UTC);
}
 
Example #23
Source File: TCKMinguoChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test()
public void test_MinguoChrono() {
    MinguoDate h1 = MinguoChronology.INSTANCE.date(MinguoEra.ROC, 1, 2, 3);
    MinguoDate h2 = h1;
    ChronoLocalDateTime<MinguoDate> h3 = h2.atTime(LocalTime.NOON);
    @SuppressWarnings("unused")
    ChronoZonedDateTime<MinguoDate> h4 = h3.atZone(ZoneOffset.UTC);
}
 
Example #24
Source File: TestUmmAlQuraChronology.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="chronoDateTimes")
public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
    HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
    ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.US);
    assertEquals(df.format(hdt), expected);
}
 
Example #25
Source File: TCKMinguoChronology.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test()
public void test_MinguoChrono() {
    MinguoDate h1 = MinguoChronology.INSTANCE.date(MinguoEra.ROC, 1, 2, 3);
    MinguoDate h2 = h1;
    ChronoLocalDateTime<MinguoDate> h3 = h2.atTime(LocalTime.NOON);
    @SuppressWarnings("unused")
    ChronoZonedDateTime<MinguoDate> h4 = h3.atZone(ZoneOffset.UTC);
}
 
Example #26
Source File: TCKMinguoChronology.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test()
public void test_MinguoChrono() {
    MinguoDate h1 = MinguoChronology.INSTANCE.date(MinguoEra.ROC, 1, 2, 3);
    MinguoDate h2 = h1;
    ChronoLocalDateTime<MinguoDate> h3 = h2.atTime(LocalTime.NOON);
    @SuppressWarnings("unused")
    ChronoZonedDateTime<MinguoDate> h4 = h3.atZone(ZoneOffset.UTC);
}
 
Example #27
Source File: TCKChronoLocalDateTimeSerialization.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@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);
}
 
Example #28
Source File: Date_To_ChronoLocalDateTime.java    From manifold with Apache License 2.0 4 votes vote down vote up
@Override
public ChronoLocalDateTime<LocalDate> proxy(Date date, Class<ChronoLocalDateTime<LocalDate>> aClass) {
  return new Proxy(date);
}
 
Example #29
Source File: TCKChronoLocalDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="calendars")
public void test_datetime_comparisons(Chronology chrono) {
    List<ChronoLocalDateTime<?>> dates = new ArrayList<>();

    ChronoLocalDateTime<?> date = chrono.date(LocalDate.of(2013, 1, 1)).atTime(LocalTime.MIN);

    // 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<ChronoLocalDateTime<?>> otherDates = new ArrayList<>();
        Chronology chrono2 = clist[0];
        for (ChronoLocalDateTime<?> d : dates) {
            otherDates.add(chrono2.date(d).atTime(d.toLocalTime()));
        }

        // Now compare  the sequence of original dates with the sequence of converted dates
        for (int i = 0; i < dates.size(); i++) {
            ChronoLocalDateTime<?> a = dates.get(i);
            for (int j = 0; j < otherDates.size(); j++) {
                ChronoLocalDateTime<?> b = otherDates.get(j);
                int cmp = ChronoLocalDateTime.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 + " isAfter " + 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 + " isAfter " + 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 + " isAfter " + b);
                    assertEquals(a.isEqual(b), true, a + " isEqual " + b);
                }
            }
        }
    }
}
 
Example #30
Source File: TCKChronoLocalDateTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_from_TemporalAccessor_timeOnly() {
    ChronoLocalDateTime.from(LocalTime.of(12, 30));
}