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

The following examples show how to use java.time.chrono.ChronoLocalDate#minus() . 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: WeekFields.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 2
Source File: WeekFields.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 3
Source File: WeekFields.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 4
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_badMinusTemporalUnitChrono(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.minus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd minus 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.minus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 5
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_badMinusAdjusterChrono(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.minus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.minus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 6
Source File: WeekFields.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 7
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_badMinusTemporalUnitChrono(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.minus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd minus 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.minus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 8
Source File: WeekFields.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 9
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_badMinusTemporalUnitChrono(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.minus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd minus 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.minus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 10
Source File: WeekFields.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 11
Source File: WeekFields.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 12
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_badMinusAdjusterChrono(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.minus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.minus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 13
Source File: WeekFields.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 14
Source File: TCKChronoLocalDate.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("data_of_calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : (Chronology[][]) data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.minus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd minus 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.minus(1, adjuster);
            assertEquals("WithAdjuster failed to replace date", result, date2);
        }
    }
}
 
Example 15
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_badMinusAdjusterChrono(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.minus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.minus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 16
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_badMinusAdjusterChrono(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.minus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.minus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 17
Source File: WeekFields.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 18
Source File: TCKChronoLocalDate.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badMinusAdjusterChrono(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.minus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.minus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 19
Source File: WeekFields.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
Example 20
Source File: WeekFields.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}