Example usage for java.time LocalDate plusDays

List of usage examples for java.time LocalDate plusDays

Introduction

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

Prototype

public LocalDate plusDays(long daysToAdd) 

Source Link

Document

Returns a copy of this LocalDate with the specified number of days added.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = a.plusDays(100);
    System.out.println(b);/*from w ww.j  a v  a 2s .c  o  m*/
}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    System.out.println(tomorrow.isAfter(today));

}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    LocalDate yesterday = today.minus(1, DAYS);

    if (tomorrow.isAfter(today)) {
        System.out.println("Tomorrow comes after today");
    }/*  w  w w  . j a  v a 2s  .  c  o m*/

    if (yesterday.isBefore(today)) {
        System.out.println("Yesterday is day before today");
    }
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, 6, 21);
    LocalDate localDate1 = localDate.plusDays(5);
    System.out.println(localDate1);
    LocalDate localDate2 = localDate.plusMonths(3);
    System.out.println(localDate2);
    LocalDate localDate3 = localDate.plusWeeks(3);
    System.out.println(localDate3);
}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    LocalDateTime time = LocalDateTime.now();
    LocalDateTime nextHour = time.plusHours(1);

    System.out.println("today = " + today);
    System.out.println("1) tomorrow = " + tomorrow + " \n2) tomorrow = " + today.plus(1, DAYS));
    System.out.println("local time now = " + time);
    System.out.println("1) nextHour = " + nextHour + " \n2) nextHour = " + time.plus(1, HOURS));

    LocalDate nextWeek = today.plus(1, WEEKS);
    System.out.println("Date after 1 week : " + nextWeek);

    LocalDate previousYear = today.minus(1, YEARS);
    System.out.println("Date before 1 year : " + previousYear);

    LocalDate nextYear = today.plus(1, YEARS);
    System.out.println("Date after 1 year : " + nextYear);

    LocalDate firstDayOfMonth = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
    System.out.println("firstDayOfMonth = " + firstDayOfMonth);
}

From source file:Main.java

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

    // plus and minus operations
    System.out.println("10 days after today will be " + today.plusDays(10));
    System.out.println("3 weeks after today will be " + today.plusWeeks(3));
    System.out.println("20 months after today will be " + today.plusMonths(20));

    System.out.println("10 days before today will be " + today.minusDays(10));
    System.out.println("3 weeks before today will be " + today.minusWeeks(3));
    System.out.println("20 months before today will be " + today.minusMonths(20));

}

From source file:cz.pichlik.goodsentiment.MockDataGenerator.java

public static void main(String args[]) throws IOException {
    String outputDirectory = args[0];
    LocalDate seedDate = LocalDate.of(2015, 9, 1);
    for (int i = 0; i < 100; i++) {
        LocalDate date = seedDate.plusDays(i);
        File outputDirectoryFile = new File(outputDirectory);
        outputDirectoryFile.mkdirs();/*from   w w w .jav  a2s  .c om*/
        File outputFile = new File(outputDirectoryFile, String.format("goodsentinment-data-%s.csv", date));
        generateFile(outputFile, date);
    }
}

From source file:tech.tablesaw.filters.TimeDependentFilteringTest.java

public static void main(String[] args) throws Exception {

    int numberOfRecordsInTable = 100_000_000;
    Stopwatch stopwatch = Stopwatch.createStarted();

    Table t = defineSchema();/*from   w  ww. j a v  a  2  s .  com*/
    generateTestData(t, numberOfRecordsInTable, stopwatch);

    t.setName("Observations");

    // non temporal constraints
    String conceptA = t.stringColumn("concept").get(RandomUtils.nextInt(0, t.rowCount()));
    String conceptB = t.stringColumn("concept").get(RandomUtils.nextInt(0, t.rowCount()));

    // independent temporal constraints
    String conceptZ = t.stringColumn("concept").get(RandomUtils.nextInt(0, t.rowCount()));
    String conceptD = t.stringColumn("concept").get(RandomUtils.nextInt(0, t.rowCount()));
    DependencyFilter independentConstraintFilter = DependencyFilter.FIRST;

    // temporal dependency range constraint
    Range<Integer> daysConstraint = Range.closed(0, 0);

    StringColumn concept = t.stringColumn("concept");

    //Non-temporal clause
    Table nt = t.where(concept.isEqualTo(conceptA).and(concept.isNotEqualTo(conceptB)));

    DoubleColumn ntPatients = nt.doubleColumn("patient");

    // Group the original table by patient id
    TableSliceGroup patients = StandardTableSliceGroup.create(t, "patient");

    // Create a list of patient sub-tables to work with TODO(lwhite): Build the copy-on-write to ViewGroups to avoid
    CopyOnWriteArrayList<TableSlice> patientTables = new CopyOnWriteArrayList<>(patients.getSlices());

    // Apply the independent temporal event filtering to the patient subtables and remove any that don't pass
    for (TableSlice patientTable : patients) {
        StringColumn concepts = patientTable.stringColumn("concept");
        double patientId = Double.parseDouble(patientTable.name());
        if (!concepts.contains(conceptZ) || concepts.contains(conceptD)) {
            patientTables.remove(patientTable);
        } else if (!ntPatients.contains(patientId)) { // filtering out the non-temporal now constraints for
            // efficiency
            patientTables.remove(patientTable);
        }
    }

    List<IndependentResult> independentResults = new ArrayList<>();

    // Working with the filtered patient tables, calculate the event dates for the independent events
    for (TableSlice patientTable : patientTables) {
        IndependentResult result = new IndependentResult();
        List<LocalDate> eventDates = new ArrayList<>();

        // iterate an individual table and find the rows where concept matches the target concept
        for (int row : patientTable) {
            StringColumn concepts = patientTable.stringColumn("concept");
            DateColumn dates = patientTable.dateColumn("date");
            if (concepts.get(row).equals(conceptZ)) {
                eventDates.add(dates.get(row));
            }
        }

        if (independentConstraintFilter == DependencyFilter.FIRST) {
            if (eventDates.isEmpty()) {
                // this is an error
                fail("There are no event dates");
            } else { //Get the first event for the current patient and createFromCsv a date range around it
                LocalDate date = eventDates.get(0);
                result.addRange(Range.closed(date.minusDays(daysConstraint.lowerEndpoint()),
                        date.plusDays(daysConstraint.upperEndpoint())));
            } //TODO handle last and any cases
        }
        independentResults.add(result);
    }
}

