Java Code Examples for java.time.chrono.ChronoLocalDate#plus()

The following examples show how to use java.time.chrono.ChronoLocalDate#plus() . 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: TCKChronoLocalDate.java    From dragonwell8_jdk 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);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.plus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
                        + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 2
Source File: TCKChronoLocalDate.java    From jdk8u-dev-jdk 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);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.plus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
                        + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 3
Source File: TCKChronoLocalDate.java    From openjdk-jdk8u 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);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.plus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
                        + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 4
Source File: TCKChronoLocalDate.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAmount adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.plus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 5
Source File: TCKChronoLocalDate.java    From openjdk-8-source 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);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.plus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
                        + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 6
Source File: TCKChronoLocalDate.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);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.plus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
                        + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 7
Source File: TCKChronoLocalDate.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAmount adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.plus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 8
Source File: TCKChronoLocalDate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAmount adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.plus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 9
Source File: TCKChronoLocalDate.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);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.plus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
                        + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 10
Source File: WeekFields.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a new week-based-year date of the Chronology, year, week-of-year,
 * and dow of week.
 * @param chrono The chronology of the new date
 * @param yowby the year of the week-based-year
 * @param wowby the week of the week-based-year
 * @param dow the day of the week
 * @return a ChronoLocalDate for the requested year, week of year, and day of week
 */
private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
        int yowby, int wowby, int dow) {
    ChronoLocalDate date = chrono.date(yowby, 1, 1);
    int ldow = localizedDayOfWeek(date);
    int offset = startOfWeekOffset(1, ldow);

    // Clamp the week of year to keep it in the same year
    int yearLen = date.lengthOfYear();
    int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
    wowby = Math.min(wowby, newYearWeek - 1);

    int days = -offset + (dow - 1) + (wowby - 1) * 7;
    return date.plus(days, DAYS);
}
 
Example 11
Source File: TestUmmAlQuraChronology.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test (dataProvider="monthDays")
public void test_valueRange_monthDays(int year, int month, int maxlength) {
    ChronoLocalDate date = HijrahChronology.INSTANCE.date(year, month, 1);
    ValueRange range = null;
    for (int i=1; i<=12; i++) {
        range = date.range(ChronoField.DAY_OF_MONTH);
        date = date.plus(1, ChronoUnit.MONTHS);
        assertEquals(range.getMaximum(), month, maxlength);
    }
}
 
Example 12
Source File: WeekFields.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a new week-based-year date of the Chronology, year, week-of-year,
 * and dow of week.
 * @param chrono The chronology of the new date
 * @param yowby the year of the week-based-year
 * @param wowby the week of the week-based-year
 * @param dow the day of the week
 * @return a ChronoLocalDate for the requested year, week of year, and day of week
 */
private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
        int yowby, int wowby, int dow) {
    ChronoLocalDate date = chrono.date(yowby, 1, 1);
    int ldow = localizedDayOfWeek(date);
    int offset = startOfWeekOffset(1, ldow);

    // Clamp the week of year to keep it in the same year
    int yearLen = date.lengthOfYear();
    int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
    wowby = Math.min(wowby, newYearWeek - 1);

    int days = -offset + (dow - 1) + (wowby - 1) * 7;
    return date.plus(days, DAYS);
}
 
Example 13
Source File: WeekFields.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a new week-based-year date of the Chronology, year, week-of-year,
 * and dow of week.
 * @param chrono The chronology of the new date
 * @param yowby the year of the week-based-year
 * @param wowby the week of the week-based-year
 * @param dow the day of the week
 * @return a ChronoLocalDate for the requested year, week of year, and day of week
 */
private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
        int yowby, int wowby, int dow) {
    ChronoLocalDate date = chrono.date(yowby, 1, 1);
    int ldow = localizedDayOfWeek(date);
    int offset = startOfWeekOffset(1, ldow);

    // Clamp the week of year to keep it in the same year
    int yearLen = date.lengthOfYear();
    int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
    wowby = Math.min(wowby, newYearWeek - 1);

    int days = -offset + (dow - 1) + (wowby - 1) * 7;
    return date.plus(days, DAYS);
}
 
Example 14
Source File: WeekFields.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a new week-based-year date of the Chronology, year, week-of-year,
 * and dow of week.
 * @param chrono The chronology of the new date
 * @param yowby the year of the week-based-year
 * @param wowby the week of the week-based-year
 * @param dow the day of the week
 * @return a ChronoLocalDate for the requested year, week of year, and day of week
 */
