Example usage for org.joda.time DateTime getHourOfDay

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

Introduction

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

Prototype

public int getHourOfDay() 

Source Link

Document

Get the hour of day field value.

Usage

From source file:org.fenixedu.academic.ui.struts.action.person.UploadPhotoDA.java

License:Open Source License

public ActionForward upload(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    PhotographUploadBean photo = getRenderedObject();
    RenderUtils.invalidateViewState();//w ww  . j a v a 2s  .  c o  m
    String base64Thumbnail = request.getParameter("encodedThumbnail");
    String base64Image = request.getParameter("encodedPicture");
    if (base64Image != null && base64Thumbnail != null) {
        DateTime now = new DateTime();
        photo.setFilename("mylovelypic_" + now.getYear() + now.getMonthOfYear() + now.getDayOfMonth()
                + now.getHourOfDay() + now.getMinuteOfDay() + now.getSecondOfMinute() + ".png");
        photo.setBase64RawContent(base64Image.split(",")[1]);
        photo.setBase64RawThumbnail(base64Thumbnail.split(",")[1]);
        photo.setContentType(base64Image.split(",")[0].split(":")[1].split(";")[0]);
    }

    ActionMessages actionMessages = new ActionMessages();
    try (InputStream stream = photo.getFileInputStream()) {
        if (stream == null) {
            actionMessages.add("fileRequired", new ActionMessage("errors.fileRequired"));
            saveMessages(request, actionMessages);
            return prepare(mapping, actionForm, request, response);
        }
    }

    if (ContentType.getContentType(photo.getContentType()) == null) {
        actionMessages.add("fileUnsupported", new ActionMessage("errors.unsupportedFile"));
        saveMessages(request, actionMessages);
        return prepare(mapping, actionForm, request, response);
    }

    if (photo.getRawSize() > MAX_RAW_SIZE) {
        actionMessages.add("fileTooLarge", new ActionMessage("errors.fileTooLarge"));
        saveMessages(request, actionMessages);
        photo.deleteTemporaryFiles();
        return prepare(mapping, actionForm, request, response);
    }

    try {
        photo.processImage();
    } catch (UnableToProcessTheImage e) {
        actionMessages.add("unableToProcessImage", new ActionMessage("errors.unableToProcessImage"));
        saveMessages(request, actionMessages);
        photo.deleteTemporaryFiles();
        return prepare(mapping, actionForm, request, response);
    }
    photo.createTemporaryFiles();

    request.setAttribute("preview", true);
    request.setAttribute("photo", photo);
    return mapping.findForward("confirm");
}

From source file:org.fenixedu.learning.servlets.FenixEduLearningContextListener.java

License:Open Source License

private static int hasTime(DateTime proposedDiscussed) {
    if (proposedDiscussed.getHourOfDay() == 0 && proposedDiscussed.getMinuteOfHour() == 0) {
        return 0;
    } else {/*from w  w  w  . j  a  v a 2 s.c  om*/
        return 1;
    }
}

From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java

License:Open Source License

private XMLGregorianCalendar convertToXMLDateTime(DatatypeFactory dataTypeFactory, DateTime documentDate) {
    return dataTypeFactory.newXMLGregorianCalendar(documentDate.getYear(), documentDate.getMonthOfYear(),
            documentDate.getDayOfMonth(), documentDate.getHourOfDay(), documentDate.getMinuteOfHour(),
            documentDate.getSecondOfMinute(), 0, DatatypeConstants.FIELD_UNDEFINED);
}

From source file:org.forgerock.openidm.util.DateUtil.java

License:CDDL license

/**
 * Returns a {@link String} representing a scheduler expression of the supplied date. The scheduler expression is of
 * the form: "{second} {minute} {hour} {day} {month} ? {year}".  
 *
 * For example, a scheduler expression for January 3, 2016 at 04:56 AM would be: "0 56 4 3 1 ? 2016". 
 * // ww w  .  j  a  va  2  s  .com
 * @param intervalString a {@link String} object representing an ISO 8601 time interval.
 * @return a {@link String} representing a scheduler expression of the supplied date.
 * @throws IllegalArgumentException if an error occurs while parsing the intervalString.
 */
public String getSchedulerExpression(DateTime date) throws IllegalArgumentException {
    StringBuilder sb = new StringBuilder().append(date.getSecondOfMinute()).append(" ")
            .append(date.getMinuteOfHour()).append(" ").append(date.getHourOfDay()).append(" ")
            .append(date.getDayOfMonth()).append(" ").append(date.getMonthOfYear()).append(" ").append("? ")
            .append(date.getYear());
    return sb.toString();
}

From source file:org.gravidence.gravifon.util.DateTimeUtils.java

License:Open Source License

/**
 * Converts datetime object to array of UTC datetime fields.<p>
 * Given datetime object is casted to UTC.<p>
 * Resulting array content is as follows: <code>[yyyy,MM,dd,HH,mm,ss,SSS]</code>.
 * // ww w  . j a v  a  2  s . c  om
 * @param value datetime object
 * @return array of UTC datetime fields
 */
