Java Code Examples for java.time.Year#MAX_VALUE

The following examples show how to use java.time.Year#MAX_VALUE . 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: JapaneseChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int prolepticYear(Era era, int yearOfEra) {
    if (era instanceof JapaneseEra == false) {
        throw new ClassCastException("Era must be JapaneseEra");
    }

    JapaneseEra jera = (JapaneseEra) era;
    int gregorianYear = jera.getPrivateEra().getSinceDate().getYear() + yearOfEra - 1;
    if (yearOfEra == 1) {
        return gregorianYear;
    }
    if (gregorianYear >= Year.MIN_VALUE && gregorianYear <= Year.MAX_VALUE) {
        LocalGregorianCalendar.Date jdate = JCAL.newCalendarDate(null);
        jdate.setEra(jera.getPrivateEra()).setDate(yearOfEra, 1, 1);
        if (JapaneseChronology.JCAL.validate(jdate)) {
            return gregorianYear;
        }
    }
    throw new DateTimeException("Invalid yearOfEra value");
}
 
Example 2
Source File: TCKYear.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="goodParseData")
Object[][] provider_goodParseData() {
    return new Object[][] {
            {"0000", Year.of(0)},
            {"9999", Year.of(9999)},
            {"2000", Year.of(2000)},

            {"+12345678", Year.of(12345678)},
            {"+123456", Year.of(123456)},
            {"-1234", Year.of(-1234)},
            {"-12345678", Year.of(-12345678)},

            {"+" + Year.MAX_VALUE, Year.of(Year.MAX_VALUE)},
            {"" + Year.MIN_VALUE, Year.of(Year.MIN_VALUE)},
    };
}
 
Example 3
Source File: TCKZonedDateTime.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void factory_ofInstant_maxWithMinOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MIN.getTotalSeconds());
    ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MIN);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MIN);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
Example 4
Source File: TCKZonedDateTime.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void factory_ofInstant_maxWithMaxOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MAX.getTotalSeconds());
    ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MAX);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MAX);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
Example 5
Source File: TCKYear.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="goodParseData")
Object[][] provider_goodParseData() {
    return new Object[][] {
            {"0000", Year.of(0)},
            {"9999", Year.of(9999)},
            {"2000", Year.of(2000)},

            {"+12345678", Year.of(12345678)},
            {"+123456", Year.of(123456)},
            {"-1234", Year.of(-1234)},
            {"-12345678", Year.of(-12345678)},

            {"+" + Year.MAX_VALUE, Year.of(Year.MAX_VALUE)},
            {"" + Year.MIN_VALUE, Year.of(Year.MIN_VALUE)},
    };
}
 
Example 6
Source File: TestOffsetDateTime_instants.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_tooBig() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    long year = Year.MAX_VALUE + 1L;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
    OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
}
 
Example 7
Source File: TestOffsetDateTime_instants.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void factory_ofInstant_maxWithMaxOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MAX.getTotalSeconds());
    OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MAX);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MAX);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
Example 8
Source File: ZoneRules.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the next transition after the specified instant.
 * <p>
 * This returns details of the next transition after the specified instant.
 * For example, if the instant represents a point where "Summer" daylight savings time
 * applies, then the method will return the transition to the next "Winter" time.
 *
 * @param instant  the instant to get the next transition after, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the next transition after the specified instant, null if this is after the last transition
 */
public ZoneOffsetTransition nextTransition(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return null;
    }
    long epochSec = instant.getEpochSecond();
    // check if using last rules
    if (epochSec >= savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
        if (lastRules.length == 0) {
            return null;
        }
        // search year the instant is in
        int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        for (ZoneOffsetTransition trans : transArray) {
            if (epochSec < trans.toEpochSecond()) {
                return trans;
            }
        }
        // use first from following year
        if (year < Year.MAX_VALUE) {
            transArray = findTransitionArray(year + 1);
            return transArray[0];
        }
        return null;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        index = -index - 1;  // switched value is the next transition
    } else {
        index += 1;  // exact match, so need to add one to get the next
    }
    return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]);
}
 
Example 9
Source File: TestOffsetDateTime_instants.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void factory_ofInstant_maxWithMinOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MIN.getTotalSeconds());
    OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MIN);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MIN);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
Example 10
Source File: ZoneRules.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the next transition after the specified instant.
 * <p>
 * This returns details of the next transition after the specified instant.
 * For example, if the instant represents a point where "Summer" daylight savings time
 * applies, then the method will return the transition to the next "Winter" time.
 *
 * @param instant  the instant to get the next transition after, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the next transition after the specified instant, null if this is after the last transition
 */
