use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class AbstractChronology method resolveYMD.
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
if (resolverStyle == ResolverStyle.LENIENT) {
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
}
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
ValueRange domRange = range(DAY_OF_MONTH);
int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
if (resolverStyle == ResolverStyle.SMART) {
// previous valid
try {
return date(y, moy, dom);
} catch (DateTimeException ex) {
return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
}
}
return date(y, moy, dom);
}
use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class ChronoLocalDateImpl method monthsUntil.
private long monthsUntil(ChronoLocalDate end) {
ValueRange range = getChronology().range(MONTH_OF_YEAR);
if (range.getMaximum() != 12) {
throw new IllegalStateException("ChronoLocalDateImpl only supports Chronologies with 12 months per year");
}
// no overflow
long packed1 = getLong(PROLEPTIC_MONTH) * 32L + get(DAY_OF_MONTH);
// no overflow
long packed2 = end.getLong(PROLEPTIC_MONTH) * 32L + end.get(DAY_OF_MONTH);
return (packed2 - packed1) / 32;
}
use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_rangeWeekOfWeekBasedYear.
@Test(dataProvider = "weekFields")
public void test_rangeWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields weekFields = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = weekFields.dayOfWeek();
TemporalField wowByField = weekFields.weekOfWeekBasedYear();
LocalDate day1 = LocalDate.of(2012, 1, weekFields.getMinimalDaysInFirstWeek());
day1 = day1.with(wowByField, 1).with(dowField, 1);
LocalDate day2 = LocalDate.of(2013, 1, weekFields.getMinimalDaysInFirstWeek());
day2 = day2.with(wowByField, 1).with(dowField, 1);
int expectedWeeks = (int) ChronoUnit.DAYS.between(day1, day2) / 7;
ValueRange range = day1.range(wowByField);
assertEquals(range.getMaximum(), expectedWeeks, "Range incorrect");
}
use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class TestUmmAlQuraChronology method Test_UmmAlQuraRanges.
// Test to verify the min/max field ranges for given dates
@Test(dataProvider = "dates")
public void Test_UmmAlQuraRanges(HijrahDate date, int minYear, int maxYear, int minMonth, int maxMonth, int minDay, int maxDay, int maxChronoDay) {
// Check the chronology ranges
HijrahChronology chrono = date.getChronology();
ValueRange yearRange = chrono.range(YEAR);
assertEquals(yearRange.getMinimum(), minYear, "Minimum year for Hijrah chronology");
assertEquals(yearRange.getLargestMinimum(), minYear, "Largest minimum year for Hijrah chronology");
assertEquals(yearRange.getMaximum(), maxYear, "Maximum year for Hijrah chronology");
assertEquals(yearRange.getSmallestMaximum(), maxYear, "Smallest Maximum year for Hijrah chronology");
ValueRange monthRange = chrono.range(MONTH_OF_YEAR);
assertEquals(monthRange.getMinimum(), minMonth, "Minimum month for Hijrah chronology");
assertEquals(monthRange.getMaximum(), maxMonth, "Maximum month for Hijrah chronology");
ValueRange daysRange = chrono.range(DAY_OF_MONTH);
assertEquals(daysRange.getMinimum(), minDay, "Minimum day for chronology");
assertEquals(daysRange.getMaximum(), maxChronoDay, "Maximum day for Hijrah chronology");
// Check the date ranges
yearRange = date.range(YEAR);
assertEquals(yearRange.getMinimum(), minYear, "Minimum year for Hijrah date");
assertEquals(yearRange.getLargestMinimum(), minYear, "Largest minimum year for Hijrah date");
assertEquals(yearRange.getMaximum(), maxYear, "Maximum year for Hijrah date");
assertEquals(yearRange.getSmallestMaximum(), maxYear, "Smallest maximum year for Hijrah date");
monthRange = date.range(MONTH_OF_YEAR);
assertEquals(monthRange.getMinimum(), minMonth, "Minimum month for HijrahDate");
assertEquals(monthRange.getMaximum(), maxMonth, "Maximum month for HijrahDate");
daysRange = date.range(DAY_OF_MONTH);
assertEquals(daysRange.getMinimum(), minDay, "Minimum day for HijrahDate");
assertEquals(daysRange.getMaximum(), maxDay, "Maximum day for HijrahDate");
}
use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class TestUmmAlQuraChronology method test_valueRange_monthDays.
// Test to verify the maximum number of days by adding one month to a given date
@Test(dataProvider = "monthDays")
public void test_valueRange_monthDays(int year, int month, int maxlength) {
ChronoLocalDate date = HijrahChronology.INSTANCE.date(year, month, 1);
ValueRange range = null;
for (int i = 1; i <= 12; i++) {
range = date.range(ChronoField.DAY_OF_MONTH);
date = date.plus(1, ChronoUnit.MONTHS);
assertEquals(range.getMaximum(), month, maxlength);
}
}
Aggregations