List of usage examples for org.joda.time DateTime minus
public DateTime minus(ReadablePeriod period)
From source file:com.pureblue.quant.util.frequency.CustomFrequency.java
@Override public DateTime periodBegin(DateTime time) { // TODO: improve efficiency by removing the while loops DateTime currentTime = startTime; if (time.isAfter(startTime)) { while (!currentTime.isAfter(time)) { currentTime = currentTime.plus(duration); }// w w w.j a v a 2 s .c o m return currentTime.minus(duration); } else { while (currentTime.isAfter(time)) { currentTime = currentTime.minus(duration); } return currentTime; } }
From source file:com.quant.Tick.java
License:Open Source License
/** * Constructor./* w ww. j a va 2 s. com*/ * @param timePeriod the time period * @param endTime the end time of the tiHck period */ public Tick(Period timePeriod, DateTime endTime) { checkTimeArguments(timePeriod, endTime); this.timePeriod = timePeriod; this.endTime = endTime; this.beginTime = endTime.minus(timePeriod); }
From source file:com.quant.Tick.java
License:Open Source License
/** * Constructor./*from w ww . jav a 2 s .c om*/ * @param timePeriod the time period * @param endTime the end time of the tick period * @param openPrice the open price of the tick period * @param highPrice the highest price of the tick period * @param lowPrice the lowest price of the tick period * @param closePrice the close price of the tick period * @param volume the volume of the tick period */ public Tick(Period timePeriod, DateTime endTime, Decimal openPrice, Decimal highPrice, Decimal lowPrice, Decimal closePrice, Decimal volume) { checkTimeArguments(timePeriod, endTime); this.timePeriod = timePeriod; this.endTime = endTime; this.beginTime = endTime.minus(timePeriod); this.openPrice = openPrice; this.maxPrice = highPrice; this.minPrice = lowPrice; this.closePrice = closePrice; this.volume = volume; }
From source file:com.robwilliamson.healthyesther.reminder.TimingModel.java
License:Open Source License
private void ensureNotificationIsPending() { DateTime now = mEnvironment.getNow(); DateTime next = mEnvironment.getNextNotificationTime(); if (next == null || next.isBefore(now) || next.minus(mPeriod).isAfter(now)) { setAlarm(getNextNotificationAfter(now)); } else {/* w w w . ja v a2 s.co m*/ setAlarm(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.serotonin.mango.util.DateUtils.java
License:Open Source License
public static DateTime minus(DateTime time, int periodType, int periods) { return time.minus(Common.getPeriod(periodType, periods)); }
From source file:com.serotonin.mango.util.DateUtils.java
License:Open Source License
public static DateTime truncateDateTime(DateTime time, int periodType) { if (periodType == TimePeriods.SECONDS) time = time.minus(time.getMillisOfSecond()); else if (periodType == TimePeriods.MINUTES) { time = time.minus(time.getMillisOfSecond()); time = time.minus(Common.getPeriod(TimePeriods.SECONDS, time.getSecondOfMinute())); } else if (periodType == TimePeriods.HOURS) { time = time.minus(time.getMillisOfSecond()); time = time.minus(Common.getPeriod(TimePeriods.SECONDS, time.getSecondOfMinute())); time = time.minus(Common.getPeriod(TimePeriods.MINUTES, time.getMinuteOfHour())); } else if (periodType == TimePeriods.DAYS) { time = time.minus(time.getMillisOfDay()); } else if (periodType == TimePeriods.WEEKS) { time = time.minus(time.getMillisOfDay()); time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfWeek() - 1)); } else if (periodType == TimePeriods.MONTHS) { time = time.minus(time.getMillisOfDay()); time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfMonth() - 1)); } else if (periodType == TimePeriods.YEARS) { time = time.minus(time.getMillisOfDay()); time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfYear() - 1)); }// www . ja va 2s . c o m return time; }
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;//from www.j ava 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 av a 2 s .co m*/ 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.tomtom.speedtools.metrics.MetricsCollector.java
License:Apache License
private void prune(@Nonnull final DateTime now) { assert now != null; final DateTime earliest = now.minus(totalMetricDuration); while (!values.isEmpty() && values.getFirst().startTime.isBefore(earliest)) { final MetricsTimeSlot slot = values.removeFirst(); this.sum -= slot.sum; this.count -= slot.count; this.sumSquares -= slot.sumSquares; }//w w w.j a va 2 s.co m }