private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
        int yowby, int wowby, int dow) {
    ChronoLocalDate date = chrono.date(yowby, 1, 1);
    int ldow = localizedDayOfWeek(date);
    int offset = startOfWeekOffset(1, ldow);

    // Clamp the week of year to keep it in the same year
    int yearLen = date.lengthOfYear();
    int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
    wowby = Math.min(wowby, newYearWeek - 1);

    int days = -offset + (dow - 1) + (wowby - 1) * 7;
    return date.plus(days, DAYS);
}
 
Example 15
Source File: TestUmmAlQuraChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test (dataProvider="monthDays")
public void test_valueRange_monthDays(int year, int month, int maxlength) {
    ChronoLocalDate date = HijrahChronology.INSTANCE.date(year, month, 1);
    ValueRange range = null;
    for (int i=1; i<=12; i++) {
        range = date.range(ChronoField.DAY_OF_MONTH);
        date = date.plus(1, ChronoUnit.MONTHS);
        assertEquals(range.getMaximum(), month, maxlength);
    }
}
 
Example 16
Source File: TestUmmAlQuraChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test (dataProvider="monthDays")
public void test_valueRange_monthDays(int year, int month, int maxlength) {
    ChronoLocalDate date = HijrahChronology.INSTANCE.date(year, month, 1);
    ValueRange range = null;
    for (int i=1; i<=12; i++) {
        range = date.range(ChronoField.DAY_OF_MONTH);
        date = date.plus(1, ChronoUnit.MONTHS);
        assertEquals(range.getMaximum(), month, maxlength);
    }
}
 
Example 17
Source File: WeekFields.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a new week-based-year date of the Chronology, year, week-of-year,
 * and dow of week.
 * @param chrono The chronology of the new date
 * @param yowby the year of the week-based-year
 * @param wowby the week of the week-based-year
 * @param dow the day of the week
 * @return a ChronoLocalDate for the requested year, week of year, and day of week
 */
private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
        int yowby, int wowby, int dow) {
    ChronoLocalDate date = chrono.date(yowby, 1, 1);
    int ldow = localizedDayOfWeek(date);
    int offset = startOfWeekOffset(1, ldow);

    // Clamp the week of year to keep it in the same year
    int yearLen = date.lengthOfYear();
    int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
    wowby = Math.min(wowby, newYearWeek - 1);

    int days = -offset + (dow - 1) + (wowby - 1) * 7;
    return date.plus(days, DAYS);
}
 
Example 18
Source File: WeekFields.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Return a new week-based-year date of the Chronology, year, week-of-year,
 * and dow of week.
 * @param chrono The chronology of the new date
 * @param yowby the year of the week-based-year
 * @param wowby the week of the week-based-year
 * @param dow the day of the week
 * @return a ChronoLocalDate for the requested year, week of year, and day of week
 */
private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
        int yowby, int wowby, int dow) {
    ChronoLocalDate date = chrono.date(yowby, 1, 1);
    int ldow = localizedDayOfWeek(date);
    int offset = startOfWeekOffset(1, ldow);

    // Clamp the week of year to keep it in the same year
    int yearLen = date.lengthOfYear();
    int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
    wowby = Math.min(wowby, newYearWeek - 1);

    int days = -offset + (dow - 1) + (wowby - 1) * 7;
    return date.plus(days, DAYS);
}
 
Example 19
Source File: TestUmmAlQuraChronology.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test (dataProvider="monthDays")
public void test_valueRange_monthDays(int year, int month, int maxlength) {
    ChronoLocalDate date = HijrahChronology.INSTANCE.date(year, month, 1);
    ValueRange range = null;
    for (int i=1; i<=12; i++) {
        range = date.range(ChronoField.DAY_OF_MONTH);
        date = date.plus(1, ChronoUnit.MONTHS);
        assertEquals(range.getMaximum(), month, maxlength);
    }
}
 
Example 20
Source File: WeekFields.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a new week-based-year date of the Chronology, year, week-of-year,
 * and dow of week.
 * @param chrono The chronology of the new date
 * @param yowby the year of the week-based-year
 * @param wowby the week of the week-based-year
 * @param dow the day of the week
 * @return a ChronoLocalDate for the requested year, week of year, and day of week
 */
private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
        int yowby, int wowby, int dow) {
    ChronoLocalDate date = chrono.date(yowby, 1, 1);
    int ldow = localizedDayOfWeek(date);
    int offset = startOfWeekOffset(1, ldow);

    // Clamp the week of year to keep it in the same year
    int yearLen = date.lengthOfYear();
    int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
    wowby = Math.min(wowby, newYearWeek - 1);

    int days = -offset + (dow - 1) + (wowby - 1) * 7;
    return date.plus(days, DAYS);
}