本文整理汇总了Java中java.time.LocalDate.minus方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDate.minus方法的具体用法?Java LocalDate.minus怎么用?Java LocalDate.minus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.minus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRangeOfLocalDates
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider = "localDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
final Range<LocalDate> range = Range.of(start, end, step);
final Array<LocalDate> array = range.toArray(parallel);
final boolean ascend = start.isBefore(end);
final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.DAYS.between(start, end)) / (double)step.getDays());
Assert.assertEquals(array.length(), expectedLength);
Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
LocalDate expected = null;
for (int i=0; i<array.length(); ++i) {
final LocalDate actual = array.getValue(i);
expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
Assert.assertEquals(actual, expected, "Value matches at " + i);
Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
}
}
示例2: testRangeOfLocalDates
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider = "LocalDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
final boolean ascend = start.isBefore(end);
final Range<LocalDate> range = Range.of(start, end, step, v -> v.getDayOfWeek() == DayOfWeek.MONDAY);
final Array<LocalDate> array = range.toArray(parallel);
final LocalDate first = array.first(v -> true).map(ArrayValue::getValue).get();
final LocalDate last = array.last(v -> true).map(ArrayValue::getValue).get();
Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
int index = 0;
LocalDate value = first;
while (ascend ? value.isBefore(last) : value.isAfter(last)) {
final LocalDate actual = array.getValue(index);
Assert.assertEquals(actual, value, "Value matches at " + index);
Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
value = ascend ? value.plus(step) : value.minus(step);
while (value.getDayOfWeek() == DayOfWeek.MONDAY) value = ascend ? value.plus(step) : value.minus(step);
index++;
}
}
示例3: bepaalDatum
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* bepaald de nieuwe datum door van de meegegeven datum het aantal meegegeven dagen af te trekken
* @param datum peilDatum
* @param minus aantal dagen voor peildatum
* @return bepaalde datum
*/
public static Integer bepaalDatum(final int datum, final int minus) {
final Integer minimaleDatum = bepaalEindDatumStrengOfBeginDatumSoepel(datum, false);
final LocalDate minimaleDate = vanIntegerNaarLocalDate(minimaleDatum);
final LocalDate nieuweDate = minimaleDate.minus(minus, ChronoUnit.DAYS);
final String formattedDateString = FORMATTER.format(nieuweDate);
return Integer.parseInt(formattedDateString);
}
示例4: initialize
import java.time.LocalDate; //导入方法依赖的package包/类
@Override
public void initialize(URL location, ResourceBundle resources) {
diag = new Dialog();
diag.getDialogPane().setContent(borderPane);
diag.getDialogPane().setBackground(Background.EMPTY);
diag.setResizable(true);
UIUtils.setIcon(diag);
diag.setTitle("Export senor data to CSV");
// date
endPicker.disableProperty().bind(nowCheck.selectedProperty());
dateInput.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
try {
SimpleDateFormat sdf = new SimpleDateFormat(newValue);
dateLabel.setText(sdf.format(new Date()));
validFormat.set(true);
} catch (IllegalArgumentException ex) {
dateLabel.setText("Invalid format!");
validFormat.set(false);
}
});
// trigger
String cur = dateInput.getText();
dateInput.textProperty().set("");
dateInput.textProperty().set(cur);
endPicker.setValue(LocalDate.now());
LocalDate s = LocalDate.now();
s = s.minus(7, ChronoUnit.DAYS);
startPicker.setValue(s);
// Bug: can not bind same data on 2 lists
sensorList.getItems().addAll(store.getSensors());
sensorList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
sensorSelected.set(newValue != null);
});
canExport.bind(sensorSelected.and(validFormat));
ButtonType closeButton = new ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE);
ButtonType exportButton = new ButtonType("Export", ButtonBar.ButtonData.OK_DONE);
diag.getDialogPane().getButtonTypes().addAll(closeButton, exportButton);
diag.getDialogPane().lookupButton(exportButton).disableProperty().bind(canExport.not());
showDialog();
}
示例5: getPreviousDay
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* 获取前 i 天日期
*
* @return
*/
public static LocalDate getPreviousDay ( int i ) {
LocalDate today = LocalDate.now();
return today.minus( i , ChronoUnit.DAYS );
}