java.time.MonthDay Java Examples

The following examples show how to use java.time.MonthDay. 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: TCKMonthDay.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void doTest_comparisons_MonthDay(MonthDay... localDates) {
    for (int i = 0; i < localDates.length; i++) {
        MonthDay a = localDates[i];
        for (int j = 0; j < localDates.length; j++) {
            MonthDay b = localDates[j];
            if (i < j) {
                assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), true, a + " <=> " + b);
                assertEquals(a.isAfter(b), false, a + " <=> " + b);
                assertEquals(a.equals(b), false, a + " <=> " + b);
            } else if (i > j) {
                assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), false, a + " <=> " + b);
                assertEquals(a.isAfter(b), true, a + " <=> " + b);
                assertEquals(a.equals(b), false, a + " <=> " + b);
            } else {
                assertEquals(a.compareTo(b), 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), false, a + " <=> " + b);
                assertEquals(a.isAfter(b), false, a + " <=> " + b);
                assertEquals(a.equals(b), true, a + " <=> " + b);
            }
        }
    }
}
 
Example #2
Source File: TestMonthDay.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
void doTest_comparisons_MonthDay(MonthDay... localDates) {
    for (int i = 0; i < localDates.length; i++) {
        MonthDay a = localDates[i];
        for (int j = 0; j < localDates.length; j++) {
            MonthDay b = localDates[j];
            if (i < j) {
                assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), true, a + " <=> " + b);
                assertEquals(a.isAfter(b), false, a + " <=> " + b);
                assertEquals(a.equals(b), false, a + " <=> " + b);
            } else if (i > j) {
                assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), false, a + " <=> " + b);
                assertEquals(a.isAfter(b), true, a + " <=> " + b);
                assertEquals(a.equals(b), false, a + " <=> " + b);
            } else {
                assertEquals(a.compareTo(b), 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), false, a + " <=> " + b);
                assertEquals(a.isAfter(b), false, a + " <=> " + b);
                assertEquals(a.equals(b), true, a + " <=> " + b);
            }
        }
    }
}
 
Example #3
Source File: TestMonthDay.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
void doTest_comparisons_MonthDay(MonthDay... localDates) {
    for (int i = 0; i < localDates.length; i++) {
        MonthDay a = localDates[i];
        for (int j = 0; j < localDates.length; j++) {
            MonthDay b = localDates[j];
            if (i < j) {
                assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), true, a + " <=> " + b);
                assertEquals(a.isAfter(b), false, a + " <=> " + b);
                assertEquals(a.equals(b), false, a + " <=> " + b);
            } else if (i > j) {
                assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), false, a + " <=> " + b);
                assertEquals(a.isAfter(b), true, a + " <=> " + b);
                assertEquals(a.equals(b), false, a + " <=> " + b);
            } else {
                assertEquals(a.compareTo(b), 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), false, a + " <=> " + b);
                assertEquals(a.isAfter(b), false, a + " <=> " + b);
                assertEquals(a.equals(b), true, a + " <=> " + b);
            }
        }
    }
}
 
Example #4
Source File: TestIsoWeekFields.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "fields")
public void test_WOWBY_isSupportedBy(TemporalField weekField, TemporalField yearField) {
    assertEquals(weekField.isSupportedBy(LocalTime.NOON), false);
    assertEquals(weekField.isSupportedBy(MonthDay.of(2, 1)), false);
    assertEquals(weekField.isSupportedBy(LocalDate.MIN), true);
    assertEquals(weekField.isSupportedBy(OffsetDateTime.MAX), true);
}
 
Example #5
Source File: TCKMonthDay.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="badParseData", expectedExceptions=DateTimeParseException.class)
public void factory_parse_fail(String text, int pos) {
    try {
        MonthDay.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 #6
Source File: TCKMonthDay.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_hashCode_unique() {
    int leapYear = 2008;
    Set<Integer> uniques = new HashSet<Integer>(366);
    for (int i = 1; i <= 12; i++) {
        for (int j = 1; j <= 31; j++) {
            if (YearMonth.of(leapYear, i).isValidDay(j)) {
                assertTrue(uniques.add(MonthDay.of(i, j).hashCode()));
            }
        }
    }
}
 
Example #7
Source File: TestIsoWeekFields.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "fields")
public void test_WOWBY_isSupportedBy(TemporalField weekField, TemporalField yearField) {
    assertEquals(weekField.isSupportedBy(LocalTime.NOON), false);
    assertEquals(weekField.isSupportedBy(MonthDay.of(2, 1)), false);
    assertEquals(weekField.isSupportedBy(LocalDate.MIN), true);
    assertEquals(weekField.isSupportedBy(OffsetDateTime.MAX), true);
}
 
Example #8
Source File: TestDateTimeFormatter.java    From hottub with GNU General Public License v2.0 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 #9
Source File: TCKYear.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="atMonthDay")
Object[][] data_atMonthDay() {
    return new Object[][] {
            {Year.of(2008), MonthDay.of(6, 30), LocalDate.of(2008, 6, 30)},
            {Year.of(2008), MonthDay.of(2, 29), LocalDate.of(2008, 2, 29)},
            {Year.of(2009), MonthDay.of(2, 29), LocalDate.of(2009, 2, 28)},
    };
}
 
