Java Code Examples for java.time.Year

The following are top voted examples for showing how to use java.time.Year. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: uroborosql   File: DateTimeApiPropertyMapper.java   Source Code and License 7 votes vote down vote up
@Override
public boolean canAccept(final Class<?> type) {
	return LocalDateTime.class.equals(type)
			|| OffsetDateTime.class.equals(type)
			|| ZonedDateTime.class.equals(type)
			|| LocalDate.class.equals(type)
			|| LocalTime.class.equals(type)
			|| OffsetTime.class.equals(type)
			|| Year.class.equals(type)
			|| YearMonth.class.equals(type)
			|| MonthDay.class.equals(type)
			|| Month.class.equals(type)
			|| DayOfWeek.class.equals(type)
			|| checkEra(type)
			|| checkChronoLocalDate(type);
}
 
Example 2
Project: CalendarFX   File: YearMonthViewSkin.java   Source Code and License 6 votes vote down vote up
private void updateHyerlinkSupport() {
    final YearMonthView view = getSkinnable();

    if (view.isEnableHyperlinks()) {
        monthLabel.setOnMouseClicked(evt -> {
            if (evt.getClickCount() == 1) {
                view.fireEvent(new RequestEvent(view, view, getSkinnable().getYearMonth()));
            }
        });

        yearLabel.setOnMouseClicked(evt -> {
            if (evt.getClickCount() == 1) {
                view.fireEvent(new RequestEvent(view, view, Year.of(getSkinnable().getYearMonth().getYear())));
            }
        });
    } else {
        monthLabel.setOnMouseClicked(null);
        yearLabel.setOnMouseClicked(null);
    }
}
 
Example 3
Project: openjdk-jdk10   File: TCKYear.java   Source Code and License 6 votes vote down vote up
@Test
public void test_with() {
    Year base = Year.of(5);
    Year result = base.with(ChronoField.ERA, 0);
    assertEquals(result, base.with(IsoEra.of(0)));

    int prolepticYear = IsoChronology.INSTANCE.prolepticYear(IsoEra.of(0), 5);
    assertEquals(result.get(ChronoField.ERA), 0);
    assertEquals(result.get(ChronoField.YEAR), prolepticYear);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 5);

    result = base.with(ChronoField.YEAR, 10);
    assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA));
    assertEquals(result.get(ChronoField.YEAR), 10);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 10);

    result = base.with(ChronoField.YEAR_OF_ERA, 20);
    assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA));
    assertEquals(result.get(ChronoField.YEAR), 20);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 20);
}
 
Example 4
Project: openjdk-jdk10   File: CopticDate.java   Source Code and License 6 votes vote down vote up
@Override
public ValueRange range(TemporalField field) {
    if (field instanceof ChronoField) {
        if (isSupported(field)) {
            ChronoField f = (ChronoField) field;
            switch (f) {
                case DAY_OF_MONTH: return ValueRange.of(1, lengthOfMonth());
                case DAY_OF_YEAR: return ValueRange.of(1, lengthOfYear());
                case ALIGNED_WEEK_OF_MONTH: return ValueRange.of(1, month == 13 ? 1 : 5);
                case YEAR:
                case YEAR_OF_ERA: return (prolepticYear <= 0 ?
                        ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE));  // TODO
            }
            return getChronology().range(f);
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.rangeRefinedBy(this);
}
 
Example 5
Project: jdk8u-jdk   File: TCKLocalDate.java   Source Code and License 6 votes vote down vote up
@Test
public void factory_ofEpochDay() {
    long date_0000_01_01 = -678941 - 40587;
    assertEquals(LocalDate.ofEpochDay(0), LocalDate.of(1970, 1, 1));
    assertEquals(LocalDate.ofEpochDay(date_0000_01_01), LocalDate.of(0, 1, 1));
    assertEquals(LocalDate.ofEpochDay(date_0000_01_01 - 1), LocalDate.of(-1, 12, 31));
    assertEquals(LocalDate.ofEpochDay(MAX_VALID_EPOCHDAYS), LocalDate.of(Year.MAX_VALUE, 12, 31));
    assertEquals(LocalDate.ofEpochDay(MIN_VALID_EPOCHDAYS), LocalDate.of(Year.MIN_VALUE, 1, 1));

    LocalDate test = LocalDate.of(0, 1, 1);
    for (long i = date_0000_01_01; i < 700000; i++) {
        assertEquals(LocalDate.ofEpochDay(i), test);
        test = next(test);
    }
    test = LocalDate.of(0, 1, 1);
    for (long i = date_0000_01_01; i > -2000000; i--) {
        assertEquals(LocalDate.ofEpochDay(i), test);
        test = previous(test);
    }
}
 
Example 6
Project: openjdk-jdk10   File: TCKZonedDateTime.java   Source Code and License 6 votes vote down vote up
@Test
public void factory_ofInstant_minWithMaxOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MIN_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L - OFFSET_MAX.getTotalSeconds());
    ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MAX);
    assertEquals(test.getYear(), Year.MIN_VALUE);
    assertEquals(test.getMonth().getValue(), 1);
    assertEquals(test.getDayOfMonth(), 1);
    assertEquals(test.getOffset(), OFFSET_MAX);
    assertEquals(test.getHour(), 0);
    assertEquals(test.getMinute(), 0);
    assertEquals(test.getSecond(), 0);
    assertEquals(test.getNano(), 0);
}
 
