Example usage for org.joda.time DateTime minusDays

List of usage examples for org.joda.time DateTime minusDays

Introduction

In this page you can find the example usage for org.joda.time DateTime minusDays.

Prototype

public DateTime minusDays(int days) 

Source Link

Document

Returns a copy of this datetime minus the specified number of days.

Usage

From source file:org.springframework.xd.dirt.rest.metrics.AggregateCountersController.java

License:Apache License

/**
 * Return a default value for the interval start if none has been provided.
 *//* w  ww . j a  v a  2 s  .  c o  m*/
private DateTime providedOrDefaultFromValue(DateTime from, DateTime to, AggregateCountResolution resolution) {
    if (from != null) {
        return from;
    }
    switch (resolution) {
    case minute:
        return to.minusMinutes(59);
    case hour:
        return to.minusHours(23);
    case day:
        return to.minusDays(6);
    case month:
        return to.minusMonths(11);
    case year:
        return to.minusYears(4);
    default:
        throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution);
    }
}

From source file:org.tanrabad.survey.repository.persistence.DbPlaceRepository.java

License:Apache License

private String surveyWithRangeCondition() {
    DateTime dateTime = ThaiDateTimeConverter.convert(new DateTime().toString());
    return "date(" + DbSurveyRepository.TABLE_NAME + "." + SurveyColumn.CREATE_TIME + ")" + " BETWEEN date('"
            + dateTime.minusDays(BuildConfig.SURVEY_RANGE_DAY) + "') " + "AND date('" + dateTime + "') ";
}

From source file:org.tanrabad.survey.service.ApiSyncInfoPreference.java

License:Apache License

public void backLastUpdateTimeToYesterday() {
    DateTimeFormatter rfc1123Formatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'");
    DateTime dateTime = rfc1123Formatter.parseDateTime(get());
    save(dateTime.minusDays(1).toString());
}

From source file:org.tanrabad.survey.service.EntomologyRestService.java

License:Apache License

private String oneWeekIntervalParam() {
    DateTime dateTime = new DateTime();
    return "startdate=" + unixTime(dateTime.minusDays(BuildConfig.SURVEY_RANGE_DAY));
}

From source file:org.terasoluna.tourreservation.domain.model.TourInfo.java

License:Apache License

public DateTime getPaymentLimit() {
    DateTime paymentLimit = new DateTime(this.getDepDay());
    return paymentLimit.minusDays(7);
}

From source file:org.vaadin.spring.samples.mvp.ui.component.selector.MarketDayPicker.java

License:Apache License

private void setOffsetDays(int startOffset, int endOffset) {
    setCaption(DEFAULT_CAPTION);// ww w .j a  v a 2s  .  co  m
    DateTime today = getValue() != null ? new DateTime(getValue().getTime()) : new DateTime();
    Date end = today.plusDays(startOffset).toDate();
    Date start = today.minusDays(endOffset).toDate();
    setValue(today.toDate());
    setDateFormat("yyyy-MM-dd");
    setRangeStart(start);
    setRangeEnd(end);
    setDateOutOfRangeMessage(OUT_OF_RANGE_MESSAGE);
}

From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java

License:Apache License

/**
 * Return the starting day accounting for Hour 00:00:00 being the day after.
 *
 * @param isoHour//from ww w  .  j a  va2s. c  o m
 *              an iso String
 * @return an iso String
 */
public static String isoHourEndingToIsoDay(String isoHour) {
    DateTime dt = isoToDateTime(isoHour);
    dt = dt.withZone(SSTimeUtil.getMarketTimeZone());
    if (dt.getHourOfDay() == 0) {
        dt = dt.minusDays(1);
    }
    return dateTimeToIsoDay(dt);
}

From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java

License:Apache License

/**
 * Return the starting day accounting for Hour 00:00:00 being the day after.
 * The date is coerced into the market time zone before computing the hour
 * When hour 00 is detected the day is decremented. The returned date has a
 * time of 00:00:00 in the market time zone.
 *
 * @param dt/*  www.  j  av a2s .co m*/
 *            an org.joda.time.DateTime
 * @return an org.joda.time.DateTime expressing an operating day
 */
public static DateTime getOperatingDay(DateTime dt) {
    dt = dt.withZone(SSTimeUtil.getMarketTimeZone());
    if (dt.getHourOfDay() == 0) {
        dt = dt.minusDays(1);
    }
    return dt.withMillisOfDay(0);
}

From source file:org.wannatrak.ShowServlet.java

