Example usage for java.time LocalDate now

List of usage examples for java.time LocalDate now

Introduction

In this page you can find the example usage for java.time LocalDate now.

Prototype

public static LocalDate now(Clock clock) 

Source Link

Document

Obtains the current date from the specified clock.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.now(Clock.systemDefaultZone());

    System.out.println(a);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.now(ZoneId.systemDefault());

    System.out.println(a);
}

From source file:Main.java

public static void main(String[] args) {
    // Current date in "Asia/Kolkata", you can get it from ZoneId javadoc
    LocalDate todayKolkata = LocalDate.now(ZoneId.of("Asia/Kolkata"));
    System.out.println("Current Date in IST=" + todayKolkata);
}

From source file:Main.java

public static void main(String[] args) {
    Clock clock = Clock.systemDefaultZone();

    Instant instant1 = clock.instant();
    System.out.println(instant1);

    Instant instant2 = Instant.now(clock);
    System.out.println(instant2);

    LocalDate localDate = LocalDate.now(clock);
    System.out.println(localDate);

    ZonedDateTime zoneDateTime = ZonedDateTime.now(clock);
    System.out.println(zoneDateTime);
}

From source file:org.zaproxy.admin.PendingAddOnReleases.java

public static void main(String[] args) throws Exception {
    LocalDate now = LocalDate.now(ZoneOffset.UTC);
    boolean showChanges = true;

    ZapXmlConfiguration zapVersions = new ZapXmlConfiguration(Paths.get(ZAP_VERSIONS_FILE_NAME).toFile());
    AddOnCollection addOnCollection = new AddOnCollection(zapVersions, AddOnCollection.Platform.daily);

    zapVersions.setExpressionEngine(new XPathExpressionEngine());

    Set<AddOnData> addOns = getAllAddOns();
    int totalAddOns = addOns.size();

    Set<AddOnData> unreleasedAddOns = new TreeSet<>();
    Set<AddOnData> unchangedAddOns = new TreeSet<>();

    for (Iterator<AddOnData> it = addOns.iterator(); it.hasNext();) {
        AddOnData addOnData = it.next();
        AddOn addOn = addOnCollection.getAddOn(addOnData.getId());
        if (addOn == null) {
            unreleasedAddOns.add(addOnData);
            it.remove();//from w  ww .  ja v  a 2  s. co  m
        } else if (addOn.getVersion().compareTo(addOnData.getVersion()) >= 0) {
            it.remove();
        } else if (addOnData.getChanges().isEmpty()) {
            unchangedAddOns.add(addOnData);
            it.remove();
        }
    }

    if (!unreleasedAddOns.isEmpty()) {
        System.out.println("=============================");
        System.out.println("Unreleased add-ons (" + unreleasedAddOns.size() + " of " + totalAddOns + ")");
        System.out.println("=============================");
        for (AddOnData addOn : unreleasedAddOns) {
            System.out.println(addOn.getStatus() + "\t" + addOn.getName() + " v" + addOn.getVersion());
        }
        System.out.println("=============================\n");
    }

    if (!addOns.isEmpty()) {
        System.out.println("=======================================");
        System.out.println("New versions pending release (" + addOns.size() + " of " + totalAddOns + ")");
        System.out.println("=======================================");
        Status currentStatus = null;
        for (AddOnData addOn : addOns) {
            if (currentStatus != addOn.getStatus()) {
                currentStatus = addOn.getStatus();
                System.out.println(currentStatus);
            }
            LocalDate releaseDate = LocalDate.parse(zapVersions.getString("/addon_" + addOn.getId() + "/date"));
            System.out.println("  * " + addOn.getName() + " v" + addOn.getVersion() + " ("
                    + Period.between(releaseDate, now) + ")");

            if (showChanges) {
                for (String change : addOn.getChanges()) {
                    System.out.println("       - " + change);
                }
            }
        }
        System.out.println("=======================================\n");
    }

    if (!unchangedAddOns.isEmpty()) {
        System.out.println("=============================");
        System.out.println("Unchanged add-ons (" + unchangedAddOns.size() + " of " + totalAddOns + ")");
        System.out.println("=============================");
        for (AddOnData addOn : unchangedAddOns) {
            System.out.println(addOn.getStatus() + "\t" + addOn.getName() + " v" + addOn.getVersion());
        }
        System.out.println("=============================\n");
    }
}

From source file:org.openlmis.fulfillment.util.DateHelper.java

public LocalDate getCurrentDate() {
    return LocalDate.now(clock);
}

From source file:cz.muni.fi.javaseminar.kafa.bookregister.AuthorManagerImpl.java

