List of usage examples for org.joda.time DateTime plus
public DateTime plus(ReadablePeriod period)
From source file:com.quant.TimeSeries.java
License:Open Source License
/** * Builds a list of split indexes from splitDuration. * @param splitDuration the duration between 2 splits * @return a list of begin indexes after split *///from w w w . j a va2s . c o m private List<Integer> getSplitBeginIndexes(Period splitDuration) { ArrayList<Integer> beginIndexes = new ArrayList<Integer>(); // Adding the first begin index beginIndexes.add(beginIndex); // Building the first interval before next split DateTime beginInterval = getTick(beginIndex).getEndTime(); DateTime endInterval = beginInterval.plus(splitDuration); Interval splitInterval = new Interval(beginInterval, endInterval); for (int i = beginIndex; i <= endIndex; i++) { // For each tick... DateTime tickTime = getTick(i).getEndTime(); if (!splitInterval.contains(tickTime)) { // Tick out of the interval if (!endInterval.isAfter(tickTime)) { // Tick after the interval // --> Adding a new begin index beginIndexes.add(i); } // Building the new interval before next split beginInterval = endInterval.isBefore(tickTime) ? tickTime : endInterval; endInterval = beginInterval.plus(splitDuration); splitInterval = new Interval(beginInterval, endInterval); } } return beginIndexes; }
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); }/*from w ww . j av a2s. 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.robwilliamson.healthyesther.reminder.TimingModel.java
License:Open Source License
private DateTime getNextNotificationAfter(DateTime before) { if (before == null) { before = mEnvironment.getNow();/*ww w. j av a 2 s .co m*/ } DateTime next = before.plus(mPeriod); if (allowedTimes().contains(next)) { return next; } next = allowedTimes().getEdgeAfter(next); if (next == null) { next = allowedTimes().to; } return next; }
From source file:com.robwilliamson.healthyesther.util.time.Range.java
License:Open Source License
public Range(DateTime centre, Duration sigma) { super(centre.minus(sigma), centre.plus(sigma)); this.centre = centre; this.sigma = sigma; }
From source file:com.robwilliamson.healthyesther.util.time.Range.java
License:Open Source License
public Range startingFrom(DateTime time) { return new Range(time, time.plus(sigma).plus(sigma)); }
From source file:com.sheepdog.mashmesh.models.VolunteerProfile.java
License:Apache License
public void addAppointmentTime(RideRequest rideRequest, DateTime departureTime, DateTime arrivalTime) { Duration commuteDuration = new Duration(departureTime, arrivalTime); DateTime startTime = departureTime;//from w ww . j av a 2 s . c o m DateTime endTime = arrivalTime.plus(commuteDuration); AppointmentPeriod appointmentTime = new AppointmentPeriod(); appointmentTime.rideRequestId = rideRequest.getId(); appointmentTime.startTimeMillis = startTime.getMillis(); appointmentTime.endTimeMillis = endTime.getMillis(); appointmentTimes.add(appointmentTime); }
From source file:com.sonicle.webtop.calendar.CalendarManager.java
License:Open Source License
@Override public void updateEventInstance(UpdateEventTarget target, EventKey key, DateTime newStart, DateTime newEnd, String newTitle, boolean notifyAttendees) throws WTException { CalendarDAO calDao = CalendarDAO.getInstance(); Connection con = null;/* ww w.j av a 2 s .c o m*/ try { con = WT.getConnection(SERVICE_ID, false); EventInstance ei = doEventInstanceGet(con, key.eventId, key.instanceDate, true); int calendarId = ei.getCalendarId(); checkRightsOnCalendarElements(calendarId, "UPDATE"); String provider = calDao.selectProviderById(con, calendarId); if (Calendar.isProviderRemote(provider)) throw new WTException("Calendar is remote and therefore read-only [{}]", calendarId); if ((newStart != null) && (newEnd != null)) { ei.setStartDate(newStart); ei.setEndDate(newEnd); } else if (newStart != null) { Duration length = new Duration(ei.getStartDate(), ei.getEndDate()); ei.setStartDate(newStart); ei.setEndDate(newStart.plus(length)); } else if (newEnd != null) { Duration length = new Duration(ei.getStartDate(), ei.getEndDate()); ei.setStartDate(newEnd.minus(length)); ei.setEndDate(newEnd); } if (newTitle != null) { ei.setTitle(newTitle); } ei.ensureCoherence(); doEventInstanceUpdateAndCommit(con, target, key, ei, notifyAttendees); } catch (SQLException | DAOException | IOException | WTException ex) { DbUtils.rollbackQuietly(con); throw wrapException(ex); } finally { DbUtils.closeQuietly(con); } }
From source file:com.sonicle.webtop.calendar.CalendarManager.java
License:Open Source License
@Override public Event cloneEventInstance(EventKey key, Integer newCalendarId, DateTime newStart, DateTime newEnd, boolean notifyAttendees) throws WTException { Connection con = null;//w w w . j ava2 s .c om EventInstance ei = null; try { con = WT.getConnection(SERVICE_ID); ei = doEventInstanceGet(con, key.eventId, key.instanceDate, true); checkRightsOnCalendarFolder(ei.getCalendarId(), "READ"); int calendarId = (newCalendarId != null) ? newCalendarId : ei.getCalendarId(); ei.setCalendarId(calendarId); ei.setPublicUid(null); // Reset value in order to make inner function generate new one! ei.setHref(null); // Reset value in order to make inner function generate new one! if ((newStart != null) && (newEnd != null)) { ei.setStartDate(newStart); ei.setEndDate(newEnd); } else if (newStart != null) { Duration length = new Duration(ei.getStartDate(), ei.getEndDate()); ei.setStartDate(newStart); ei.setEndDate(newStart.plus(length)); } else if (newEnd != null) { Duration length = new Duration(ei.getStartDate(), ei.getEndDate()); ei.setStartDate(newEnd.minus(length)); ei.setEndDate(newEnd); } } catch (SQLException | DAOException | WTException ex) { throw wrapException(ex); } finally { DbUtils.closeQuietly(con); } return addEvent(ei, notifyAttendees); }
From source file:com.stagecents.pay.domain.Overtime.java
License:Open Source License
@Override public void processHours(Interval interval, Activity activity, Timecard timecard, Position position) { DateTime start = interval.getStart(); DateTime end = interval.getEnd(); // 1. Test start time against normal start time. DateTime regStart = start;//from w w w. j a v a 2 s . c o m if (position.getNormalStart() != null) { DateTime normalStart = start.toLocalDate().toDateTime(position.getNormalStart()); regStart = regStart.isBefore(normalStart) ? normalStart : regStart; } // Update the time card with any premium time prior to the position's // normal start if (start.isBefore(regStart)) { updateTimecard(timecard, activity, new Interval(start, regStart)); } // 2. Test end time against minimum call. MinimumCallValue mc = getMinimumCall(new Interval(start, end)); if (mc != null) { long minCall = (long) mc.getDefaultValue() * 1000 * 60 * 60; DateTime minCallEnd = end.plus(minCall); end = end.isBefore(minCallEnd) ? minCallEnd : end; } // Test end time against normal end time. DateTime regEnd = end; if (position.getNormalEnd() != null) { DateTime normalEnd = end.toLocalDate().toDateTime(position.getNormalEnd()); regEnd = normalEnd.isBefore(regEnd) ? normalEnd : regEnd; } // Test end time against maximum time for position. if (position.getMaximumHours() > 0) { float priorHrs = getPriorHours(timecard, regStart.toLocalDate()); long availMillis = (long) (position.getMaximumHours() - priorHrs) * 1000 * 60 * 60; DateTime availEnd = regStart.plus(availMillis); regEnd = availEnd.isBefore(regEnd) ? availEnd : regEnd; } // Update the timecard with any premium time after the position's normal // end if (regEnd.isBefore(end)) { updateTimecard(timecard, activity, new Interval(regEnd, end)); } }
From source file:com.stagecents.pay.domain.RegularWages.java
License:Open Source License
protected void doProcessHours(Interval interval, Activity activity, Timecard timecard, Position position) { DateTime start = interval.getStart(); DateTime end = interval.getEnd(); // Test start time against normal start time. if (position.getNormalStart() != null) { DateTime normalStart = start.toLocalDate().toDateTime(position.getNormalStart()); start = start.isBefore(normalStart) ? normalStart : start; }//w w w. j a va2 s . c o m // Test end time against minimum call. MinimumCallValue mc = getMinimumCall(activity.duration()); if (mc != null) { long minCall = (long) mc.getDefaultValue() * 1000 * 60 * 60; DateTime minCallEnd = end.plus(minCall); end = end.isBefore(minCallEnd) ? minCallEnd : end; } // Test end time against normal end time. if (position.getNormalEnd() != null) { DateTime normalEnd = end.toLocalDate().toDateTime(position.getNormalEnd()); end = end.isAfter(normalEnd) ? normalEnd : end; } // Test end time against maximum time for position. if (position.getMaximumHours() > 0) { float priorHours = getPriorHours(timecard, start.toLocalDate()); long availMillis = (long) (position.getMaximumHours() - priorHours) * 1000 * 60 * 60; DateTime availEnd = start.plus(availMillis); end = availEnd.isBefore(end) ? availEnd : end; } updateTimecard(timecard, activity, new Interval(start, end)); }