Пример #1
0
 /**
  * Calculates the range of months based on the temporal.
  *
  * @param temporal the temporal, not null
  * @return the month range, negative if not fixed range
  */
 private long monthRange(Temporal temporal) {
   ValueRange startRange = Chronology.from(temporal).range(MONTH_OF_YEAR);
   if (startRange.isFixed() && startRange.isIntValue()) {
     return startRange.getMaximum() - startRange.getMinimum() + 1;
   }
   return -1;
 }
Пример #2
0
  // -----------------------------------------------------------------------
  // range() and rangeRefinedBy(TemporalAccessor temporal)
  // -----------------------------------------------------------------------
  @Test
  public void test_range() {
    assertEquals(MONTH_OF_YEAR.range(), ValueRange.of(1, 12));
    assertEquals(MONTH_OF_YEAR.rangeRefinedBy(LocalDate.of(2000, 2, 29)), ValueRange.of(1, 12));

    assertEquals(DAY_OF_MONTH.range(), ValueRange.of(1, 28, 31));
    assertEquals(DAY_OF_MONTH.rangeRefinedBy(LocalDate.of(2000, 2, 29)), ValueRange.of(1, 29));
  }
Пример #3
0
 ValueRange rangeChrono(ChronoField field) {
   switch (field) {
     case DAY_OF_MONTH:
       return ValueRange.of(1, lengthOfMonth());
     case DAY_OF_YEAR:
       return ValueRange.of(1, lengthOfYear());
     case ALIGNED_WEEK_OF_MONTH:
       return rangeAlignedWeekOfMonth();
     default:
       break;
   }
   return getChronology().range(field);
 }