Java 类java.time.YearMonth 实例源码

项目:simter-jxls-ext    文件:JxlsUtilsTest.java   
private Map<String, Object> generateData() {
  Map<String, Object> data = new HashMap<>();
  data.put("stage", 0);
  Map<Integer, Object> stageLabels = new HashMap<>();
  stageLabels.put(0, "TODO");
  stageLabels.put(1, "ALLOW");
  data.put("stageLabels", stageLabels);

  List<Map<String, Object>> rows = new ArrayList<>();
  data.put("rows", rows);
  Map<String, Object> row;
  for (int i = 0; i < 10; i++) {
    row = new HashMap<>();
    rows.add(row);
    row.put("yearMonth", YearMonth.now());
    row.put("dateTime", LocalDateTime.now());
    row.put("str", "test");
    row.put("money", new BigDecimal("100.01").add(new BigDecimal((float) i / 1000)).setScale(2, BigDecimal.ROUND_HALF_UP));
    row.put("stage", i % 2);
    if (i % 2 == 0) {
      row.put("remark", "remark" + (i + 1));
    }
  }
  return data;
}
项目:living-documentation    文件:BillingService.java   
@GET
@Path("/{month}")
@ApiOperation(value = "Facturation d'un mois", response = Bill.class)
@ApiResponses(value = {
        @ApiResponse(code = 400, message = "Invalid input"),
        @ApiResponse(code = 404, message = "Billing not found")}
)
public Response getBill(@PathParam("month") final String month, @Context Request request) {
    Optional<Bill> bill = repository.get(YearMonth.parse(month));

    if (!bill.isPresent()) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }

    EntityTag etag = new EntityTag(Integer.toString(bill.get().hashCode()));
    Response.ResponseBuilder preconditions = request == null ? null : request.evaluatePreconditions(etag);

    // cached resource did change -> serve updated content
    if (preconditions == null) {
        preconditions = Response.ok(bill.get()).tag(etag);
    }

    return preconditions.build();
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
void doTest_comparisons_YearMonth(YearMonth... localDates) {
    for (int i = 0; i < localDates.length; i++) {
        YearMonth a = localDates[i];
        for (int j = 0; j < localDates.length; j++) {
            YearMonth 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);
            }
        }
    }
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
void doTest_comparisons_YearMonth(YearMonth... localDates) {
    for (int i = 0; i < localDates.length; i++) {
        YearMonth a = localDates[i];
        for (int j = 0; j < localDates.length; j++) {
            YearMonth 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);
            }
        }
    }
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@DataProvider(name="atEndOfMonth")
Object[][] data_atEndOfMonth() {
    return new Object[][] {
            {YearMonth.of(2008, 1), LocalDate.of(2008, 1, 31)},
            {YearMonth.of(2008, 2), LocalDate.of(2008, 2, 29)},
            {YearMonth.of(2008, 3), LocalDate.of(2008, 3, 31)},
            {YearMonth.of(2008, 4), LocalDate.of(2008, 4, 30)},
            {YearMonth.of(2008, 5), LocalDate.of(2008, 5, 31)},
            {YearMonth.of(2008, 6), LocalDate.of(2008, 6, 30)},
            {YearMonth.of(2008, 12), LocalDate.of(2008, 12, 31)},

            {YearMonth.of(2009, 1), LocalDate.of(2009, 1, 31)},
            {YearMonth.of(2009, 2), LocalDate.of(2009, 2, 28)},
            {YearMonth.of(2009, 3), LocalDate.of(2009, 3, 31)},
            {YearMonth.of(2009, 4), LocalDate.of(2009, 4, 30)},
            {YearMonth.of(2009, 5), LocalDate.of(2009, 5, 31)},
            {YearMonth.of(2009, 6), LocalDate.of(2009, 6, 30)},
            {YearMonth.of(2009, 12), LocalDate.of(2009, 12, 31)},
    };
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@DataProvider(name="minus_long_TemporalUnit")
Object[][] data_minus_long_TemporalUnit() {
    return new Object[][] {
        {YearMonth.of(1, 10), 1, ChronoUnit.YEARS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 12, ChronoUnit.YEARS, YearMonth.of(-11, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.YEARS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), 999999999, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), -999999999, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.MONTHS, YearMonth.of(1, 9), null},
        {YearMonth.of(1, 10), 12, ChronoUnit.MONTHS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.MONTHS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), 1, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 11), -1, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.ERAS, YearMonth.of(0, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.CENTURIES, YearMonth.of(-95, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.DECADES, YearMonth.of(-5, 10), null},

        {YearMonth.of(999999999, 12), -1, ChronoUnit.MONTHS, null, DateTimeException.class},
        {YearMonth.of(-999999999, 1), 1, ChronoUnit.MONTHS, null, DateTimeException.class},

        {YearMonth.of(1, 1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {YearMonth.of(1, 1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
    };
}
项目:CalendarFX    文件:HelloYearMonthView.java   
private void createEntries(YearMonth month) {
    for (int i = 1; i < 28; i++) {

        LocalDate date = month.atDay(i);

        for (int j = 0; j < (int) (Math.random() * 7); j++) {
            Entry<?> entry = new Entry<>();
            entry.changeStartDate(date);
            entry.changeEndDate(date);

            entry.setTitle("Entry " + (j + 1));

            int hour = (int) (Math.random() * 23);
            int durationInHours = Math.min(24 - hour,
                    (int) (Math.random() * 4));

            LocalTime startTime = LocalTime.of(hour, 0);
            LocalTime endTime = startTime.plusHours(durationInHours);

            entry.changeStartTime(startTime);
            entry.changeEndTime(endTime);

            if (Math.random() < .3) {
                entry.setFullDay(true);
            }

            entry.setCalendar(this);
        }
    }
}
项目:CalendarFX    文件:HelloCalendarView.java   
public HelloCalendar() {
    for (Month month : Month.values()) {

        YearMonth yearMonth = YearMonth.of(LocalDate.now().getYear(), month);

        for (int i = 1; i < 28; i++) {

            LocalDate date = yearMonth.atDay(i);

            for (int j = 0; j < (int) (Math.random() * 7); j++) {
                Entry<?> entry = new Entry<>();
                entry.changeStartDate(date);
                entry.changeEndDate(date);

                entry.setTitle("Entry " + (j + 1));

                int hour = (int) (Math.random() * 23);
                int durationInHours = Math.min(24 - hour,
                        (int) (Math.random() * 4));

                LocalTime startTime = LocalTime.of(hour, 0);
                LocalTime endTime = startTime
                        .plusHours(durationInHours);

                entry.changeStartTime(startTime);
                entry.changeEndTime(endTime);

                if (Math.random() < .3) {
                    entry.setFullDay(true);
                }

                entry.setCalendar(this);
            }
        }
    }
}
项目:CalendarFX    文件:HelloCalendar.java   
public HelloCalendar() {
    for (int i = 1; i < 28; i++) {

        LocalDate date = YearMonth.now().atDay(i);

        for (int j = 0; j < (int) (Math.random() * 7); j++) {
            Entry<?> entry = new Entry<>();
            entry.changeStartDate(date);
            entry.changeEndDate(date.plusDays((int) (Math.random() * 4)));

            entry.setTitle("Entry " + (j + 1));

            int hour = (int) (Math.random() * 23);
            int durationInHours = Math.min(24 - hour,
                    (int) (Math.random() * 4));

            LocalTime startTime = LocalTime.of(hour, 0);
            LocalTime endTime = startTime.plusHours(durationInHours);

            entry.changeStartTime(startTime);
            entry.changeEndTime(endTime);

            if (Math.random() < .3) {
                entry.setFullDay(true);
            }

            entry.setCalendar(this);
        }
    }
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test
public void test_hashCode_unique() {
    Set<Integer> uniques = new HashSet<Integer>(201 * 12);
    for (int i = 1900; i <= 2100; i++) {
        for (int j = 1; j <= 12; j++) {
            assertTrue(uniques.add(YearMonth.of(i, j).hashCode()));
        }
    }
}
项目:openjdk-jdk10    文件:TCKYearMonthSerialization.java   
@Test
public void test_serialization_format() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (DataOutputStream dos = new DataOutputStream(baos) ) {
        dos.writeByte(12);       // java.time.temporal.Ser.YEAR_MONTH_TYPE
        dos.writeInt(2012);
        dos.writeByte(9);
    }
    byte[] bytes = baos.toByteArray();
    assertSerializedBySer(YearMonth.of(2012, 9), bytes);
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test(dataProvider="plus_long_TemporalUnit")
public void test_plus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) {
    if (expectedEx == null) {
        assertEquals(base.plus(amount, unit), expectedYearMonth);
    } else {
        try {
            YearMonth result = base.plus(amount, unit);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test
public void test_isValidDay_int_febLeap() {
    YearMonth test = YearMonth.of(2008, 2);
    assertEquals(test.isValidDay(1), true);
    assertEquals(test.isValidDay(29), true);

    assertEquals(test.isValidDay(-1), false);
    assertEquals(test.isValidDay(0), false);
    assertEquals(test.isValidDay(30), false);
    assertEquals(test.isValidDay(32), false);
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test(dataProvider="minus_long_TemporalUnit")
public void test_minus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) {
    if (expectedEx == null) {
        assertEquals(base.minus(amount, unit), expectedYearMonth);
    } else {
        try {
            YearMonth result = base.minus(amount, unit);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
项目:jdk8u-jdk    文件:TestDateTimeFormatter.java   
@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, "");
}
项目:jdk8u-jdk    文件:TestDateTimeFormatterBuilder.java   
@Test
public void test_padOptional() throws Exception {
    builder.appendValue(MONTH_OF_YEAR).appendLiteral(':')
            .padNext(5).optionalStart().appendValue(DAY_OF_MONTH).optionalEnd()
            .appendLiteral(':').appendValue(YEAR);
    assertEquals(builder.toFormatter().format(LocalDate.of(2013, 2, 1)), "2:    1:2013");
    assertEquals(builder.toFormatter().format(YearMonth.of(2013, 2)), "2:     :2013");
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test(dataProvider="atDay")
public void test_atDay(YearMonth test, int day, LocalDate expected) {
    if (expected != null) {
        assertEquals(test.atDay(day), expected);
    } else {
        try {
            test.atDay(day);
            fail();
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:CalendarFX    文件:CalendarView.java   
/**
 * Sends the request to the calendar view to display the given year and
 * month. The view will switch to the {@link MonthPage} and set the value of
 * {@link #dateProperty()} to the first day of the month.
 *
 * @param yearMonth the year and month to show in the view
 */
public final void showYearMonth(YearMonth yearMonth) {
    requireNonNull(yearMonth);

    if (!monthPage.isHidden()) {
        selectedPage.set(getMonthPage());
    } else if (!yearPage.isHidden()) {
        selectedPage.set(getYearPage());
    }

    setDate(yearMonth.atDay(1));
}
项目:CalendarFX    文件:MonthSheetViewSkin.java   
private void buildCells() {
    positionToDateCellMap.clear();
    dateToPositionMap.clear();
    cellMap.clear();

    YearMonth start = getSkinnable().getExtendedStartMonth();
    YearMonth end = getSkinnable().getExtendedEndMonth();

    int colIndex = 0;

    grid.getColumnConstraints().clear();
    grid.getChildren().clear();

    while (!start.isAfter(end)) {
        ColumnConstraints columnConstraints = new ColumnConstraints();
        columnConstraints.setFillWidth(true);
        columnConstraints.setMinWidth(Region.USE_PREF_SIZE);
        columnConstraints.setMaxWidth(Double.MAX_VALUE);
        grid.getColumnConstraints().add(columnConstraints);

        buildCells(start, colIndex);

        start = start.plusMonths(1);
        colIndex++;
    }

    grid.getColumnConstraints().forEach(con -> con.setPercentWidth(100d / (double) grid.getColumnConstraints().size()));

    updateEntries("cells were rebuild");
    updateToday();
    updateSelected();
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test
public void test_hashCode_unique() {
    Set<Integer> uniques = new HashSet<Integer>(201 * 12);
    for (int i = 1900; i <= 2100; i++) {
        for (int j = 1; j <= 12; j++) {
            assertTrue(uniques.add(YearMonth.of(i, j).hashCode()));
        }
    }
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@DataProvider(name="plus_long_TemporalUnit")
Object[][] data_plus_long_TemporalUnit() {
    return new Object[][] {
        {YearMonth.of(1, 10), 1, ChronoUnit.YEARS, YearMonth.of(2, 10), null},
        {YearMonth.of(1, 10), -12, ChronoUnit.YEARS, YearMonth.of(-11, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.YEARS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), -999999999, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), 999999999, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.MONTHS, YearMonth.of(1, 11), null},
        {YearMonth.of(1, 10), -12, ChronoUnit.MONTHS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.MONTHS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), -1, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 3), 9, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(-1, 10), 1, ChronoUnit.ERAS, YearMonth.of(2, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.CENTURIES, YearMonth.of(105, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.DECADES, YearMonth.of(15, 10), null},

        {YearMonth.of(999999999, 12), 1, ChronoUnit.MONTHS, null, DateTimeException.class},
        {YearMonth.of(-999999999, 1), -1, ChronoUnit.MONTHS, null, DateTimeException.class},

        {YearMonth.of(1, 1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {YearMonth.of(1, 1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
    };
}
项目:iextrading4j    文件:HistoricalStatsRequestBuilderTest.java   
@Test
public void shouldSuccessfullyCreateRequestWithYearMonthDate() {
    final YearMonth yearMonth = YearMonth.of(2017, 5);

    final RestRequest<List<HistoricalStats>> request = new HistoricalStatsRequestBuilder()
            .withDate(yearMonth)
            .build();

    assertThat(request.getMethodType()).isEqualTo(MethodType.GET);
    assertThat(request.getPath()).isEqualTo("/stats/historical");
    assertThat(request.getResponseType()).isEqualTo(new GenericType<List<HistoricalStats>>() {});
    assertThat(request.getPathParams()).isEmpty();
    assertThat(request.getQueryParams()).contains(entry("date", "201705"));
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test
public void test_isValidDay_int_febLeap() {
    YearMonth test = YearMonth.of(2008, 2);
    assertEquals(test.isValidDay(1), true);
    assertEquals(test.isValidDay(29), true);

    assertEquals(test.isValidDay(-1), false);
    assertEquals(test.isValidDay(0), false);
    assertEquals(test.isValidDay(30), false);
    assertEquals(test.isValidDay(32), false);
}
项目:openjdk-jdk10    文件:TCKMonthDay.java   
@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()));
            }
        }
    }
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test(dataProvider="minus_TemporalAmount")
public void test_minus_TemporalAmount(YearMonth base, TemporalAmount temporalAmount, YearMonth expectedYearMonth, Class<?> expectedEx) {
    if (expectedEx == null) {
        assertEquals(base.minus(temporalAmount), expectedYearMonth);
    } else {
        try {
            YearMonth result = base.minus(temporalAmount);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    YearMonth expected = YearMonth.now(Clock.system(zone));
    YearMonth test = YearMonth.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = YearMonth.now(Clock.system(zone));
        test = YearMonth.now(zone);
    }
    assertEquals(test, expected);
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@DataProvider(name="minus_long_TemporalUnit")
Object[][] data_minus_long_TemporalUnit() {
    return new Object[][] {
        {YearMonth.of(1, 10), 1, ChronoUnit.YEARS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 12, ChronoUnit.YEARS, YearMonth.of(-11, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.YEARS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), 999999999, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), -999999999, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.MONTHS, YearMonth.of(1, 9), null},
        {YearMonth.of(1, 10), 12, ChronoUnit.MONTHS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.MONTHS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), 1, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 11), -1, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.ERAS, YearMonth.of(0, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.CENTURIES, YearMonth.of(-95, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.DECADES, YearMonth.of(-5, 10), null},

        {YearMonth.of(999999999, 12), -1, ChronoUnit.MONTHS, null, DateTimeException.class},
        {YearMonth.of(-999999999, 1), 1, ChronoUnit.MONTHS, null, DateTimeException.class},

        {YearMonth.of(1, 1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {YearMonth.of(1, 1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
    };
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test
public void test_comparisons() {
    doTest_comparisons_YearMonth(
        YearMonth.of(-1, 1),
        YearMonth.of(0, 1),
        YearMonth.of(0, 12),
        YearMonth.of(1, 1),
        YearMonth.of(1, 2),
        YearMonth.of(1, 12),
        YearMonth.of(2008, 1),
        YearMonth.of(2008, 6),
        YearMonth.of(2008, 12)
    );
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test(dataProvider="badParseData", expectedExceptions=DateTimeParseException.class)
public void factory_parse_fail(String text, int pos) {
    try {
        YearMonth.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;
    }
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test(dataProvider="minus_long_TemporalUnit")
public void test_minus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) {
    if (expectedEx == null) {
        assertEquals(base.minus(amount, unit), expectedYearMonth);
    } else {
        try {
            YearMonth result = base.minus(amount, unit);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
项目:openjdk-jdk10    文件:TestDateTimeFormatterBuilder.java   
@Test
public void test_padOptional() throws Exception {
    builder.appendValue(MONTH_OF_YEAR).appendLiteral(':')
            .padNext(5).optionalStart().appendValue(DAY_OF_MONTH).optionalEnd()
            .appendLiteral(':').appendValue(YEAR);
    assertEquals(builder.toFormatter().format(LocalDate.of(2013, 2, 1)), "2:    1:2013");
    assertEquals(builder.toFormatter().format(YearMonth.of(2013, 2)), "2:     :2013");
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test(expectedExceptions=DateTimeException.class)
public void test_plusMonths_long_invalidTooLargeMaxAddMin() {
    YearMonth test = YearMonth.of(Year.MAX_VALUE, 12);
    test.plusMonths(Long.MIN_VALUE);
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M");
    String t = YearMonth.of(2010, 12).format(f);
    assertEquals(t, "2010 12");
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test
public void factory_ints() {
    YearMonth test = YearMonth.of(2008, 2);
    check(test, 2008, 2);
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test(expectedExceptions={DateTimeException.class})
public void test_plusMonths_long_invalidTooLarge() {
    YearMonth test = YearMonth.of(Year.MAX_VALUE, 12);
    test.plusMonths(1);
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@Test(expectedExceptions={DateTimeException.class})
public void test_plusMonths_long_invalidTooSmall() {
    YearMonth test = YearMonth.of(Year.MIN_VALUE, 1);
    test.plusMonths(-1);
}
项目:living-documentation    文件:Bill.java   
public YearMonth getMonth() {
    return month;
}
项目:openjdk-jdk10    文件:TCKYearMonth.java   
@Test
public void factory_intsMonth() {
    YearMonth test = YearMonth.of(2008, Month.FEBRUARY);
    check(test, 2008, 2);
}
项目:openjdk-jdk10    文件:TCKDateTimeFormatters.java   
@Test(expectedExceptions=DateTimeException.class)
public void test_print_isoWeekDate_missingField() {
    TemporalAccessor test = YearMonth.of(2008, 6);
    DateTimeFormatter.ISO_WEEK_DATE.format(test);
}
项目:CalendarFX    文件:HelloYearMonthView.java   
public HelloCalendar(YearMonth month) {
    createEntries(month);
}