Java Code Examples for java.time.YearMonth

The following are top voted examples for showing how to use java.time.YearMonth. 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: simter-jxls-ext   File: JxlsUtilsTest.java   Source Code and License 7 votes vote down vote up
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;
}
 
Example 2
Project: living-documentation   File: BillingService.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 3
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example 4
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example 5
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 6 votes vote down vote up
@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)},
    };
}
 
Example 6
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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},
    };
}
 
Example 7
Project: CalendarFX   File: HelloYearMonthView.java   Source Code and License 5 votes vote down vote up
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);
        }
    }
}
 
Example 8
Project: CalendarFX   File: HelloCalendarView.java   Source Code and License 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 9
Project: CalendarFX   File: HelloCalendar.java   Source Code and License 5 votes vote down vote up
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);
        }
    }
}
 
Example 10
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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()));
        }
    }
}
 
Example 11
Project: openjdk-jdk10   File: TCKYearMonthSerialization.java   Source Code and License 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(12);       // java.time.temporal.Ser.YEAR_MONTH_TYPE
        dos.writeInt(2012);
        dos.writeByte(9);
    }
    byte[] bytes = baos.toByteArray();
    assertSerializedBySer(YearMonth.of(2012, 9), bytes);
}
 
Example 12
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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));
        }
    }
}
 
Example 13
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 14
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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));
        }
    }
}
 
Example 15
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 16
Project: jdk8u-jdk   File: TestDateTimeFormatterBuilder.java   Source Code and License 5 votes vote down vote up
@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");
}
 
Example 17
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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
        }
    }
}
 
Example 18
Project: CalendarFX   File: CalendarView.java   Source Code and License 5 votes vote down vote up
/**
 * 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));
}
 
Example 19
Project: CalendarFX   File: MonthSheetViewSkin.java   Source Code and License 5 votes vote down vote up
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();
}
 
Example 20
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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()));
        }
    }
}
 
Example 21
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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},
    };
}
 
Example 22
Project: iextrading4j   File: HistoricalStatsRequestBuilderTest.java   Source Code and License 5 votes vote down vote up
@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"));
}
 
Example 23
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 24
Project: openjdk-jdk10   File: TCKMonthDay.java   Source Code and License 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 25
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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));
        }
    }
}
 
Example 26
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 27
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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},
    };
}
 
Example 28
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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)
    );
}
 
Example 29
Project: jdk8u-jdk   File: TCKYearMonth.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 {
        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;
    }
}
 
Example 30
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 5 votes vote down vote up
@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));
        }
    }
}
 
Example 31
Project: openjdk-jdk10   File: TestDateTimeFormatterBuilder.java   Source Code and License 5 votes vote down vote up
@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");
}
 
Example 32
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_plusMonths_long_invalidTooLargeMaxAddMin() {
    YearMonth test = YearMonth.of(Year.MAX_VALUE, 12);
    test.plusMonths(Long.MIN_VALUE);
}
 
Example 33
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 4 votes vote down vote up
@Test
public void test_format_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M");
    String t = YearMonth.of(2010, 12).format(f);
    assertEquals(t, "2010 12");
}
 
Example 34
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 4 votes vote down vote up
@Test
public void factory_ints() {
    YearMonth test = YearMonth.of(2008, 2);
    check(test, 2008, 2);
}
 
Example 35
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions={DateTimeException.class})
public void test_plusMonths_long_invalidTooLarge() {
    YearMonth test = YearMonth.of(Year.MAX_VALUE, 12);
    test.plusMonths(1);
}
 
Example 36
Project: jdk8u-jdk   File: TCKYearMonth.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions={DateTimeException.class})
public void test_plusMonths_long_invalidTooSmall() {
    YearMonth test = YearMonth.of(Year.MIN_VALUE, 1);
    test.plusMonths(-1);
}
 
Example 37
Project: living-documentation   File: Bill.java   Source Code and License 4 votes vote down vote up
public YearMonth getMonth() {
    return month;
}
 
Example 38
Project: openjdk-jdk10   File: TCKYearMonth.java   Source Code and License 4 votes vote down vote up
@Test
public void factory_intsMonth() {
    YearMonth test = YearMonth.of(2008, Month.FEBRUARY);
    check(test, 2008, 2);
}
 
Example 39
Project: openjdk-jdk10   File: TCKDateTimeFormatters.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_print_isoWeekDate_missingField() {
    TemporalAccessor test = YearMonth.of(2008, 6);
    DateTimeFormatter.ISO_WEEK_DATE.format(test);
}
 
Example 40
Project: CalendarFX   File: HelloYearMonthView.java   Source Code and License 4 votes vote down vote up
public HelloCalendar(YearMonth month) {
    createEntries(month);
}