private void validate(Author author) throws IllegalArgumentException {
    if (author == null) {
        throw new IllegalArgumentException("author is null");
    }/*from www  . ja  v  a2 s  .c  o m*/

    if (author.getDateOfBirth().isAfter(LocalDate.now(clock))) {
        throw new IllegalArgumentException("date of birth is in future");
    }

}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void testCreateReservation() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Reservation reservation = setReservation(1, 1, checkin, checkout, reservationdate);
    reservationManager.createReservation(reservation);

    Long reservationId = reservation.getReservationId();
    assertNotNull(reservationId);// w w  w  . j a v  a 2 s  .  com

    Reservation result = reservationManager.findReservation(reservationId);
    assertThat("loaded reservation differs from the saved one", result, is(equalTo(reservation)));
    assertThat("loaded reservation is the same instance", result, is(not(sameInstance(reservation))));
    assertDeepEquals(reservation, result);
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void testUpdateReservation() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Reservation reservation1 = setReservation(1L, 1L, checkin, checkout, reservationdate);
    Reservation reservation2 = setReservation(2L, 2L, checkin.plusDays(1), checkout,
            reservationdate.plusDays(2));

    reservationManager.createReservation(reservation1);
    reservationManager.createReservation(reservation2);

    Long reservationId = reservation1.getReservationId();

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setRoomId(3L);//from   w w  w . ja v  a  2s . c  om
    reservationManager.updateReservation(reservation1);
    assertThat("room id was not changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was changed", reservation1.getGuestId(), is(equalTo(1L)));
    assertThat("resrvation date was changed", reservation1.getReservationDate(), is(equalTo(reservationdate)));
    assertThat("checkin date was changed", reservation1.getCheckinDate(), is(equalTo(checkin)));
    assertThat("checkout date was changed", reservation1.getCheckoutDate(), is(equalTo(checkout)));

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setGuestId(3L);
    reservationManager.updateReservation(reservation1);
    assertThat("room id was changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was not changed", reservation1.getGuestId(), is(equalTo(3L)));
    assertThat("resrvation date was changed", reservation1.getReservationDate(), is(equalTo(reservationdate)));
    assertThat("checkin date was changed", reservation1.getCheckinDate(), is(equalTo(checkin)));
    assertThat("checkout date was changed", reservation1.getCheckoutDate(), is(equalTo(checkout)));

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setReservationDate(reservationdate.plusDays(1));
    reservationManager.updateReservation(reservation1);
    assertThat("room id was changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was changed", reservation1.getGuestId(), is(equalTo(3L)));
    assertThat("resrvation date was not changed", reservation1.getReservationDate(),
            is(equalTo(reservationdate.plusDays(1))));
    assertThat("checkin date was changed", reservation1.getCheckinDate(), is(equalTo(checkin)));
    assertThat("checkout date was changed", reservation1.getCheckoutDate(), is(equalTo(checkout)));

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setCheckinDate(checkin.plusDays(2));
    reservationManager.updateReservation(reservation1);
    assertThat("room id was changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was changed", reservation1.getGuestId(), is(equalTo(3L)));
    assertThat("resrvation date was changed", reservation1.getReservationDate(),
            is(equalTo(reservationdate.plusDays(1))));
    assertThat("checkin date was not changed", reservation1.getCheckinDate(), is(equalTo(checkin.plusDays(2))));
    assertThat("checkout date was changed", reservation1.getCheckoutDate(), is(equalTo(checkout)));

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setCheckoutDate(checkout.plusDays(2));
    reservationManager.updateReservation(reservation1);
    assertThat("room id was changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was changed", reservation1.getGuestId(), is(equalTo(3L)));
    assertThat("resrvation date was changed", reservation1.getReservationDate(),
            is(equalTo(reservationdate.plusDays(1))));
    assertThat("checkin date was changed", reservation1.getCheckinDate(), is(equalTo(checkin.plusDays(2))));
    assertThat("checkout date was not changed", reservation1.getCheckoutDate(),
            is(equalTo(checkout.plusDays(2))));

    assertDeepEquals(reservation2, reservationManager.findReservation(reservation2.getReservationId()));
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void testCreateReservationWithWrongValues() {

    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));
    Reservation reservation;//ww  w  . ja v a2s. c  o m

    reservation = setReservation(-5, 1, checkin, checkout, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("wrong room id(negative value)");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, -1, checkin, checkout, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("wrong guest id (negative value)");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, 1, checkin.plusMonths(3), checkout, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("checkin after checkout");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, 1, checkin, checkout, reservationdate.plusYears(1));
    try {
        reservationManager.createReservation(reservation);
        fail("reservation date after checkin");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, 1, checkin, null, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("checkout is null");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, 1, null, checkout, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("checkin is null");
    } catch (IllegalArgumentException ex) {
        //OK
    }
}