public ZoneOffsetTransition nextTransition(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return null;
    }
    long epochSec = instant.getEpochSecond();
    // check if using last rules
    if (epochSec >= savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
        if (lastRules.length == 0) {
            return null;
        }
        // search year the instant is in
        int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        for (ZoneOffsetTransition trans : transArray) {
            if (epochSec < trans.toEpochSecond()) {
                return trans;
            }
        }
        // use first from following year
        if (year < Year.MAX_VALUE) {
            transArray = findTransitionArray(year + 1);
            return transArray[0];
        }
        return null;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        index = -index - 1;  // switched value is the next transition
    } else {
        index += 1;  // exact match, so need to add one to get the next
    }
    return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]);
}
 
Example 11
Source File: TestOffsetDateTime_instants.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void factory_ofInstant_maxWithMaxOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MAX.getTotalSeconds());
    OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MAX);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MAX);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
Example 12
Source File: ZoneRules.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the next transition after the specified instant.
 * <p>
 * This returns details of the next transition after the specified instant.
 * For example, if the instant represents a point where "Summer" daylight savings time
 * applies, then the method will return the transition to the next "Winter" time.
 *
 * @param instant  the instant to get the next transition after, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the next transition after the specified instant, null if this is after the last transition
 */
public ZoneOffsetTransition nextTransition(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return null;
    }
    long epochSec = instant.getEpochSecond();
    // check if using last rules
    if (epochSec >= savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
        if (lastRules.length == 0) {
            return null;
        }
        // search year the instant is in
        int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        for (ZoneOffsetTransition trans : transArray) {
            if (epochSec < trans.toEpochSecond()) {
                return trans;
            }
        }
        // use first from following year
        if (year < Year.MAX_VALUE) {
            transArray = findTransitionArray(year + 1);
            return transArray[0];
        }
        return null;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        index = -index - 1;  // switched value is the next transition
    } else {
        index += 1;  // exact match, so need to add one to get the next
    }
    return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]);
}
 
Example 13
Source File: ZoneRules.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the next transition after the specified instant.
 * <p>
 * This returns details of the next transition after the specified instant.
 * For example, if the instant represents a point where "Summer" daylight savings time
 * applies, then the method will return the transition to the next "Winter" time.
 *
 * @param instant  the instant to get the next transition after, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the next transition after the specified instant, null if this is after the last transition
 */
public ZoneOffsetTransition nextTransition(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return null;
    }
    long epochSec = instant.getEpochSecond();
    // check if using last rules
    if (epochSec >= savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
        if (lastRules.length == 0) {
            return null;
        }
        // search year the instant is in
        int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        for (ZoneOffsetTransition trans : transArray) {
            if (epochSec < trans.toEpochSecond()) {
                return trans;
            }
        }
        // use first from following year
        if (year < Year.MAX_VALUE) {
            transArray = findTransitionArray(year + 1);
            return transArray[0];
        }
        return null;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        index = -index - 1;  // switched value is the next transition
    } else {
        index += 1;  // exact match, so need to add one to get the next
    }
    return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]);
}
 
Example 14
Source File: TCKLocalDate.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_plusYears_long_big() {
    long years = 20L + Year.MAX_VALUE;
    LocalDate test = LocalDate.of(-40, 6, 1).plusYears(years);
    assertEquals(test, LocalDate.of((int) (-40L + years), 6, 1));
}
 
Example 15
Source File: TCKYear.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_minusYears_big() {
    long years = 20L + Year.MAX_VALUE;
    assertEquals(Year.of(40).minusYears(years), Year.of((int) (40L - years)));
}
 
Example 16
Source File: TCKLocalDate.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_minusYears_long_big() {
    long years = 20L + Year.MAX_VALUE;
    LocalDate test = LocalDate.of(40, 6, 1).minusYears(years);
    assertEquals(test, LocalDate.of((int) (40L - years), 6, 1));
}
 
Example 17
Source File: TCKYear.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_plusYears_big() {
    long years = 20L + Year.MAX_VALUE;
    assertEquals(Year.of(-40).plusYears(years), Year.of((int) (-40L + years)));
}
 
Example 18
Source File: TCKYear.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test
public void test_plusYears_big() {
    long years = 20L + Year.MAX_VALUE;
    assertEquals(Year.of(-40).plusYears(years), Year.of((int) (-40L + years)));
}
 
Example 19
Source File: TCKYear.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_plusYears_big() {
    long years = 20L + Year.MAX_VALUE;
    assertEquals(Year.of(-40).plusYears(years), Year.of((int) (-40L + years)));
}
 
Example 20
Source File: TCKLocalDate.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_plusYears_long_big() {
    long years = 20L + Year.MAX_VALUE;
    LocalDate test = LocalDate.of(-40, 6, 1).plusYears(years);
    assertEquals(test, LocalDate.of((int) (-40L + years), 6, 1));
}