From source file:squash.tools.FakeBookingCreator.java

public static void main(String[] args) throws IOException {
    int numberOfDays = 21;
    int numberOfCourts = 5;
    int maxCourtSpan = 5;
    int numberOfSlots = 16;
    int maxSlotSpan = 3;
    int minSurnameLength = 2;
    int maxSurnameLength = 20;
    int minBookingsPerDay = 0;
    int maxBookingsPerDay = 8;
    LocalDate startDate = LocalDate.of(2016, 7, 5);

    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    List<Booking> bookings = new ArrayList<>();
    for (LocalDate date = startDate; date.isBefore(startDate.plusDays(numberOfDays)); date = date.plusDays(1)) {
        int numBookings = ThreadLocalRandom.current().nextInt(minBookingsPerDay, maxBookingsPerDay + 1);
        List<Booking> daysBookings = new ArrayList<>();
        for (int bookingIndex = 0; bookingIndex < numBookings; bookingIndex++) {
            String player1 = RandomStringUtils.randomAlphabetic(1) + "." + RandomStringUtils.randomAlphabetic(
                    ThreadLocalRandom.current().nextInt(minSurnameLength, maxSurnameLength + 1));
            String player2 = RandomStringUtils.randomAlphabetic(1) + "." + RandomStringUtils.randomAlphabetic(
                    ThreadLocalRandom.current().nextInt(minSurnameLength, maxSurnameLength + 1));

            Set<ImmutablePair<Integer, Integer>> bookedCourts = new HashSet<>();
            daysBookings.forEach((booking) -> {
                addBookingToSet(booking, bookedCourts);
            });// www . jav  a 2 s. co  m

            Booking booking;
            Set<ImmutablePair<Integer, Integer>> courtsToBook = new HashSet<>();
            do {
                // Loop until we create a booking of free courts
                int court = ThreadLocalRandom.current().nextInt(1, numberOfCourts + 1);
                int courtSpan = ThreadLocalRandom.current().nextInt(1,
                        Math.min(maxCourtSpan + 1, numberOfCourts - court + 2));
                int slot = ThreadLocalRandom.current().nextInt(1, numberOfSlots + 1);
                int slotSpan = ThreadLocalRandom.current().nextInt(1,
                        Math.min(maxSlotSpan + 1, numberOfSlots - slot + 2));
                booking = new Booking(court, courtSpan, slot, slotSpan, player1 + "/" + player2);
                booking.setDate(date.format(formatter));
                courtsToBook.clear();
                addBookingToSet(booking, courtsToBook);
            } while (Boolean.valueOf(Sets.intersection(courtsToBook, bookedCourts).size() > 0));

            daysBookings.add(booking);
        }
        bookings.addAll(daysBookings);
    }

    // Encode bookings as JSON
    // Create the node factory that gives us nodes.
    JsonNodeFactory factory = new JsonNodeFactory(false);
    // Create a json factory to write the treenode as json.
    JsonFactory jsonFactory = new JsonFactory();
    ObjectNode rootNode = factory.objectNode();

    ArrayNode bookingsNode = rootNode.putArray("bookings");
    for (int i = 0; i < bookings.size(); i++) {
        Booking booking = bookings.get(i);
        ObjectNode bookingNode = factory.objectNode();
        bookingNode.put("court", booking.getCourt());
        bookingNode.put("courtSpan", booking.getCourtSpan());
        bookingNode.put("slot", booking.getSlot());
        bookingNode.put("slotSpan", booking.getSlotSpan());
        bookingNode.put("name", booking.getName());
        bookingNode.put("date", booking.getDate());
        bookingsNode.add(bookingNode);
    }
    // Add empty booking rules array - just so restore works
    rootNode.putArray("bookingRules");
    rootNode.put("clearBeforeRestore", true);

    try (JsonGenerator generator = jsonFactory.createGenerator(new File("FakeBookings.json"),
            JsonEncoding.UTF8)) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_EMPTY);
        mapper.setSerializationInclusion(Include.NON_NULL);
        mapper.writeTree(generator, rootNode);
    }
}

From source file:Main.java

public static List<LocalDate> getDatesInPeriod(Date startDate, Date endDate) {
    List<LocalDate> dates = new ArrayList<>();
    LocalDate start = toLocalDate(startDate);
    LocalDate end = toLocalDate(endDate);
    while (!start.equals(end)) {
        dates.add(start);// ww w.j av  a 2  s .  co  m
        start = start.plusDays(1);
    }
    return dates;
}