List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:com.almende.eve.agent.MeetingAgent.java
License:Apache License
/** * Retrieve the busy intervals of a calendar agent * //from ww w . j av a2 s .co m * @param agent */ private void updateBusyInterval(@Name("agent") final String agent) { try { // create parameters with the boundaries of the interval to be // retrieved final ObjectNode params = JOM.createObjectNode(); final DateTime timeMin = DateTime.now(); final DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS); params.put("timeMin", timeMin.toString()); params.put("timeMax", timeMax.toString()); // exclude the event managed by this agent from the busy intervals final String eventId = getAgentData(agent).eventId; if (eventId != null) { final ArrayNode excludeEventIds = JOM.createArrayNode(); excludeEventIds.add(eventId); params.put("excludeEventIds", excludeEventIds); } // get the busy intervals from the agent final ArrayNode array = send(URI.create(agent), "getBusy", params, ArrayNode.class); // convert from ArrayNode to List final List<Interval> busy = new ArrayList<Interval>(); for (int i = 0; i < array.size(); i++) { final ObjectNode obj = (ObjectNode) array.get(i); final String start = obj.has("start") ? obj.get("start").asText() : null; final String end = obj.has("end") ? obj.get("end").asText() : null; busy.add(new Interval(new DateTime(start), new DateTime(end))); } // store the interval in the state putAgentBusy(agent, busy); } catch (final JSONRPCException e) { addIssue(TYPE.warning, Issue.JSONRPCEXCEPTION, e.getMessage()); LOG.log(Level.WARNING, "", e); } catch (final Exception e) { addIssue(TYPE.warning, Issue.EXCEPTION, e.getMessage()); LOG.log(Level.WARNING, "", e); } }
From source file:com.aurel.track.linkType.MsProjectLinkTypeBL.java
License:Open Source License
/** * Returns number of free days from given interval, start date included always, endDate only if includeLastDay == true! * @param startDateParam/*from w w w . ja v a 2 s . c o m*/ * @param endDateParam * @param includeLastDay * @return */ public static Integer getNumberOfDaysBetweenDates(Date startDateParam, Date endDateParam, boolean includeLastDay) { DateTime dateTime1 = new DateTime(startDateParam); DateTime dateTime2 = new DateTime(endDateParam); if (includeLastDay) { dateTime2 = dateTime2.plusDays(1); } int numberOfDays = Days.daysBetween(dateTime1, dateTime2).getDays(); return numberOfDays; }
From source file:com.aurel.track.util.DateTimeUtils.java
License:Open Source License
/** * Add numberOfDays to a date /*www. ja va 2s .c om*/ * @param date * @param numberOfDays * @param jumpOverWeekend * @return */ public static Date moveByDays(Date date, int numberOfDays, boolean add, boolean onlyWorkdays) { DateTime dateTime = new DateTime(getZeroTimeDate(date)); if (onlyWorkdays) { int i = 0; while (i < numberOfDays) { if (add) { dateTime = dateTime.plusDays(1); } else { dateTime = dateTime.minusDays(1); } if (dateTime.getDayOfWeek() <= 5) { i++; } } } else { if (add) { dateTime = dateTime.plusDays(numberOfDays); } else { dateTime = dateTime.minusDays(numberOfDays); } } return dateTime.toDate(); }
From source file:com.aurel.track.util.DateTimeUtils.java
License:Open Source License
/** * Returns number of free days from given interval, start date included always, endDate only if includeLastDay == true! * @param startDateParam/*from ww w . j a v a 2s. co m*/ * @param endDateParam * @param includeLastDay * @return */ public static int getDurationBetweenDates(Date startDateParam, Date endDateParam, boolean onlyWorkdays) { DateTime dateTime1 = new DateTime(getZeroTimeDate(startDateParam)); DateTime dateTime2 = new DateTime(getZeroTimeDate(endDateParam)); int i = 0; if (onlyWorkdays) { while (dateTime1.isBefore(dateTime2)) { dateTime1 = dateTime1.plusDays(1); int dayOfWeek = dateTime1.getDayOfWeek(); if (dayOfWeek <= 5) { //weekday i++; } else { //end date explicitly set on Saturday or Sunday: take this week end day(s) as working day if (!dateTime1.isBefore(dateTime2)) { if (dayOfWeek == 6) { //add one day for task ending on Saturday i++; } else { //add two days for task ending on Sunday i = i + 2; } } } } return i; } else { return Days.daysBetween(dateTime1, dateTime2).getDays() + 1; } }
From source file:com.boha.golfkids.util.NewGolfGroupUtil.java
private static void generateExampleTournament(boolean isLive, GolfGroup gg, List<Player> pList, int clubID, String tournamentName, int rounds, boolean useAgeGroups, int holesPerRound, int gender, DataUtil dataUtil, PlatformUtil platformUtil) throws DataException { DateTime dt = new DateTime(); dt = dt.minusDays(7);//ww w . j av a2s.c o m // TournamentDTO t = new TournamentDTO(); t.setTourneyName(tournamentName); t.setGolfRounds(rounds); t.setStartDate(dt.getMillis()); t.setClubID(clubID); t.setGolfGroupID(gg.getGolfGroupID()); t.setHolesPerRound(holesPerRound); t.setExampleFlag(1); t.setTournamentType(RequestDTO.STROKE_PLAY_INDIVIDUAL); if (holesPerRound == 9) { t.setPar(36); } else { t.setPar(72); } if (rounds > 1) { for (int i = 0; i < rounds; i++) { dt = dt.plusDays(i); } t.setEndDate(dt.getMillis()); } else { t.setEndDate(t.getStartDate()); } if (useAgeGroups) { t.setUseAgeGroups(1); } ResponseDTO r = dataUtil.addTournament(t, platformUtil); Tournament tournament = new Tournament(); List<TournamentDTO> tList = r.getTournaments(); for (TournamentDTO tn : tList) { if (tn.getTourneyName().equalsIgnoreCase(t.getTourneyName())) { tournament = dataUtil.getTournamentByID(tn.getTournamentID()); break; } } List<LeaderBoard> list = addPlayersToTournament(pList, tournament, gender, dataUtil, platformUtil); log.log(Level.INFO, "LeaderBoard items generated, about to score: {0}", list.size()); List<TourneyScoreByRound> tsbrList = generateScores(list, tournament.getTournamentID(), dataUtil, tournament.getGolfRounds()); if (isLive) { generateScoresForLiveLeaderBoard(tsbrList, list, tournament, dataUtil, rounds); } log.log(Level.OFF, "Sample Tournament generated: {0} - {1}", new Object[] { gg.getGolfGroupName(), tournamentName }); }
From source file:com.cisco.dvbu.ps.utils.date.DateAddDate.java
License:Open Source License
/** * Called to invoke the stored procedure. Will only be called a * single time per instance. Can throw CustomProcedureException or * SQLException if there is an error during invoke. *///from w w w . j a v a 2s . co m @Override public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { java.util.Date startDate = null; Calendar startCal = null; DateTime startDateTime = null; DateTime endDateTime = null; String datePart = null; int dateLength = 0; try { result = null; if (inputValues[0] == null || inputValues[1] == null || inputValues[2] == null) { return; } datePart = (String) inputValues[0]; dateLength = (Integer) inputValues[1]; startDate = (java.util.Date) inputValues[2]; startCal = Calendar.getInstance(); startCal.setTime(startDate); startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1, startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0); if (datePart.equalsIgnoreCase("second")) { endDateTime = startDateTime.plusSeconds(dateLength); } if (datePart.equalsIgnoreCase("minute")) { endDateTime = startDateTime.plusMinutes(dateLength); } if (datePart.equalsIgnoreCase("hour")) { endDateTime = startDateTime.plusHours(dateLength); } if (datePart.equalsIgnoreCase("day")) { endDateTime = startDateTime.plusDays(dateLength); } if (datePart.equalsIgnoreCase("week")) { endDateTime = startDateTime.plusWeeks(dateLength); } if (datePart.equalsIgnoreCase("month")) { endDateTime = startDateTime.plusMonths(dateLength); } if (datePart.equalsIgnoreCase("year")) { endDateTime = startDateTime.plusYears(dateLength); } result = new java.sql.Date(endDateTime.getMillis()); } catch (Throwable t) { throw new CustomProcedureException(t); } }
From source file:com.cisco.dvbu.ps.utils.date.DateAddTimestamp.java
License:Open Source License
/** * Called to invoke the stored procedure. Will only be called a * single time per instance. Can throw CustomProcedureException or * SQLException if there is an error during invoke. */// w w w. j av a 2 s . co m @Override public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { Timestamp startDate = null; Calendar startCal = null; DateTime startDateTime = null; DateTime endDateTime = null; String datePart = null; int dateLength = 0; try { result = null; if (inputValues[0] == null || inputValues[1] == null || inputValues[2] == null) { return; } datePart = (String) inputValues[0]; dateLength = (Integer) inputValues[1]; startDate = (Timestamp) inputValues[2]; startCal = Calendar.getInstance(); startCal.setTime(startDate); startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1, startCal.get(Calendar.DAY_OF_MONTH), startCal.get(Calendar.HOUR_OF_DAY), startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND), startCal.get(Calendar.MILLISECOND)); if (datePart.equalsIgnoreCase("second")) { endDateTime = startDateTime.plusSeconds(dateLength); } if (datePart.equalsIgnoreCase("minute")) { endDateTime = startDateTime.plusMinutes(dateLength); } if (datePart.equalsIgnoreCase("hour")) { endDateTime = startDateTime.plusHours(dateLength); } if (datePart.equalsIgnoreCase("day")) { endDateTime = startDateTime.plusDays(dateLength); } if (datePart.equalsIgnoreCase("week")) { endDateTime = startDateTime.plusWeeks(dateLength); } if (datePart.equalsIgnoreCase("month")) { endDateTime = startDateTime.plusMonths(dateLength); } if (datePart.equalsIgnoreCase("year")) { endDateTime = startDateTime.plusYears(dateLength); } result = new Timestamp(endDateTime.toDate().getTime()); } catch (Throwable t) { throw new CustomProcedureException(t); } }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method to create date and time object based on input. By default 1 hour * will be added if hrs parameter is 0./* w w w.j a va 2s . co m*/ * * @param days * (create date and time object based on number of days) * @param hrs * (create date and time object based on number of hours) * @param mins * (create date and time object based on number of minutes) * @return startDate (return date and time object based on the parameters) */ public DateTime getDateTime(final int days, final int hrs, final int mins) { DateTime startDate = this.getDateTime(); if (startDate.getMinuteOfHour() < 60) { startDate = this.getAgedDateTime(startDate.plusDays(days)).plusHours(hrs + 1).withMinuteOfHour(mins) .withSecondOfMinute(0).withMillisOfSecond(0); } return startDate; }
From source file:com.cloudhopper.commons.util.time.DateTimePeriod.java
License:Apache License
/** * Converts this period to a list of day periods. Partial days will not be * included. For example, a period of "January 2009" will return a list * of 31 days - one for each day in January. On the other hand, a period * of "January 20, 2009 13:00-59" would return an empty list since partial * days are not included./*from w w w . j a va 2 s .c o m*/ * @return A list of day periods contained within this period */ public List<DateTimePeriod> toDays() { ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>(); // default "current" day to start datetime DateTime currentStart = getStart(); // calculate "next" day DateTime nextStart = currentStart.plusDays(1); // continue adding until we've reached the end while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) { // its okay to add the current list.add(new DateTimeDay(currentStart, nextStart)); // increment both currentStart = nextStart; nextStart = currentStart.plusDays(1); } return list; }
From source file:com.cloudhopper.commons.util.time.DateTimePeriod.java
License:Apache License
static public DateTimePeriod createDay(DateTime start) { DateTime end = start.plusDays(1); return new DateTimeDay(start, end); }