Example 7
Project: bson-codecs-jsr310   File: YearCodec.java   Source Code and License 5 votes vote down vote up
@Override
public void encode(
        BsonWriter writer,
        Year value,
        EncoderContext encoderContext) {

    writer.writeInt32(value.getValue());
}
 
Example 8
Project: nitmproxy   File: CertUtil.java   Source Code and License 5 votes vote down vote up
public static Certificate newCert(String parentCertFile, String keyFile, String host) {
    try {
        Date before = Date.from(Instant.now());
        Date after = Date.from(Year.now().plus(3, ChronoUnit.YEARS).atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant());

        X509CertificateHolder parent = readPemFromFile(parentCertFile);
        PEMKeyPair pemKeyPair = readPemFromFile(keyFile);
        KeyPair keyPair = new JcaPEMKeyConverter()
                .setProvider(PROVIDER)
                .getKeyPair(pemKeyPair);

        X509v3CertificateBuilder x509 = new JcaX509v3CertificateBuilder(
                parent.getSubject(),
                new BigInteger(64, new SecureRandom()),
                before,
                after,
                new X500Name("CN=" + host),
                keyPair.getPublic());

        ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption")
                .build(keyPair.getPrivate());

        JcaX509CertificateConverter x509CertificateConverter = new JcaX509CertificateConverter()
                .setProvider(PROVIDER);

        return new Certificate(
                keyPair,
                x509CertificateConverter.getCertificate(x509.build(signer)),
                x509CertificateConverter.getCertificate(parent));
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example 9
Project: openjdk-jdk10   File: TCKZonedDateTime.java   Source Code and License 5 votes vote down vote up
@Test
public void test_with_adjuster_Year() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.with(Year.of(2007));
    assertEquals(test, ZonedDateTime.of(ldt.withYear(2007), ZONE_0100));
}
 
Example 10
Project: maven-release-yearly-policy   File: YearlyVersionPolicyTest.java   Source Code and License 5 votes vote down vote up
@Test
public void shouldUseFirstVersionOfYearWhenVersionNotInYearlyFormat() throws Exception {
    testee = new YearlyVersionPolicy(Year.of(2017));

    result = testee.getDevelopmentVersion(version("1.2.3"));

    assertThat(result.getVersion(), is("2017.1-SNAPSHOT"));
}
 
Example 11
Project: jdk8u-jdk   File: TCKMinguoChronology.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());

    MinguoDate minguo = MinguoDate.now();
    minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(minguo.lengthOfMonth(), 29);
    } else {
        assertEquals(minguo.lengthOfMonth(), 28);
    }
}
 
Example 12
Project: OpenJSharp   File: ZoneRules.java   Source Code and License 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
Project: openjdk-jdk10   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="minus_long_TemporalUnit")
public void test_minus_long_TemporalUnit(Year base, long amount, TemporalUnit unit, Year expectedYear, Class<?> expectedEx) {
    if (expectedEx == null) {
        assertEquals(base.minus(amount, unit), expectedYear);
    } else {
        try {
            Year result = base.minus(amount, unit);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 14
Project: openjdk-jdk10   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@Test
public void test_factory_int_singleton() {
    for (int i = -4; i <= 2104; i++) {
        Year test = Year.of(i);
        assertEquals(test.getValue(), i);
        assertEquals(Year.of(i), test);
    }
}
 
Example 15
Project: openjdk-jdk10   File: TCKMinguoChronology.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());

    MinguoDate minguo = MinguoDate.now();
    minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(minguo.lengthOfMonth(), 29);
    } else {
        assertEquals(minguo.lengthOfMonth(), 28);
    }
}
 