Example #10
Source File: TCKMonthDay.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="goodParseData")
Object[][] provider_goodParseData() {
    return new Object[][] {
            {"--01-01", MonthDay.of(1, 1)},
            {"--01-31", MonthDay.of(1, 31)},
            {"--02-01", MonthDay.of(2, 1)},
            {"--02-29", MonthDay.of(2, 29)},
            {"--03-01", MonthDay.of(3, 1)},
            {"--03-31", MonthDay.of(3, 31)},
            {"--04-01", MonthDay.of(4, 1)},
            {"--04-30", MonthDay.of(4, 30)},
            {"--05-01", MonthDay.of(5, 1)},
            {"--05-31", MonthDay.of(5, 31)},
            {"--06-01", MonthDay.of(6, 1)},
            {"--06-30", MonthDay.of(6, 30)},
            {"--07-01", MonthDay.of(7, 1)},
            {"--07-31", MonthDay.of(7, 31)},
            {"--08-01", MonthDay.of(8, 1)},
            {"--08-31", MonthDay.of(8, 31)},
            {"--09-01", MonthDay.of(9, 1)},
            {"--09-30", MonthDay.of(9, 30)},
            {"--10-01", MonthDay.of(10, 1)},
            {"--10-31", MonthDay.of(10, 31)},
            {"--11-01", MonthDay.of(11, 1)},
            {"--11-30", MonthDay.of(11, 30)},
            {"--12-01", MonthDay.of(12, 1)},
            {"--12-31", MonthDay.of(12, 31)},
    };
}
 
Example #11
Source File: TCKMonthDaySerialization.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_serialization_format() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (DataOutputStream dos = new DataOutputStream(baos) ) {
        dos.writeByte(13);       // java.time.temporal.Ser.MONTH_DAY_TYPE
        dos.writeByte(9);
        dos.writeByte(16);
    }
    byte[] bytes = baos.toByteArray();
    assertSerializedBySer(MonthDay.of(9, 16), bytes);
}
 
Example #12
Source File: TCKMonthDay.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_invalidValue_Day() {
    MonthDay.parse("--06-31");
}
 
Example #13
Source File: TCKMonthDay.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_isValidYear_febLeap() {
    MonthDay test = MonthDay.of(2, 29);
    assertEquals(test.isValidYear(2008), true);
}
 
Example #14
Source File: TCKMonthDay.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_nullText() {
    MonthDay.parse(null);
}
 
Example #15
Source File: TCKYear.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonthDay_nullMonthDay() {
    Year test = Year.of(2008);
    test.atMonthDay((MonthDay) null);
}
 
Example #16
Source File: TCKMonthDay.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void factory_parse_nullText() {
    MonthDay.parse(null);
}
 
Example #17
Source File: TCKMonthDay.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalValue_Month() {
    MonthDay.parse("--13-25");
}
 
Example #18
Source File: TCKMonthDay.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalValue_Day() {
    MonthDay.parse("--06-32");
}
 
Example #19
Source File: TCKMonthDay.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test
public void test_with_Month_adjustToValidFeb() {
    assertEquals(MonthDay.of(7, 31).with(Month.FEBRUARY), MonthDay.of(2, 29));
}
 
Example #20
Source File: TCKMonthDay.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
    MonthDay.parse((String) null, f);
}
 
Example #21
Source File: TCKMonthDay.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_isValidYear_febNonLeap() {
    MonthDay test = MonthDay.of(2, 29);
    assertEquals(test.isValidYear(2007), false);
}
 
Example #22
Source File: TCKMonthDay.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_with_Month_null() {
    MonthDay.of(6, 30).with((Month) null);
}
 
Example #23
Source File: TCKMonthDay.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_with_Month() {
    assertEquals(MonthDay.of(6, 30).with(Month.JANUARY), MonthDay.of(1, 30));
}
 
Example #24
Source File: TCKMonthDay.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_withDayOfMonth_tooLow() {
    MonthDay.of(6, 30).withDayOfMonth(0);
}
 
Example #25
Source File: TCKMonthDay.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_with_Month_adjustToValidFeb() {
    assertEquals(MonthDay.of(7, 31).with(Month.FEBRUARY), MonthDay.of(2, 29));
}
 
Example #26
Source File: TCKMonthDay.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
    MonthDay.parse("ANY", null);
}
 
Example #27
Source File: TCKMonthDay.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_ints_monthTooLow() {
    MonthDay.of(0, 1);
}
 
Example #28
Source File: MonthDaySchema.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
@Override
public MonthDay newMessage() {
    return MonthDay.of(1, 1);
}
 
Example #29
Source File: TCKYear.java    From openjdk-8-source with GNU General Public License v2.0 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 #30
Source File: TestMonthDay.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_adjustDate_same() {
    MonthDay test = MonthDay.of(6, 30);
    LocalDate date = LocalDate.of(2007, 6, 30);
    assertSame(test.adjustInto(date), date);
}