@Override public LocalDate getDepartureDate() { if (date == null) { return null; } return date.plusDays((durationInHalfDay - 1) / 2); }
// parse date from yyyy-mm-dd pattern LocalDate januaryFirst = LocalDate.parse("2014-01-01"); // add one day LocalDate januarySecond = januaryFirst.plusDays(1);
public CachedItem( File file, int from ) { this.file = file; this.from = from; exceedTime = LocalDate.now().plusDays( 1 ); }
LocalDate next = start.minusDays(1); while ((next = next.plusDays(1)).isBefore(end.plusDays(1))) { System.out.println(next); }
LocalDate start = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate end = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); for (LocalDate date = start; date.isBefore(end); date = date.plusDays(1)) { // Do your job here with `date`. System.out.println(date); }
for (LocalDate date = startDate; date.isBefore(endDate); date = date.plusDays(1)) { ... }
import java.time.LocalDate; public class DateIncrementer { static public String addOneDay(String date) { return LocalDate.parse(date).plusDays(1).toString(); } }
default Selection isAfter(LocalDate value) { return isOnOrAfter(value.plusDays(1).atStartOfDay()); }
/** * Find next available directory, after the given directory. */ public String getNextDirectory(String currentDir) throws IOException { // Fast check, if the next day directory exists return it. String nextDate = getDirForDate(getDateFromDir(currentDir).plusDays(1)); FileSystem fileSystem = basePath.getFileSystem(conf); if (fileSystem.exists(new Path(basePath, nextDate))) { return nextDate; } // Have to scan the directory to find min date greater than currentDir. String dirName = null; for (FileStatus status : fileSystem.listStatus(basePath)) { String name = status.getPath().getName(); // String comparison is good enough, since its of form date=yyyy-MM-dd if (name.compareTo(currentDir) > 0 && (dirName == null || name.compareTo(dirName) < 0)) { dirName = name; } } return dirName; }
LocalDate now = new DateTime().toLocalDate(); LocalDate plus10days = now.plusDays(10); LocalDate event = new DateTime(year, month, day, 0, 0, 0, 0).toLocalDate(); if (!event.isBefore(now) && !event.isAfter(plus10days)) { // Event is between now and 10 days (inclusive). }
LocalDate today = now.toLocalDate(); LocalDate tomorrow = today.plusDays(1); DateTime startOfToday = today.toDateTimeAtStartOfDay(now.getZone()); DateTime startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(now.getZone());
Service service = feed.services.get(trip.service_id); BitSet validOnDay = new BitSet((int) DAYS.between(startDate, endDate)); for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) { if (service.activeOn(date)) { validOnDay.set((int) DAYS.between(startDate, date));
private void createTimeslotList(ConferenceSolution solution, int timeslotListSize) { List<Timeslot> timeslotList = new ArrayList<>(timeslotListSize); int timeslotOptionsIndex = 0; LocalDate day = timeslotFirstDay; for (int i = 0; i < timeslotListSize; i++) { Timeslot timeslot = new Timeslot(); timeslot.setId((long) i); if (timeslotOptionsIndex >= timeslotOptions.size()) { timeslotOptionsIndex = 0; day = day.plusDays(1); } Pair<LocalTime, LocalTime> pair = timeslotOptions.get(timeslotOptionsIndex); timeslot.setStartDateTime(LocalDateTime.of(day, pair.getLeft())); timeslot.setEndDateTime(LocalDateTime.of(day, pair.getRight())); TalkType talkType = timeslot.getDurationInMinutes() >= 120 ? labTalkType : breakoutTalkType; talkType.getCompatibleTimeslotSet().add(timeslot); timeslot.setTalkTypeSet(Collections.singleton(talkType)); timeslotOptionsIndex++; Set<String> tagSet = new LinkedHashSet<>(2); timeslot.setTagSet(tagSet); logger.trace("Created timeslot ({}) with tags ({}).", timeslot, tagSet); timeslotList.add(timeslot); } solution.setTimeslotList(timeslotList); }
@Override public DateValue add( DurationValue duration ) { return replacement( assertValidArithmetic( () -> value.plusMonths( duration.totalMonths() ).plusDays( duration.totalDays() ) ) ); }
LocalDate lastDate = solution.getScheduleLastUTCDate(); List<LocalDate> allDateList = new ArrayList<>((int) DAYS.between(firstDate, lastDate) + 1); for (LocalDate date = firstDate; date.compareTo(lastDate) <= 0; date = date.plusDays(1)) { allDateList.add(date);
public FlightCrewSolution createFlightCrewSolution(String fileName, LocationDataGenerator.LocationData[] locationDataArray, int flightRoundTripsPerDay, int dayCount) { random = new Random(37); FlightCrewSolution solution = new FlightCrewSolution(); solution.setId(0L); LocalDate firstDate = LocalDate.of(2018, 1, 1); solution.setScheduleFirstUTCDate(firstDate); solution.setScheduleLastUTCDate(firstDate.plusDays(dayCount - 1)); FlightCrewParametrization parametrization = new FlightCrewParametrization(); parametrization.setId(0L); solution.setParametrization(parametrization); createSkillList(solution); createAirportList(solution, locationDataArray); createFlightList(solution, flightRoundTripsPerDay, dayCount); createFlightAssignmentList(solution); createEmployeeList(solution, flightRoundTripsPerDay, dayCount); int employeeListSize = solution.getEmployeeList().size(); int flightAssignmentListSize = solution.getFlightAssignmentList().size(); BigInteger possibleSolutionSize = BigInteger.valueOf((long) employeeListSize).pow(flightAssignmentListSize); logger.info("FlightCrew {} has {} skills, {} airports, {} employees, {} flights and {} flight assignments with a search space of {}.", fileName, solution.getSkillList().size(), solution.getAirportList().size(), solution.getEmployeeList().size(), solution.getFlightList().size(), flightAssignmentListSize, AbstractSolutionImporter.getFlooredPossibleSolutionSize(possibleSolutionSize)); return solution; }
id++; dayIndex++; date = date.plusDays(1);
private void writeEmployeeList() { nextSheet("Employees", 1, 2, false); nextRow(); nextHeaderCell(""); nextHeaderCell(""); nextHeaderCell(""); nextHeaderCell("Unavailability"); nextRow(); nextHeaderCell("Name"); nextHeaderCell("Home airport"); nextHeaderCell("Skills"); LocalDate firstDate = solution.getScheduleFirstUTCDate(); LocalDate lastDate = solution.getScheduleLastUTCDate(); for (LocalDate date = firstDate; date.compareTo(lastDate) <= 0; date = date.plusDays(1)) { nextHeaderCell(DAY_FORMATTER.format(date)); } for (Employee employee : solution.getEmployeeList()) { nextRow(); nextCell().setCellValue(employee.getName()); nextCell().setCellValue(employee.getHomeAirport().getCode()); nextCell().setCellValue(String.join(", ", employee.getSkillSet().stream().map(Skill::getName).collect(toList()))); for (LocalDate date = firstDate; date.compareTo(lastDate) <= 0; date = date.plusDays(1)) { nextCell(employee.getUnavailableDaySet().contains(date) ? unavailableStyle : defaultStyle) .setCellValue(""); } } autoSizeColumnsWithHeader(); }
@Test public void doWithEach() throws Exception { Table table = Table.read().csv("../data/bush.csv").first(5); DateColumn dc1 = table.dateColumn("date"); DateColumn dc2 = DateColumn.create("100 days later"); dc1.forEach(localDate -> dc2.append(localDate.plusDays(100))); assertEquals(dc1.get(0).plusDays(100), dc2.get(0)); } }
/** * Tests updating of all Date and Time fields. */ @Test public void testUpdateAllFields() { EntityWithDateTimeFields expEntity = new EntityWithDateTimeFields(entity); expEntity.setLocalTime(expEntity.getLocalTime().plusHours(1)); expEntity.setLocalDate(expEntity.getLocalDate().plusDays(1)); expEntity.setLocalDateTime(LocalDateTime.of(expEntity.getLocalDate(), expEntity.getLocalTime())); SqlFieldsQuery qry = new SqlFieldsQuery( "update EntityWithDateTimeFields set locTime = ?, locDate = ?, locDateTime = ? where id = ?" ).setArgs(expEntity.getLocalTime(), expEntity.getLocalDate(), expEntity.getLocalDateTime(), entity.getId()); List<List<?>> qryResults = cache.query(qry).getAll(); assertEquals(1, qryResults.size()); assertEquals(1L, qryResults.get(0).get(0)); assertEquals(expEntity, cache.get(expEntity.getId())); }