Example 16
Project: openjdk-jdk10   File: TestDateTimeFormatter.java   Source Code and License 5 votes vote down vote up
@Test
public void test_parse_errorMessage() throws Exception {
    assertGoodErrorDate(DayOfWeek::from, "DayOfWeek");
    assertGoodErrorDate(Month::from, "Month");
    assertGoodErrorDate(YearMonth::from, "YearMonth");
    assertGoodErrorDate(MonthDay::from, "MonthDay");
    assertGoodErrorDate(LocalDate::from, "LocalDate");
    assertGoodErrorDate(LocalTime::from, "LocalTime");
    assertGoodErrorDate(LocalDateTime::from, "LocalDateTime");
    assertGoodErrorDate(OffsetTime::from, "OffsetTime");
    assertGoodErrorDate(OffsetDateTime::from, "OffsetDateTime");
    assertGoodErrorDate(ZonedDateTime::from, "ZonedDateTime");
    assertGoodErrorDate(Instant::from, "Instant");
    assertGoodErrorDate(ZoneOffset::from, "ZoneOffset");
    assertGoodErrorDate(ZoneId::from, "ZoneId");
    assertGoodErrorDate(ThaiBuddhistChronology.INSTANCE::date, "");

    assertGoodErrorTime(DayOfWeek::from, "DayOfWeek");
    assertGoodErrorTime(Month::from, "Month");
    assertGoodErrorTime(Year::from, "Year");
    assertGoodErrorTime(YearMonth::from, "YearMonth");
    assertGoodErrorTime(MonthDay::from, "MonthDay");
    assertGoodErrorTime(LocalDate::from, "LocalDate");
    assertGoodErrorTime(LocalTime::from, "LocalTime");
    assertGoodErrorTime(LocalDateTime::from, "LocalDateTime");
    assertGoodErrorTime(OffsetTime::from, "OffsetTime");
    assertGoodErrorTime(OffsetDateTime::from, "OffsetDateTime");
    assertGoodErrorTime(ZonedDateTime::from, "ZonedDateTime");
    assertGoodErrorTime(Instant::from, "Instant");
    assertGoodErrorTime(ZoneOffset::from, "ZoneOffset");
    assertGoodErrorTime(ZoneId::from, "ZoneId");
    assertGoodErrorTime(ThaiBuddhistChronology.INSTANCE::date, "");
}
 
Example 17
Project: jdk8u-jdk   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@Test
public void now_Clock() {
    Instant instant = OffsetDateTime.of(LocalDate.of(2010, 12, 31), LocalTime.of(0, 0), ZoneOffset.UTC).toInstant();
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    Year test = Year.now(clock);
    assertEquals(test.getValue(), 2010);
}
 
Example 18
Project: openjdk-jdk10   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@Test
public void test_atDay_notLeapYear() {
    Year test = Year.of(2007);
    LocalDate expected = LocalDate.of(2007, 1, 1);
    for (int i = 1; i <= 365; i++) {
        assertEquals(test.atDay(i), expected);
        expected = expected.plusDays(1);
    }
}
 
Example 19
Project: openjdk-jdk10   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="badParseData", expectedExceptions=DateTimeParseException.class)
public void factory_parse_fail(String text, int pos) {
    try {
        Year.parse(text);
        fail(String.format("Parse should have failed for %s at position %d", text, pos));
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getParsedString(), text);
        assertEquals(ex.getErrorIndex(), pos);
        throw ex;
    }
}
 
Example 20
Project: jdk8u-jdk   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="badParseData", expectedExceptions=DateTimeParseException.class)
public void factory_parse_fail(String text, int pos) {
    try {
        Year.parse(text);
        fail(String.format("Parse should have failed for %s at position %d", text, pos));
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getParsedString(), text);
        assertEquals(ex.getErrorIndex(), pos);
        throw ex;
    }
}
 
