Example usage for org.joda.time DateTime getMinuteOfDay

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

Introduction

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

Prototype

public int getMinuteOfDay() 

Source Link

Document

Get the minute of day field value.

Usage

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 {/*w w w.  j  av a2  s.c o 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.xmlcml.euclid.JodaDate.java

License:Apache License

@SuppressWarnings("deprecation")
public static Date parseJodaDate(DateTime jodaDate) {
    int year = jodaDate.getYear();
    int month = jodaDate.getMonthOfYear();
    int day = jodaDate.getDayOfMonth();
    int hour = jodaDate.getHourOfDay();
    int min = jodaDate.getMinuteOfDay();
    int sec = jodaDate.getSecondOfMinute();
    // arghh/* ww  w.  j a va  2s .c  o  m*/
    Date date = new Date(year - 1900, month, day, hour, min, sec);
    return date;
}