本文整理汇总了Java中java.time.chrono.ChronoLocalDate.minus方法的典型用法代码示例。如果您正苦于以下问题:Java ChronoLocalDate.minus方法的具体用法?Java ChronoLocalDate.minus怎么用?Java ChronoLocalDate.minus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.chrono.ChronoLocalDate
的用法示例。
在下文中一共展示了ChronoLocalDate.minus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: localizedWeekOfWeekBasedYear
import java.time.chrono.ChronoLocalDate; //导入方法依赖的package包/类
/**
* Returns the week of week-based-year for the temporal.
* The week can be part of the previous year, the current year,
* or the next year depending on the week start and minimum number
* of days.
* @param temporal a date of any chronology
* @return the week of the year
* @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
*/
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
int dow = localizedDayOfWeek(temporal);
int doy = temporal.get(DAY_OF_YEAR);
int offset = startOfWeekOffset(doy, dow);
int week = computeWeek(offset, doy);
if (week == 0) {
// Day is in end of week of previous year
// Recompute from the last day of the previous year
ChronoLocalDate date = Chronology.from(temporal).date(temporal);
date = date.minus(doy, DAYS); // Back down into previous year
return localizedWeekOfWeekBasedYear(date);
} else if (week > 50) {
// If getting close to end of year, use higher precision logic
// Check if date of year is in partial week associated with next year
ValueRange dayRange = temporal.range(DAY_OF_YEAR);
int yearLen = (int)dayRange.getMaximum();
int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
if (week >= newYearWeek) {
// Overlaps with week of following year; reduce to week in following year
week = week - newYearWeek + 1;
}
}
return week;
}
示例2: test_badMinusAdjusterChrono
import java.time.chrono.ChronoLocalDate; //导入方法依赖的package包/类
@Test(dataProvider="calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDate date2 = chrono2.date(refDate);
TemporalAmount adjuster = new FixedAdjuster(date2);
if (chrono != chrono2) {
try {
date.minus(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException");
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDate result = date.minus(adjuster);
assertEquals(result, date2, "WithAdjuster failed to replace date");
}
}
}
示例3: test_badMinusTemporalUnitChrono
import java.time.chrono.ChronoLocalDate; //导入方法依赖的package包/类
@Test(dataProvider="calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDate date2 = chrono2.date(refDate);
TemporalUnit adjuster = new FixedTemporalUnit(date2);
if (chrono != chrono2) {
try {
date.minus(1, adjuster);
Assert.fail("TemporalUnit.doAdd minus should have thrown a ClassCastException" + date.getClass()
+ ", can not be cast to " + date2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDate result = date.minus(1, adjuster);
assertEquals(result, date2, "WithAdjuster failed to replace date");
}
}
}