List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:com.qcadoo.view.internal.components.ganttChart.GanttChartScaleImpl.java
License:Open Source License
private JSONArray getDaysArray() { JSONArray daysArray = new JSONArray(); DateTime dateTimeFrom = new DateTime(dateFrom); DateTime dateTimeTo = new DateTime(dateTo); while (dateTimeFrom.compareTo(dateTimeTo) <= 0) { daysArray.put(DATETYPE.toString(dateTimeFrom.toDate(), ganttChartComponentState.getLocale())); dateTimeFrom = dateTimeFrom.plusDays(1); }// w w w .j a v a2s .c o m return daysArray; }
From source file:com.qcadoo.view.internal.components.grid.PredefinedFilter.java
License:Open Source License
private static String evalExpression(final String expression) { DateTime today = new DateTime(); DateTime date;//from w ww . j a v a2 s . c om if ("today".equals(expression)) { date = today; } else if ("yesterday".equals(expression)) { date = today.minusDays(1); } else if ("tomorrow".equals(expression)) { date = today.plusDays(1); } else { throw new IllegalStateException("unsupported predefined filter expression: '" + expression + "'"); } return new SimpleDateFormat(DateUtils.L_DATE_FORMAT, getLocale()).format(date.toDate()); }
From source file:com.quinsoft.zeidon.domains.DateTimeDomain.java
License:Open Source License
private Object addWithContext(Task task, AttributeInstance attributeInstance, AttributeDef attributeDef, Object currentValue, Object operand, String contextName) { assert !StringUtils.isBlank(contextName); if (operand instanceof AttributeInstance) operand = ((AttributeInstance) operand).getValue(); if (!(operand instanceof Integer) && !(operand instanceof Long)) { throw new ZeidonException( "When adding to DateTime with a context, operand must be integer or long value. " + "Type of operand = %s", operand.getClass().getName()).prependAttributeDef(attributeDef); }/* w w w . j a va2 s.c o m*/ int value = ((Number) operand).intValue(); DateTime dt = (DateTime) currentValue; switch (contextName.toLowerCase()) { case "day": case "days": return dt.plusDays(value); case "hour": case "hours": return dt.plusHours(value); case "minute": case "minutes": return dt.plusMinutes(value); case "milli": case "millis": case "millisecond": case "milliseconds": return dt.plus(((Number) operand).longValue()); case "month": case "months": return dt.plusMonths(value); case "second": case "seconds": return dt.plusSeconds(value); case "week": case "weeks": return dt.plusWeeks(value); case "year": case "years": return dt.plusYears(value); } // TODO Auto-generated method stub throw new ZeidonException("Unknown context name '%s' for DateTime domain", contextName) .prependAttributeDef(attributeDef); }
From source file:com.quinsoft.zeidon.vml.VmlOperation.java
License:Open Source License
protected int AddToAttributeFromVariable(View view, String entityName, String attributeName, Object value, char variableType, int maxLth, String contextName) { int nRC = 0;/* w w w . ja v a2 s .c o m*/ EntityCursor cursor = view.cursor(entityName); if (cursor.isNull()) { nRC = zCALL_ERROR; } else { if (contextName.equals("Month")) { int nMonths = ((Number) value).intValue(); DateTime date = view.cursor(entityName).getAttribute(attributeName).getDateTime(); DateTime date2 = date.plusMonths(nMonths); view.cursor(entityName).getAttribute(attributeName).setValue(date2); } else if (contextName.equals("Day")) { int nDays = ((Number) value).intValue(); DateTime date = view.cursor(entityName).getAttribute(attributeName).getDateTime(); DateTime date2 = date.plusDays(nDays); view.cursor(entityName).getAttribute(attributeName).setValue(date2); } else { cursor.getAttribute(attributeName).add(value); } } return nRC; }
From source file:com.revetkn.achewood.AchewoodExtractor.java
License:Open Source License
/** * Pulls strips from the web and saves them locally, starting with * <tt>INITIAL_STRIP_DATE</tt> and ending with today's date. * @throws IOException If an error occurs during processing. *//*from w w w . j a va2 s . c o m*/ public void execute() throws IOException { int stripsRead = 0; int totalAttempts = 0; DateTime stripDate = ACHEWOOD_DATE_FORMATTER.parseDateTime(INITIAL_STRIP_DATE); while (stripDate.isBeforeNow()) { System.out.print("Checking " + LONG_DATE_FORMATTER.print(stripDate) + "..."); ++totalAttempts; byte[] strip = retrieveStrip(stripDate); // Only process if we find a strip if (strip != null) { System.out.println("found a strip."); saveStrip(strip, stripDate); ++stripsRead; } else { System.out.println("no strip exists for that day."); } stripDate = stripDate.plusDays(1); waitAFewSeconds(); } System.out.println(stripsRead + " strips read in " + totalAttempts + " attempts."); }
From source file:com.ro.ssc.app.client.service.impl.DataProviderImplHelper.java
private static Set<String> getNeededPresence(Map<String, User> userData, Map<String, Map<String, ShiftData>> shiftData, String user, DateTime inidate, DateTime endate) { Set<String> result = new HashSet<>(); String userId = userData.get(user).getUserId().trim(); if (shiftData.containsKey(userId)) { for (String day : shiftData.get(userId).keySet()) { if (!shiftData.get(userId).get(day).getShiftId().equals("0") && DateTime.parse(day, dtf3).plusDays(1).isAfter(inidate) && DateTime.parse(day, dtf3).isBefore(endate.plusDays(1))) { result.add(day);// ww w . j ava 2 s. co m } } } return result; }
From source file:com.ro.ssc.app.client.service.impl.DataProviderImplHelper.java
public static List<DailyData> getListPerDay(Map<String, User> userData, LocalTime time, Map<String, Map<String, ShiftData>> shiftData, Set<String> excludedGates, String userName, DateTime iniDate, DateTime endDate) { List<DailyData> result = new ArrayList(); Collections.sort(userData.get(userName).getEvents(), (c1, c2) -> c1.getEventDateTime().compareTo(c2.getEventDateTime())); Map<Pair<DateTime, DateTime>, List<Pair<Event, Event>>> eventsPerDay; Map<DateTime, List<Event>> wrongPerDay; Set<String> usedDates = new HashSet<>(); String userId = userData.get(userName).getUserId().trim(); if (Configuration.IS_EXPIRED.getAsBoolean()) { eventsPerDay = splitPerDay(time, applyExcludeLogic(excludedGates, userData.get(userName).getEvents()).get(0), iniDate, endDate); wrongPerDay = splitPerDayWrong(time, applyExcludeLogic(excludedGates, userData.get(userName).getEvents()).get(1), iniDate, endDate); } else {//from w w w. j av a 2 s. c o m eventsPerDay = splitPerDay(time, applyExcludeLogic2(excludedGates, userData.get(userName).getEvents()).get(0), iniDate, endDate); wrongPerDay = splitPerDayWrong(time, applyExcludeLogic2(excludedGates, userData.get(userName).getEvents()).get(1), iniDate, endDate); } for (DateTime date = iniDate.withTimeAtStartOfDay(); date .isBefore(endDate.plusDays(1).withTimeAtStartOfDay()); date = date.plusDays(1)) { final DateTime currentDateAsDateTime = date; for (Map.Entry<Pair<DateTime, DateTime>, List<Pair<Event, Event>>> entry : eventsPerDay.entrySet()) { if (entry.getKey().getKey().withTimeAtStartOfDay().isEqual(currentDateAsDateTime)) { Long duration = 0l; for (Pair<Event, Event> pair : entry.getValue()) { duration = duration + pair.getValue().getEventDateTime().getMillis() - pair.getKey().getEventDateTime().getMillis(); } Long pause = entry.getKey().getValue().getMillis() - entry.getKey().getKey().getMillis() - duration; Long overtime = 0l; Long latetime = 0l; Long earlytime = 0l; if (shiftData.containsKey(userId)) { final Map<String, ShiftData> shiftDataMapForUser = shiftData.get(userId); if (shiftDataMapForUser.containsKey(currentDateAsDateTime.toString(dtf3))) { ShiftData shiftDataInCurrentDate = shiftDataMapForUser .get(currentDateAsDateTime.toString(dtf3)); if (shiftDataInCurrentDate.getShiftId().equals("0")) { if (shiftDataInCurrentDate.isHasOvertime()) { overtime = duration; } } else { LocalTime officialStart = LocalTime .from(dtf4.parse(shiftDataInCurrentDate.getShiftStartHour())); LocalTime officialEnd = LocalTime .from(dtf4.parse(shiftDataInCurrentDate.getShiftEndHour())); long dailyPause = Long.valueOf(shiftDataInCurrentDate.getShiftBreakTime()) * 1000 * 60l; long dailyHours = officialEnd.isAfter(officialStart) ? 1000 * (officialEnd.toSecondOfDay() - officialStart.toSecondOfDay()) : 1000 * (officialEnd.toSecondOfDay() + (24 * 60 * 60 - officialStart.toSecondOfDay())); if (shiftDataInCurrentDate.isHasOvertime()) { if (pause > dailyPause) { overtime = duration - dailyHours + dailyPause; } else { overtime = duration + pause - dailyHours; duration = duration - (dailyPause - pause) > 0 ? duration - (dailyPause - pause) : 0; pause = dailyPause; } log.debug(userName + " data " + currentDateAsDateTime.toString(dtf3) + " overtime " + overtime); } else { if (duration < dailyHours - dailyPause) { overtime = duration - dailyHours + dailyPause; } } earlytime = entry.getKey().getValue().getSecondOfDay() < officialEnd.toSecondOfDay() ? 1000 * (officialEnd.toSecondOfDay() - entry.getKey().getValue().getSecondOfDay()) : 0l; latetime = entry.getKey().getKey().getSecondOfDay() > officialStart.toSecondOfDay() ? 1000 * (entry.getKey().getKey().getSecondOfDay() - officialStart.toSecondOfDay()) : 0l; } } } result.add(new DailyData(userId, date, entry.getKey().getKey().toString(dtf), entry.getKey().getValue().toString(dtf), earlytime, duration, duration, pause, overtime, latetime, wrongPerDay.get(currentDateAsDateTime))); usedDates.add(currentDateAsDateTime.toString(dtf3)); } } } for (String day : getNeededPresence(userData, shiftData, userName, iniDate, endDate)) { if (!usedDates.contains(day)) { ShiftData shiftDataInCurrentDate = shiftData.get(userId).get(day); LocalTime officialStart = LocalTime.from(dtf4.parse(shiftDataInCurrentDate.getShiftStartHour())); LocalTime officialEnd = LocalTime.from(dtf4.parse(shiftDataInCurrentDate.getShiftEndHour())); long dailyPause = Long.valueOf(shiftDataInCurrentDate.getShiftBreakTime()) * 1000 * 60l; long dailyHours = officialEnd.isAfter(officialStart) ? 1000 * (officialEnd.toSecondOfDay() - officialStart.toSecondOfDay()) : 1000 * (officialEnd.toSecondOfDay() + (24 * 60 * 60 - officialStart.toSecondOfDay())); if (wrongPerDay.containsKey(DateTime.parse(day, dtf3))) { if (wrongPerDay.get(DateTime.parse(day, dtf3)).size() > 0) { String ev = wrongPerDay.get(DateTime.parse(day, dtf3)).get(0).getEventDateTime() .toString(dtf); Boolean isIn = wrongPerDay.get(DateTime.parse(day, dtf3)).get(0).getAddr().contains("In"); result.add(new DailyData(userId, DateTime.parse(day, dtf3), isIn == true ? ev : "", isIn == false ? ev : "", 0, 0, 0, 0, dailyPause - dailyHours, 0, wrongPerDay.get(DateTime.parse(day, dtf3)))); } else { result.add(new DailyData(userId, DateTime.parse(day, dtf3), "", "", 0, 0, 0, 0, dailyPause - dailyHours, 0, new ArrayList<>())); } } else { result.add(new DailyData(userId, DateTime.parse(day, dtf3), "", "", 0, 0, 0, 0, dailyPause - dailyHours, 0, new ArrayList<>())); } } } return result; }
From source file:com.ro.ssc.app.client.utils.Utils.java
public static Map<Pair<DateTime, DateTime>, List<Pair<Event, Event>>> splitPerDay(LocalTime time, List<Event> events, DateTime iniDate, DateTime endDate) { Map<Pair<DateTime, DateTime>, List<Pair<Event, Event>>> result = new LinkedHashMap<>(); List<Pair<Event, Event>> pairedEvents = new LinkedList<>(); List<Pair<Event, Event>> perDayList = new LinkedList<>(); List<Pair<Event, Event>> additionalList = new LinkedList<>(); if (!events.isEmpty()) { pairedEvents = Seq.seq(events.iterator()).window() .filter(w -> w.lead().isPresent() && w.value().getAddr().contains("In")) .map(w -> new Pair<>(w.value(), w.lead().get())) // alternatively, use your new Pair() class .toList();/* www.j a v a 2 s . c om*/ for (DateTime date = iniDate.withTimeAtStartOfDay(); date .isBefore(endDate.plusDays(1).withTimeAtStartOfDay()); date = date.plusDays(1)) { final DateTime dd = date; perDayList = pairedEvents.stream() .filter(o -> o.getKey().getEventDateTime().withTimeAtStartOfDay().isEqual(dd)) .collect(Collectors.toList()); perDayList.removeAll(additionalList); additionalList.clear(); if (!perDayList.isEmpty()) { final DateTime evt = perDayList.get(perDayList.size() - 1).getValue().getEventDateTime(); if (evt.isAfter(date.plusDays(1))) { additionalList = pairedEvents.stream() .filter(o -> o.getValue().getEventDateTime().isAfter(evt) && o.getValue().getEventDateTime() .isBefore(dd.plusDays(1).plusHours(time.getHour()) .plusMinutes(time.getMinute()))) .collect(Collectors.toList()); perDayList.addAll(additionalList); if (!additionalList.isEmpty()) { result.put( new Pair(perDayList.get(0).getKey().getEventDateTime(), additionalList .get(additionalList.size() - 1).getValue().getEventDateTime()), perDayList); } else { result.put( new Pair(perDayList.get(0).getKey().getEventDateTime(), perDayList.get(perDayList.size() - 1).getValue().getEventDateTime()), perDayList); } } else { result.put( new Pair(perDayList.get(0).getKey().getEventDateTime(), perDayList.get(perDayList.size() - 1).getValue().getEventDateTime()), perDayList); } } } } return result; }
From source file:com.ro.ssc.app.client.utils.Utils.java
public static Map<DateTime, List<Event>> splitPerDayWrong(LocalTime time, List<Event> events, DateTime iniDate, DateTime endDate) { Map<DateTime, List<Event>> result = new LinkedHashMap<>(); List<Event> perDayList = new LinkedList<>(); if (!events.isEmpty()) { for (DateTime date = iniDate.withTimeAtStartOfDay(); date .isBefore(endDate.plusDays(1).withTimeAtStartOfDay()); date = date.plusDays(1)) { final DateTime dd = date; perDayList = events.stream().filter(o -> o.getEventDateTime().withTimeAtStartOfDay().isEqual(dd)) .collect(Collectors.toList()); result.put(dd, perDayList);//from w w w.j ava 2 s . c om } } return result; }
From source file:com.salesmanBuddy.dao.JDBCSalesmanBuddyDAO.java
License:Open Source License
private String wrapReportContentWithBeginningEnd(String content, ReportBeginEnd beginning, ReportBeginEnd ending, Integer dealershipId, DateTime from, DateTime to) { boolean useDefaultEnding = false; String timePeriod = ""; if (to.isAfter(from.plusMonths(1))) timePeriod = "Monthly "; else if (to.isAfter(from.plusWeeks(1))) timePeriod = "Weekly "; else if (to.isAfter(from.plusDays(1))) timePeriod = "Daily "; StringBuilder sb = new StringBuilder(); Dealerships dealership = this.getDealershipById(dealershipId); String fromTo = new StringBuilder().append(this.printTimeDateForReports(from)).append(" to ") .append(this.printTimeDateForReports(to)).toString(); switch (beginning) { case AllSalesmen: sb.append("All Salesmen ").append(timePeriod).append("summary report for ").append(dealership.getName()) .append(" from ").append(fromTo).append(".\n\n"); sb.append(content);//from w ww .j a v a 2 s. co m useDefaultEnding = true; break; case DealershipSummary: sb.append("Dealership-Wide ").append(timePeriod).append("summary report for ") .append(dealership.getName()).append(" from ").append(fromTo).append(".\n\n"); sb.append(content); useDefaultEnding = true; break; case StockNumberSummary: sb.append("Stock Number ").append(timePeriod).append("summary report for ").append(dealership.getName()) .append(" from ").append(fromTo).append(".\n\n"); sb.append(content); useDefaultEnding = true; break; case TestDriveNow: sb.append(content); useDefaultEnding = true; break; case TestDriveSummary: sb.append("Test Drive ").append(timePeriod).append("summary report for ").append(dealership.getName()) .append(" from ").append(fromTo).append(".\n\n"); sb.append(content); useDefaultEnding = true; break; case Warnings: sb.append("Warnings ").append(timePeriod).append("report for ").append(dealership.getName()) .append(" from ").append(fromTo).append(".\n\n"); sb.append(content); useDefaultEnding = true; break; default: break; } if (useDefaultEnding) sb.append("\n\nThank you for using Salesman Buddy. If you have any questions, contact us at ") .append(SUPPORT_EMAIL); return sb.toString(); }