public static int[] dateTimeToArray(DateTime value) {
    int[] result;

    if (value == null) {
        result = null;
    } else {
        result = new int[7];

        DateTime valueUTC = value.toDateTime(DateTimeZone.UTC);

        result[0] = valueUTC.getYear();
        result[1] = valueUTC.getMonthOfYear();
        result[2] = valueUTC.getDayOfMonth();
        result[3] = valueUTC.getHourOfDay();
        result[4] = valueUTC.getMinuteOfHour();
        result[5] = valueUTC.getSecondOfMinute();
        result[6] = valueUTC.getMillisOfSecond();
    }

    return result;
}

From source file:org.graylog2.inputs.random.generators.FakeHttpRawMessageGenerator.java

License:Open Source License

private static Map<String, Object> ingestTimeFields(DateTime ingestTime) {
    return ImmutableMap.<String, Object>builder().put("ingest_time", ingestTime.toString())
            .put("ingest_time_epoch", ingestTime.getMillis())
            .put("ingest_time_second", ingestTime.getSecondOfMinute())
            .put("ingest_time_minute", ingestTime.getMinuteOfHour())
            .put("ingest_time_hour", ingestTime.getHourOfDay())
            .put("ingest_time_day", ingestTime.getDayOfMonth())
            .put("ingest_time_month", ingestTime.getMonthOfYear()).put("ingest_time_year", ingestTime.getYear())
            .build();/*w w w.  ja v a 2s .co  m*/
}

From source file:org.hawkular.metrics.core.impl.DateTimeService.java

License:Apache License

public DateTime getTimeSlice(DateTime dt, Duration duration) {
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }// w w  w  .  j av a2  s .c  o m
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.hawkular.metrics.datetime.DateTimeService.java

License:Apache License

public static DateTime getTimeSlice(DateTime dt, Duration duration) {
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }/*from  w w  w. j  a  v a2  s . c o m*/
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.hawkular.metrics.tasks.api.AbstractTrigger.java

License:Apache License

protected DateTime getExecutionTime(long time, Duration duration) {
    DateTime dt = new DateTime(time);
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }/*from  w  ww  . ja  v  a 2  s .c om*/
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.hortonmachine.gvsig.epanet.core.ChartHelper.java

License:Open Source License

/**
 * Constructor./*from w  ww .ja  v  a  2s .  c  o m*/
 * 
 * @param valuesMapList the list of ordered maps containing x,y pairs.
 * @param title the title of the chart.
 * @param xLabel the x label.
 * @param yLabel the y label.
 */
@SuppressWarnings("deprecation")
public static void chart(List<LinkedHashMap<DateTime, float[]>> valuesMapList, String title, String xLabel,
        String yLabel) {

    List<TimeSeries> seriesList = new ArrayList<TimeSeries>();
    for (LinkedHashMap<DateTime, float[]> valuesMap : valuesMapList) {
        TimeSeries[] series = new TimeSeries[0];
        Set<Entry<DateTime, float[]>> entrySet = valuesMap.entrySet();
        for (Entry<DateTime, float[]> entry : entrySet) {
            DateTime date = entry.getKey();
            float[] values = entry.getValue();

            if (series.length == 0) {
                series = new TimeSeries[values.length];
                for (int i = 0; i < values.length; i++) {
                    series[i] = new TimeSeries(i + 1);
                }
            }

            for (int i = 0; i < values.length; i++) {
                int sec = date.getSecondOfMinute();
                int min = date.getMinuteOfHour();
                int hour = date.getHourOfDay();
                int day = date.getDayOfMonth();
                int month = date.getMonthOfYear();
                int year = date.getYear();
                series[i].add(new Second(sec, min, hour, day, month, year), values[i]);
            }
        }
        for (TimeSeries timeSeries : series) {
            seriesList.add(timeSeries);
        }
    }

    TimeSeriesCollection lineDataset = new TimeSeriesCollection();
    for (TimeSeries timeSeries : seriesList) {
        lineDataset.addSeries(timeSeries);
    }

    lineDataset.setXPosition(TimePeriodAnchor.MIDDLE);
    lineDataset.setDomainIsPointsInTime(true);

    JFreeChart theChart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, lineDataset,
            seriesList.size() > 1, true, true);
    XYPlot thePlot = theChart.getXYPlot();

    ((XYPlot) thePlot).setRenderer(new XYLineAndShapeRenderer());
    XYItemRenderer renderer = ((XYPlot) thePlot).getRenderer();

    DateAxis axis = (DateAxis) ((XYPlot) thePlot).getDomainAxis();
    axis.setDateFormatOverride(dateFormatter);
    // axis.setAutoRangeMinimumSize(5.0);

    ValueAxis rangeAxis = ((XYPlot) thePlot).getRangeAxis();
    rangeAxis.setAutoRangeMinimumSize(5.0);

    for (int i = 0; i < seriesList.size(); i++) {
        ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(i, true);
        ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(i, true);
    }

    ChartPanel chartPanel = new ChartPanel(theChart, false);
    chartPanel.setPreferredSize(new Dimension(600, 500));
    chartPanel.setHorizontalAxisTrace(false);
    chartPanel.setVerticalAxisTrace(false);

    WindowManager windowManager = ToolsSwingLocator.getWindowManager();
    windowManager.showWindow(chartPanel, title, MODE.WINDOW);
}