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

The following examples show how to use java.time.temporal.ValueRange#checkValidIntValue() . 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: AbstractChronology.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
    }
    int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
    ValueRange domRange = range(DAY_OF_MONTH);
    int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        try {
            return date(y, moy, dom);
        } catch (DateTimeException ex) {
            return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
        }
    }
    return date(y, moy, dom);
}
 
Example 2
Source File: AbstractChronology.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
    }
    int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
    ValueRange domRange = range(DAY_OF_MONTH);
    int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        try {
            return date(y, moy, dom);
        } catch (DateTimeException ex) {
            return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
        }
    }
    return date(y, moy, dom);
}
 
Example 3
Source File: AbstractChronology.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
    }
    int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
    ValueRange domRange = range(DAY_OF_MONTH);
    int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        try {
            return date(y, moy, dom);
        } catch (DateTimeException ex) {
            return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
        }
    }
    return date(y, moy, dom);
}
 
Example 4
Source File: AbstractChronology.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
    }
    int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
    ValueRange domRange = range(DAY_OF_MONTH);
    int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        try {
            return date(y, moy, dom);
        } catch (DateTimeException ex) {
            return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
        }
    }
    return date(y, moy, dom);
}
 
Example 5
Source File: TestDateTimeValueRange.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueInvalid_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(Integer.MAX_VALUE + 2L, (ChronoField)null);
}
 
Example 6
Source File: TestDateTimeValueRange.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="valid", expectedExceptions = DateTimeException.class)
public void test_of_checkValidValueMinException(long sMin, long lMin, long sMax, long lMax) {
    ValueRange test = ValueRange.of(sMin, lMin, sMax, lMax);
    test.checkValidIntValue(sMin-1, null);
}
 
Example 7
Source File: TestDateTimeValueRange.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueUnsupported_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(0, (ChronoField)null);
}
 
Example 8
Source File: TestDateTimeValueRange.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueUnsupported_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(0, (ChronoField)null);
}
 
Example 9
Source File: TestDateTimeValueRange.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueInvalid_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(Integer.MAX_VALUE + 2L, (ChronoField)null);
}
 
Example 10
Source File: TestDateTimeValueRange.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueInvalid_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(Integer.MAX_VALUE + 2L, (ChronoField)null);
}
 
Example 11
Source File: TestDateTimeValueRange.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="valid", expectedExceptions = DateTimeException.class)
public void test_of_checkValidValueMinException(long sMin, long lMin, long sMax, long lMax) {
    ValueRange test = ValueRange.of(sMin, lMin, sMax, lMax);
    test.checkValidIntValue(sMin-1, null);
}
 
Example 12
Source File: TestDateTimeValueRange.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueInvalid_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(Integer.MAX_VALUE + 2L, (ChronoField)null);
}
 
Example 13
Source File: TestDateTimeValueRange.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="valid", expectedExceptions = DateTimeException.class)
public void test_of_checkValidValueMinException(long sMin, long lMin, long sMax, long lMax) {
    ValueRange test = ValueRange.of(sMin, lMin, sMax, lMax);
    test.checkValidIntValue(sMin-1, null);
}
 
Example 14
Source File: TestDateTimeValueRange.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="valid", expectedExceptions = DateTimeException.class)
public void test_of_checkValidValueMinException(long sMin, long lMin, long sMax, long lMax) {
    ValueRange test = ValueRange.of(sMin, lMin, sMax, lMax);
    test.checkValidIntValue(sMin-1, null);
}
 
Example 15
Source File: TestDateTimeValueRange.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="valid", expectedExceptions = DateTimeException.class)
public void test_of_checkValidValueMaxException(long sMin, long lMin, long sMax, long lMax) {
    ValueRange test = ValueRange.of(sMin, lMin, sMax, lMax);
    test.checkValidIntValue(lMax+1, null);
}
 
Example 16
Source File: TestDateTimeValueRange.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueInvalid_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(Integer.MAX_VALUE + 2L, (ChronoField)null);
}
 
Example 17
Source File: TestDateTimeValueRange.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="valid", expectedExceptions = DateTimeException.class)
public void test_of_checkValidValueMinException(long sMin, long lMin, long sMax, long lMax) {
    ValueRange test = ValueRange.of(sMin, lMin, sMax, lMax);
    test.checkValidIntValue(sMin-1, null);
}
 
Example 18
Source File: TestDateTimeValueRange.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueInvalid_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(Integer.MAX_VALUE + 2L, (ChronoField)null);
}
 
Example 19
Source File: TestDateTimeValueRange.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueInvalid_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(Integer.MAX_VALUE + 2L, (ChronoField)null);
}
 
Example 20
Source File: TestDateTimeValueRange.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DateTimeException.class)
public void test_checkValidValueUnsupported_long_long() {
    ValueRange test = ValueRange.of(1, 28, Integer.MAX_VALUE + 1L);
    test.checkValidIntValue(0, (ChronoField)null);
}