Java Code Examples for java.time.chrono.Chronology#period()

The following examples show how to use java.time.chrono.Chronology#period() . 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: TCKChronoPeriod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_getUnits(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    assertEquals(period.getUnits().size(), 3);
    assertEquals(period.getUnits().get(0), YEARS);
    assertEquals(period.getUnits().get(1), MONTHS);
    assertEquals(period.getUnits().get(2), DAYS);
}
 
Example 2
Source File: TCKChronoPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_plus(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod period2 = chrono.period(2, 3, 4);
    ChronoPeriod result = period.plus(period2);
    assertEquals(result, chrono.period(3, 5, 7));
}
 
Example 3
Source File: TCKChronoPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_minus_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod isoPeriod = Period.of(2, 3, 4);
    ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
    // one of these two will fail
    period.minus(isoPeriod);
    period.minus(thaiPeriod);
}
 
Example 4
Source File: TCKChronoPeriod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_subtractFrom_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
    ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
    // one of these two will fail
    period.subtractFrom(isoDate);
    period.subtractFrom(thaiDate);
}
 
Example 5
Source File: TCKChronoPeriod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_plus(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod period2 = chrono.period(2, 3, 4);
    ChronoPeriod result = period.plus(period2);
    assertEquals(result, chrono.period(3, 5, 7));
}
 
Example 6
Source File: TCKChronoPeriod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_isZero_isNegative(Chronology chrono) {
    ChronoPeriod periodPositive = chrono.period(1, 2, 3);
    assertEquals(periodPositive.isZero(), false);
    assertEquals(periodPositive.isNegative(), false);

    ChronoPeriod periodZero = chrono.period(0, 0, 0);
    assertEquals(periodZero.isZero(), true);
    assertEquals(periodZero.isNegative(), false);

    ChronoPeriod periodNegative = chrono.period(-1, 0, 0);
    assertEquals(periodNegative.isZero(), false);
    assertEquals(periodNegative.isNegative(), true);
}
 
Example 7
Source File: TCKChronoPeriod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_toString(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    if (period instanceof Period == false) {
        assertEquals(period.toString(), chrono.getId() + " P1Y2M3D");
    }
}
 
Example 8
Source File: TCKChronoPeriod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_serialization(Chronology chrono) throws Exception {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(period);
    out.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

    ObjectInputStream in = new ObjectInputStream(bais);
    ChronoPeriod ser = (ChronoPeriod) in.readObject();
    assertEquals(ser, period, "deserialized ChronoPeriod is wrong");
}
 
Example 9
Source File: TCKChronoPeriod.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_addTo(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.addTo(date);
    assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}
 
Example 10
Source File: TCKChronoPeriod.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_addTo(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.addTo(date);
    assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}
 
Example 11
Source File: TCKChronoPeriod.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_plus_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod isoPeriod = Period.of(2, 3, 4);
    ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
    // one of these two will fail
    period.plus(isoPeriod);
    period.plus(thaiPeriod);
}
 
Example 12
Source File: TCKChronoPeriod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_addTo_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
    ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
    // one of these two will fail
    period.addTo(isoDate);
    period.addTo(thaiDate);
}
 
Example 13
Source File: TCKChronoPeriod.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_equals_notEqual(Chronology chrono) {
    ChronoPeriod a = chrono.period(1, 2, 3);
    ChronoPeriod b = chrono.period(2, 2, 3);
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
    assertEquals(a.equals(""), false);
    assertEquals(a.equals(null), false);
}
 
Example 14
Source File: TCKChronoPeriod.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="calendars", expectedExceptions=UnsupportedTemporalTypeException.class)
public void test_get_unsupported(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    period.get(HOURS);
}
 
Example 15
Source File: TCKChronoPeriod.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="calendars", expectedExceptions=UnsupportedTemporalTypeException.class)
public void test_get_unsupported(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    period.get(HOURS);
}
 
Example 16
Source File: TCKChronoPeriod.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="calendars")
public void test_multipliedBy(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    assertEquals(period.multipliedBy(3), chrono.period(3, 6, 9));
}
 
Example 17
Source File: TCKChronoPeriod.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="calendars")
public void test_negated(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    assertEquals(period.negated(), chrono.period(-1, -2, -3));
}
 
Example 18
Source File: TCKChronoPeriod.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="calendars")
public void test_multipliedBy(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    assertEquals(period.multipliedBy(3), chrono.period(3, 6, 9));
}
 
Example 19
Source File: TCKChronoPeriod.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="calendars")
public void test_negated(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    assertEquals(period.negated(), chrono.period(-1, -2, -3));
}
 
Example 20
Source File: TCKChronoPeriod.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="calendars")
public void test_getChronology(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    assertEquals(period.getChronology(), chrono);
}