License:Apache License

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final PositionWorkerLocal positionWorker = ServiceLocator.lookupLocal(PositionWorker.JNDI_NAME);
    final SessionWorker sessionWorker = ServiceLocator.lookupLocal(SessionWorker.JNDI_NAME);

    try {/*from  w w w.ja  v a  2s  .  co m*/
        final Long subjectId = Long.parseLong(request.getParameter("subjectId"));
        final String sessionId = request.getParameter("sessionId");
        final Integer hfrom = Integer.parseInt(request.getParameter("hfrom"));
        final Integer mfrom = Integer.parseInt(request.getParameter("mfrom"));
        Integer dfrom = Integer.parseInt(request.getParameter("dfrom"));
        final Integer hto = Integer.parseInt(request.getParameter("hto"));
        final Integer mto = Integer.parseInt(request.getParameter("mto"));
        Integer dto = Integer.parseInt(request.getParameter("dto"));
        final Boolean valid = Boolean.parseBoolean(request.getParameter("valid"));
        final String datetimeFormat = request.getParameter("format").replaceAll("_SPACE_", " ");
        Integer tzOffset = Integer.parseInt(request.getParameter("tzoffset"));
        if (tzOffset == null) {
            tzOffset = 0;
        }

        DateTime currentDateTime = new DateTime().withSecondOfMinute(0).withMillisOfSecond(0);
        final int minutesOfDayWithOffset = currentDateTime.getMinuteOfDay() - tzOffset;
        if (minutesOfDayWithOffset >= DateTimeConstants.MINUTES_PER_DAY) {
            currentDateTime = currentDateTime.plusDays(1);
        } else if (minutesOfDayWithOffset < 0) {
            currentDateTime = currentDateTime.minusDays(1);
        }

        final DateTime dateTimeFrom = currentDateTime.minusDays(dfrom).withHourOfDay(hfrom)
                .withMinuteOfHour(mfrom).plusMinutes(tzOffset);

        Logger.getLogger(getClass()).debug(subjectId);
        Logger.getLogger(getClass()).debug(dateTimeFrom.toString());

        final DateTime dateTimeTo = currentDateTime.minusDays(dto).withHourOfDay(hto).withMinuteOfHour(mto)
                .plusMinutes(tzOffset);

        Logger.getLogger(getClass()).debug(dateTimeTo.toString());

        final StringBuilder sb = new StringBuilder();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n" + "<Document>\n" + "<name>Path</name>\n"
                + "<Style id=\"style\">\n" + " <LineStyle>\n" + "  <color>ff0000ff</color>\n"
                + "  <width>1.5</width>\n" + " </LineStyle>\n" + " <PolyStyle>\n" + "  <fill>0</fill>\n"
                + " </PolyStyle>\n" + "</Style>\n" + "<open>1</open>\n" + "<Placemark>\n"
                + "<styleUrl>#style</styleUrl>\n" + "<LineString>\n" + "<extrude>0</extrude>\n"
                + "<altitudeMode>clampToGround</altitudeMode>\n" + "<coordinates>");

        final User user = sessionWorker.getUser(sessionId);
        final List<Position> positions;
        if (user == null) {
            positions = positionWorker.getDemoPositions(subjectId, dateTimeFrom, dateTimeTo, valid);
        } else {
            positions = positionWorker.getPositions(user, subjectId, dateTimeFrom, dateTimeTo, valid);
        }

        Position prevPosition = null;
        for (Iterator<Position> it = positions.iterator(); it.hasNext();) {
            final Position position = it.next();
            if (prevPosition != null && position.getLatitude().equals(prevPosition.getLatitude())
                    && position.getLongitude().equals(prevPosition.getLongitude())) {
                it.remove();
            } else {
                prevPosition = position;
            }
        }
        for (Position position : positions) {
            sb.append(position.getLongitude()).append(",").append(position.getLatitude()).append("\n");
        }
        sb.append("</coordinates>\n" + "</LineString>\n" + "</Placemark>\n");

        if (!positions.isEmpty()) {
            addFlag(sb, positions.get(0), tzOffset, datetimeFormat);
            int i = 1;
            for (; i < positions.size() - 1; i++) {
                if (i % 12 == 0) {
                    addFlag(sb, positions.get(i), tzOffset, datetimeFormat);
                }
            }
            if (positions.size() > 1) {
                addFlag(sb, positions.get(i), tzOffset, datetimeFormat);
            }
        }
        sb.append("</Document></kml>");
        final byte[] resultBytes = sb.toString().getBytes("utf-8");
        response.setContentLength(resultBytes.length);
        response.getOutputStream().write(resultBytes);
    } catch (NumberFormatException e) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:org.watterssoft.appsupport.landing.ui.LandingController.java

License:Apache License

@RequestMapping("/landingData")
public @ResponseBody LandingDTO loadLandingDTO(HttpServletRequest request) {
    DateTime dateTime = new DateTime();
    return landingService.getLandingPageForUser(request.getRemoteUser(), dateTime.minusDays(10).toDate());
}