Java Code Examples for java.time.temporal.ValueRange#getMaximum()

The following examples show how to use java.time.temporal.ValueRange#getMaximum() . 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: IsMaximum.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean matchesSafely(final T actual, final Description mismatchDesc) {
    long actualValue = this.datePart.getFrom(this.adapter.asTemporal(actual));
    ValueRange range = this.datePart.rangeRefinedBy(this.adapter.asTemporal(actual));
    if (range.getMaximum() != actualValue) {
        mismatchDesc.appendText("date is the " + actualValue
                + " "
                + this.formatter.describe(this.datePart)
                + " instead of "
                + range.getMinimum()
                + " "
                + this.formatter.describe(this.datePart));
        return false;
    } else {
        return true;
    }
}
 
Example 2
Source File: TCKWeekFields.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    int dowExpected = (day.get(dowField) - 1) % 7 + 1;
    LocalDate dowDate = day.with(dowField, dowExpected);
    int dowResult = dowDate.get(dowField);
    assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);

    int weekExpected = day.get(wowbyField) + 1;
    ValueRange range = day.range(wowbyField);
    weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
    LocalDate weekDate = day.with(wowbyField, weekExpected);
    int weekResult = weekDate.get(wowbyField);
    assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);

    int yearExpected = day.get(yowbyField) + 1;

    LocalDate yearDate = day.with(yowbyField, yearExpected);
    int yearResult = yearDate.get(yowbyField);
    assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day  + " --> " + yearDate);

    range = yearDate.range(wowbyField);
    weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());

    int weekActual = yearDate.get(wowbyField);
    assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
 
Example 3
Source File: ChronoLocalDateImpl.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private long monthsUntil(ChronoLocalDate end) {
    ValueRange range = getChronology().range(MONTH_OF_YEAR);
    if (range.getMaximum() != 12) {
        throw new IllegalStateException("ChronoLocalDateImpl only supports Chronologies with 12 months per year");
    }
    long packed1 = getLong(PROLEPTIC_MONTH) * 32L + get(DAY_OF_MONTH);  // no overflow
    long packed2 = end.getLong(PROLEPTIC_MONTH) * 32L + end.get(DAY_OF_MONTH);  // no overflow
    return (packed2 - packed1) / 32;
}
 
Example 4
Source File: ChronoPeriodImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the range of months.
 *
 * @return the month range, -1 if not fixed range
 */
private long monthRange() {
    ValueRange startRange = chrono.range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
        return startRange.getMaximum() - startRange.getMinimum() + 1;
    }
    return -1;
}
 
Example 5
Source File: TCKWeekFields.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    int dowExpected = (day.get(dowField) - 1) % 7 + 1;
    LocalDate dowDate = day.with(dowField, dowExpected);
    int dowResult = dowDate.get(dowField);
    assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);

    int weekExpected = day.get(wowbyField) + 1;
    ValueRange range = day.range(wowbyField);
    weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
    LocalDate weekDate = day.with(wowbyField, weekExpected);
    int weekResult = weekDate.get(wowbyField);
    assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);

    int yearExpected = day.get(yowbyField) + 1;

    LocalDate yearDate = day.with(yowbyField, yearExpected);
    int yearResult = yearDate.get(yowbyField);
    assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day  + " --> " + yearDate);

    range = yearDate.range(wowbyField);
    weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());

    int weekActual = yearDate.get(wowbyField);
    assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
 
Example 6
Source File: TCKWeekFields.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    int dowExpected = (day.get(dowField) - 1) % 7 + 1;
    LocalDate dowDate = day.with(dowField, dowExpected);
    int dowResult = dowDate.get(dowField);
    assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);

    int weekExpected = day.get(wowbyField) + 1;
    ValueRange range = day.range(wowbyField);
    weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
    LocalDate weekDate = day.with(wowbyField, weekExpected);
    int weekResult = weekDate.get(wowbyField);
    assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);

    int yearExpected = day.get(yowbyField) + 1;

    LocalDate yearDate = day.with(yowbyField, yearExpected);
    int yearResult = yearDate.get(yowbyField);
    assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day  + " --> " + yearDate);

    range = yearDate.range(wowbyField);
    weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());

    int weekActual = yearDate.get(wowbyField);
    assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
 