Example 21
Project: maven-release-yearly-policy   File: YearlyVersionPolicyTest.java   Source Code and License 5 votes vote down vote up
@Test
public void shouldGoToNextMinorVersionWhenExtraSubVersionsPresent() throws Exception {
    testee = new YearlyVersionPolicy(Year.of(2017));

    result = testee.getDevelopmentVersion(version("2017.3.2.1"));

    assertThat(result.getVersion(), is("2017.3.2.2-SNAPSHOT"));
}
 
Example 22
Project: openjdk-jdk10   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@DataProvider(name="isValidMonthDay")
Object[][] data_isValidMonthDay() {
    return new Object[][] {
            {Year.of(2007), MonthDay.of(6, 30), true},
            {Year.of(2008), MonthDay.of(2, 28), true},
            {Year.of(2008), MonthDay.of(2, 29), true},
            {Year.of(2009), MonthDay.of(2, 28), true},
            {Year.of(2009), MonthDay.of(2, 29), false},
            {Year.of(2009), null, false},
    };
}
 
Example 23
Project: openjdk-jdk10   File: TestOffsetDateTime_instants.java   Source Code and License 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 24
Project: git-rekt   File: BookingsReportScreenController.java   Source Code and License 5 votes vote down vote up
/**
 * This method is a little weird, but necessary, due to the quirks of JavaFX charts.
 *
 * Essentially, the problem boils down to the fact that JavaFX charts cannot cleanly handle
 * an integer based axis in exactly the way we need them to, so we have to hack around it by
 * using categories whose names just happen to be the integer days of the month.
 */
private void prepareXAxis() {
    int selectedYear = selectedMonth.getYear();
    int numDaysInMonth = selectedMonth.getMonth().length(Year.isLeap(selectedYear));
    for(int i = 1; i <= numDaysInMonth; i++) {
        daysInCurrentMonth.add(String.valueOf(i));
    }
    CategoryAxis xAxis  = (CategoryAxis) lineChart.getXAxis();
    xAxis.setCategories(daysInCurrentMonth);
}
 
Example 25
Project: openjdk-jdk10   File: TzdbZoneRulesProvider.java   Source Code and License 5 votes vote down vote up
int parseYear(String year, int defaultYear) {
    switch (year.toLowerCase()) {
    case "min":  return 1900;
    case "max":  return Year.MAX_VALUE;
    case "only": return defaultYear;
    }
    return Integer.parseInt(year);
}
 
