Example usage for java.time LocalDateTime plusYears

List of usage examples for java.time LocalDateTime plusYears

Introduction

In this page you can find the example usage for java.time LocalDateTime plusYears.

Prototype

public LocalDateTime plusYears(long years) 

Source Link

Document

Returns a copy of this LocalDateTime with the specified number of years added.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00);

    LocalDateTime t = a.plusYears(100);

    System.out.println(t);//  www.  java  2s  .  c o m
}

From source file:Main.java

private static String getDateAsStringIncrementedByYear(String inputDateStr, String pattern,
        long yearsToIncrement) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
    LocalDateTime dateTime = LocalDateTime.parse(inputDateStr, formatter);
    return dateTime.plusYears(yearsToIncrement).format(formatter);
}

From source file:rmblworx.tools.timey.gui.AlarmIntegrationTest.java

/**
 * Testet//from w  ww  . j a  va2 s . c  om
 * <ol>
 * <li>Anlegen eines Alarms per GUI,</li>
 * <li>Senden des Ereignisses zum Auslsen des Alarms per Backend und</li>
 * <li>Reaktion der GUI auf das Ereignis.</li>
 * </ol>
 */
@Test
@Ignore("schlgt derzeit fehl") // TODO
public final void testCreateAlarmAndHandleEvent() {
    /*
     * Zeitdifferenz, die der Alarm in der Zukunft ausgelst werden soll.
     * Wert mglichst klein halten, um Test nich unntig lange dauern zu lassen, aber dennoch gro genug, um sicherzustellen, dass
     * Alarm bis zu diesem Zeitpunkt vollstndig angelegt werden kann.
     */
    final int bufferInSeconds = 2;

    final String alarmDescription = "relevanter Alarm";

    final AlarmController controller = (AlarmController) getController();
    final GuiHelper guiHelper = controller.getGuiHelper();
    final ITimey facade = guiHelper.getFacade();

    // zwei unwichtige Alarme per Fassade hinzufgen
    final LocalDateTime now = LocalDateTime.now().withNano(0);
    facade.setAlarm(AlarmDescriptorConverter
            .getAsAlarmDescriptor(new Alarm(now.minusYears(1), "alter Alarm", "", false)));
    facade.setAlarm(
            AlarmDescriptorConverter.getAsAlarmDescriptor(new Alarm(now.plusYears(1), "Zukunftsalarm")));

    // relevanten Alarm per GUI hinzufgen
    final Button alarmAddButton = (Button) stage.getScene().lookup("#alarmAddButton");
    click(alarmAddButton);
    waitForThreads();

    final Scene dialogScene = controller.getDialogStage().getScene();
    final TimePicker alarmTimePicker = (TimePicker) dialogScene.lookup("#alarmTimePicker");
    final TextField alarmDescriptionTextField = (TextField) dialogScene.lookup("#alarmDescriptionTextField");
    final Button alarmSaveButton = (Button) dialogScene.lookup("#alarmSaveButton");

    Platform.runLater(new Runnable() {
        public void run() {
            alarmTimePicker.setValue(alarmTimePicker.getValue().plusSeconds(bufferInSeconds));
            alarmDescriptionTextField.setText(alarmDescription);
        }
    });
    FXTestUtils.awaitEvents();

    final MessageHelper messageHelper = mock(MessageHelper.class);
    guiHelper.setMessageHelper(messageHelper);

    // Speichern-Schaltflche bettigen
    click(alarmSaveButton);
    waitForThreads();

    // sicherstellen, dass Ereignis genau einmal fr den korrekten Alarm eintritt und verarbeitet wird
    verify(messageHelper, timeout(WAIT_FOR_EVENT)).showTrayMessageWithFallbackToDialog(anyString(),
            eq(alarmDescription), isNull(TrayIcon.class), isA(ResourceBundle.class));
}