Example 7
Source File: ChronoPeriodImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the range of months.
 *
 * @return the month range, -1 if not fixed range
 */
private long monthRange() {
    ValueRange startRange = chrono.range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
        return startRange.getMaximum() - startRange.getMinimum() + 1;
    }
    return -1;
}
 
Example 8
Source File: ChronoPeriodImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the range of months.
 *
 * @return the month range, -1 if not fixed range
 */
private long monthRange() {
    ValueRange startRange = chrono.range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
        return startRange.getMaximum() - startRange.getMinimum() + 1;
    }
    return -1;
}
 
Example 9
Source File: ChronoPeriodImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the range of months.
 *
 * @return the month range, -1 if not fixed range
 */
private long monthRange() {
    ValueRange startRange = chrono.range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
        return startRange.getMaximum() - startRange.getMinimum() + 1;
    }
    return -1;
}
 
Example 10
Source File: ChronoLocalDateImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private long monthsUntil(ChronoLocalDate end) {
    ValueRange range = getChronology().range(MONTH_OF_YEAR);
    if (range.getMaximum() != 12) {
        throw new IllegalStateException("ChronoLocalDateImpl only supports Chronologies with 12 months per year");
    }
    long packed1 = getLong(PROLEPTIC_MONTH) * 32L + get(DAY_OF_MONTH);  // no overflow
    long packed2 = end.getLong(PROLEPTIC_MONTH) * 32L + end.get(DAY_OF_MONTH);  // no overflow
    return (packed2 - packed1) / 32;
}
 
Example 11
Source File: ChronoPeriodImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Calculates the range of months.
 *
 * @return the month range, -1 if not fixed range
 */
private long monthRange() {
    ValueRange startRange = chrono.range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
        return startRange.getMaximum() - startRange.getMinimum() + 1;
    }
    return -1;
}
 
Example 12
Source File: ChronoLocalDateImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private long monthsUntil(ChronoLocalDate end) {
    ValueRange range = getChronology().range(MONTH_OF_YEAR);
    if (range.getMaximum() != 12) {
        throw new IllegalStateException("ChronoLocalDateImpl only supports Chronologies with 12 months per year");
    }
    long packed1 = getLong(PROLEPTIC_MONTH) * 32L + get(DAY_OF_MONTH);  // no overflow
    long packed2 = end.getLong(PROLEPTIC_MONTH) * 32L + end.get(DAY_OF_MONTH);  // no overflow
    return (packed2 - packed1) / 32;
}
 
Example 13
Source File: ChronoLocalDateImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private long monthsUntil(ChronoLocalDate end) {
    ValueRange range = getChronology().range(MONTH_OF_YEAR);
    if (range.getMaximum() != 12) {
        throw new IllegalStateException("ChronoLocalDateImpl only supports Chronologies with 12 months per year");
    }
    long packed1 = getLong(PROLEPTIC_MONTH) * 32L + get(DAY_OF_MONTH);  // no overflow
    long packed2 = end.getLong(PROLEPTIC_MONTH) * 32L + end.get(DAY_OF_MONTH);  // no overflow
    return (packed2 - packed1) / 32;
}
 