Example 26
Project: jdk8u-jdk   File: TCKYear.java   Source Code and License 5 votes vote down vote up
@Test(dataProvider="plus_long_TemporalUnit")
public void test_plus_long_TemporalUnit(Year base, long amount, TemporalUnit unit, Year expectedYear, Class<?> expectedEx) {
    if (expectedEx == null) {
        assertEquals(base.plus(amount, unit), expectedYear);
    } else {
        try {
            base.plus(amount, unit);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example 27
Project: jdk8u-jdk   File: TestDateTimeFormatter.java   Source Code and License 5 votes vote down vote up
@Test
public void test_parse_errorMessage() throws Exception {
    assertGoodErrorDate(DayOfWeek::from, "DayOfWeek");
    assertGoodErrorDate(Month::from, "Month");
    assertGoodErrorDate(YearMonth::from, "YearMonth");
    assertGoodErrorDate(MonthDay::from, "MonthDay");
    assertGoodErrorDate(LocalDate::from, "LocalDate");
    assertGoodErrorDate(LocalTime::from, "LocalTime");
    assertGoodErrorDate(LocalDateTime::from, "LocalDateTime");
    assertGoodErrorDate(OffsetTime::from, "OffsetTime");
    assertGoodErrorDate(OffsetDateTime::from, "OffsetDateTime");
    assertGoodErrorDate(ZonedDateTime::from, "ZonedDateTime");
    assertGoodErrorDate(Instant::from, "Instant");
    assertGoodErrorDate(ZoneOffset::from, "ZoneOffset");
    assertGoodErrorDate(ZoneId::from, "ZoneId");
    assertGoodErrorDate(ThaiBuddhistChronology.INSTANCE::date, "");

    assertGoodErrorTime(DayOfWeek::from, "DayOfWeek");
    assertGoodErrorTime(Month::from, "Month");
    assertGoodErrorTime(Year::from, "Year");
    assertGoodErrorTime(YearMonth::from, "YearMonth");
    assertGoodErrorTime(MonthDay::from, "MonthDay");
    assertGoodErrorTime(LocalDate::from, "LocalDate");
    assertGoodErrorTime(LocalTime::from, "LocalTime");
    assertGoodErrorTime(LocalDateTime::from, "LocalDateTime");
    assertGoodErrorTime(OffsetTime::from, "OffsetTime");
    assertGoodErrorTime(OffsetDateTime::from, "OffsetDateTime");
    assertGoodErrorTime(ZonedDateTime::from, "ZonedDateTime");
    assertGoodErrorTime(Instant::from, "Instant");
    assertGoodErrorTime(ZoneOffset::from, "ZoneOffset");
    assertGoodErrorTime(ZoneId::from, "ZoneId");
    assertGoodErrorTime(ThaiBuddhistChronology.INSTANCE::date, "");
}
 
Example 28
Project: maven-release-yearly-policy   File: YearlyVersionPolicyTest.java   Source Code and License 5 votes vote down vote up
@Test
public void shouldDefaultToFirstReleaseOfYearOnNonsenseVersion() throws Exception {
    testee = new YearlyVersionPolicy(Year.of(2017));

    result = testee.getDevelopmentVersion(version("This doesn't look like a version"));

    assertThat(result.getVersion(), is("2017.1-SNAPSHOT"));
}
 
Example 29
Project: openjdk-jdk10   File: TCKLocalDateTime.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_withYear_int_invalid() {
    TEST_2007_07_15_12_30_40_987654321.withYear(Year.MIN_VALUE - 1);
}
 
Example 30
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_withYear_tooHigh() {
    YearMonth test = YearMonth.of(2008, 6);
    test.withYear(Year.MAX_VALUE + 1);
}
 
Example 31
Project: jdk8u-jdk   File: TCKLocalDate.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 32
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions={DateTimeException.class})
public void test_minusMonths_long_invalidTooLarge() {
    YearMonth test = YearMonth.of(Year.MAX_VALUE, 12);
    test.minusMonths(-1);
}
 
Example 33
Project: jdk8u-jdk   File: TCKYear.java   Source Code and License 4 votes vote down vote up
@Test(dataProvider="isValidMonthDay")
public void test_isValidMonthDay(Year year, MonthDay monthDay, boolean expected) {
    assertEquals(year.isValidMonthDay(monthDay), expected);
}
 
Example 34
Project: jdk8u-jdk   File: TCKZoneRules.java   Source Code and License 4 votes vote down vote up
public void test_London_nextTransition_lastYear() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    ZoneOffsetTransition zot = rules.get(1).createTransition(Year.MAX_VALUE);
    assertEquals(test.nextTransition(zot.getInstant()), null);
}
 
Example 35
Project: openjdk-jdk10   File: TCKLocalDateTime.java   Source Code and License 4 votes vote down vote up
@Test
public void constant_MIN() {
    check(LocalDateTime.MIN, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
}
 
Example 36
Project: jdk8u-jdk   File: TCKLocalDateTime.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusWeeks_invalidTooSmall() {
    createDateMidnight(Year.MIN_VALUE, 1, 7).minusWeeks(1);
}
 
Example 37
Project: jdk8u-jdk   File: TestIsoWeekFields.java   Source Code and License 4 votes vote down vote up
@Test(dataProvider = "fields")
public void test_WBY_rangeRefinedBy(TemporalField weekField, TemporalField yearField) {
    assertEquals(yearField.rangeRefinedBy(LocalDate.of(2012, 12, 31)), ValueRange.of(Year.MIN_VALUE, Year.MAX_VALUE));
}
 
Example 38
Project: jdk8u-jdk   File: TCKLocalDate.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_plusYears_long_invalidTooSmall_invalidInt() {
    LocalDate.of(Year.MIN_VALUE, 1, 1).plusYears(-10);
}
 
Example 39
Project: openjdk-jdk10   File: TCKLocalDateTime.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_plusMonths_int_invalidTooLarge() {
    createDateMidnight(Year.MAX_VALUE, 12, 1).plusMonths(1);
}
 
Example 40
Project: openjdk-jdk10   File: TCKLocalDateTime.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minus_TemporalAmount_invalidTooSmall() {
    MockSimplePeriod period = MockSimplePeriod.of(1, YEARS);
    LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(period);
}