Example 14
Source File: TCKWeekFields.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    int dowExpected = (day.get(dowField) - 1) % 7 + 1;
    LocalDate dowDate = day.with(dowField, dowExpected);
    int dowResult = dowDate.get(dowField);
    assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);

    int weekExpected = day.get(wowbyField) + 1;
    ValueRange range = day.range(wowbyField);
    weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
    LocalDate weekDate = day.with(wowbyField, weekExpected);
    int weekResult = weekDate.get(wowbyField);
    assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);

    int yearExpected = day.get(yowbyField) + 1;

    LocalDate yearDate = day.with(yowbyField, yearExpected);
    int yearResult = yearDate.get(yowbyField);
    assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day  + " --> " + yearDate);

    range = yearDate.range(wowbyField);
    weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());

    int weekActual = yearDate.get(wowbyField);
    assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
 
Example 15
Source File: ChronoLocalDateImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private long monthsUntil(ChronoLocalDate end) {
    ValueRange range = getChronology().range(MONTH_OF_YEAR);
    if (range.getMaximum() != 12) {
        throw new IllegalStateException("ChronoLocalDateImpl only supports Chronologies with 12 months per year");
    }
    long packed1 = getLong(PROLEPTIC_MONTH) * 32L + get(DAY_OF_MONTH);  // no overflow
    long packed2 = end.getLong(PROLEPTIC_MONTH) * 32L + end.get(DAY_OF_MONTH);  // no overflow
    return (packed2 - packed1) / 32;
}
 
Example 16
Source File: ChronoLocalDateImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private long monthsUntil(ChronoLocalDate end) {
    ValueRange range = getChronology().range(MONTH_OF_YEAR);
    if (range.getMaximum() != 12) {
        throw new IllegalStateException("ChronoLocalDateImpl only supports Chronologies with 12 months per year");
    }
    long packed1 = getLong(PROLEPTIC_MONTH) * 32L + get(DAY_OF_MONTH);  // no overflow
    long packed2 = end.getLong(PROLEPTIC_MONTH) * 32L + end.get(DAY_OF_MONTH);  // no overflow
    return (packed2 - packed1) / 32;
}
 
Example 17
Source File: ChronoPeriodImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the range of months.
 *
 * @return the month range, -1 if not fixed range
 */
private long monthRange() {
    ValueRange startRange = chrono.range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
        return startRange.getMaximum() - startRange.getMinimum() + 1;
    }
    return -1;
}
 
Example 18
Source File: ChronoPeriodImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the range of months.
 *
 * @return the month range, -1 if not fixed range
 */
private long monthRange() {
    ValueRange startRange = chrono.range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
        return startRange.getMaximum() - startRange.getMinimum() + 1;
    }
    return -1;
}
 
Example 19
Source File: TCKWeekFields.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    int dowExpected = (day.get(dowField) - 1) % 7 + 1;
    LocalDate dowDate = day.with(dowField, dowExpected);
    int dowResult = dowDate.get(dowField);
    assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);

    int weekExpected = day.get(wowbyField) + 1;
    ValueRange range = day.range(wowbyField);
    weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
    LocalDate weekDate = day.with(wowbyField, weekExpected);
    int weekResult = weekDate.get(wowbyField);
    assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);

    int yearExpected = day.get(yowbyField) + 1;

    LocalDate yearDate = day.with(yowbyField, yearExpected);
    int yearResult = yearDate.get(yowbyField);
    assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day  + " --> " + yearDate);

    range = yearDate.range(wowbyField);
    weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());

    int weekActual = yearDate.get(wowbyField);
    assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
 
Example 20
Source File: ChronoLocalDateImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private long monthsUntil(ChronoLocalDate end) {
    ValueRange range = getChronology().range(MONTH_OF_YEAR);
    if (range.getMaximum() != 12) {
        throw new IllegalStateException("ChronoLocalDateImpl only supports Chronologies with 12 months per year");
    }
    long packed1 = getLong(PROLEPTIC_MONTH) * 32L + get(DAY_OF_MONTH);  // no overflow
    long packed2 = end.getLong(PROLEPTIC_MONTH) * 32L + end.get(DAY_OF_MONTH);  // no overflow
    return (packed2 - packed1) / 32;
}