Example usage for org.joda.time DateTime getSecondOfMinute

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

Introduction

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

Prototype

public int getSecondOfMinute() 

Source Link

Document

Get the second of minute field value.

Usage

From source file:org.efaps.admin.datamodel.attributetype.DateTimeType.java

License:Apache License

/**
 * The value that can be set is a Date, a DateTime or a String
 * yyyy-MM-dd'T'HH:mm:ss.SSSZZ. It will be normalized to ISO Calender with
 * TimeZone from SystemAttribute Admin_Common_DataBaseTimeZone. In case that
 * the SystemAttribute is missing UTC will be used.
 *
 * @param _value value to evaluate//  w  ww  .  java  2  s .  com
 * @return evaluated value
 * @throws EFapsException on error
 */
protected Timestamp eval(final Object[] _value) throws EFapsException {
    final Timestamp ret;
    if (_value == null || _value.length == 0 || _value[0] == null) {
        ret = null;
    } else {
        final DateTime dateTime = DateTimeUtil.translateFromUI(_value[0]);
        // until now we have a time that depends on the timezone of the application server
        // to convert it in a timestamp for the efaps database the timezone information (mainly the offset)
        // must be removed. This is done by creating a local date with the same, date and time.
        // this guarantees that the datetime inserted into the database depends on the setting
        // in the configuration and not on the timezone for the application server.
        final DateTime localized = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(),
                dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour(),
                dateTime.getSecondOfMinute(), dateTime.getMillisOfSecond());
        ret = localized != null ? new Timestamp(localized.getMillis()) : null;
    }
    return ret;
}

From source file:org.everit.jira.timetracker.plugin.util.DateTimeConverterUtil.java

License:Apache License

/**
 * Convert joda DateTime to java Date. Convert the date and time without Time Zone correction.
 * (the joda DateTime toDate metod add the time zone).
 *
 * @param dateTime/*from   w w  w  . jav a2s.c om*/
 *          The dateTime.
 * @return The new date.
 */
@SuppressWarnings("deprecation")
public static Date convertDateTimeToDate(final DateTime dateTime) {
    return new Date(dateTime.getYear() - YEAR_1900, dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth(),
            dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute());
}

From source file:org.fenixedu.academic.ui.struts.action.operator.SubmitPhotoAction.java

License:Open Source License

public ActionForward photoUpload(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    PhotographUploadBean photo = getRenderedObject();
    RenderUtils.invalidateViewState();/*from   w ww  . ja  va2  s. 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("error", new ActionMessage("errors.fileRequired"));
            saveMessages(request, actionMessages);
            return preparePhotoUpload(mapping, actionForm, request, response);
        }
    }

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

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

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

    try {
        updatePersonPhoto(photo);
    } catch (Exception e) {
        actionMessages.add("error", new ActionMessage("errors.unableToSaveImage"));
        saveMessages(request, actionMessages);
        photo.deleteTemporaryFiles();
        return preparePhotoUpload(mapping, actionForm, request, response);
    }

    actionMessages.add("success", new ActionMessage("label.operator.submit.ok", ""));
    saveMessages(request, actionMessages);
    return preparePhotoUpload(mapping, actionForm, request, response);
}

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();//from   w  w w.ja  v a2 s  . co  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.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". 
 * /*w ww  . j a v a  2  s.  c  om*/
 * @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>.
 * /*from   www .  j  av a 2s. 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.database.MongoBridge.java

License:Open Source License

public void writeMessageCounts(int total, Map<String, Integer> streams, Map<String, Integer> hosts) {
    // We store the first second of the current minute, to allow syncing (summing) message counts
    // from different graylog-server nodes later
    DateTime dt = new DateTime();
    int startOfMinute = Tools.getUTCTimestamp() - dt.getSecondOfMinute();
    ;/*from  w  w  w .j  a v  a 2s  . c  om*/

    BasicDBObject obj = new BasicDBObject();
    obj.put("timestamp", startOfMinute);
    obj.put("total", total);
    obj.put("streams", streams);
    obj.put("hosts", hosts);
    obj.put("server_id", server.getServerId());

    getConnection().getMessageCountsColl().insert(obj);
}

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();//from  w  w  w. jav a  2  s .c o  m
}

From source file:org.graylog2.periodical.TrafficCounterCalculator.java

License:Open Source License

@Override
public void doRun() {
    final DateTime now = Tools.nowUTC();
    final int secondOfMinute = now.getSecondOfMinute();
    // on the top of every minute, we flush the current throughput
    if (secondOfMinute == 0) {
        LOG.trace("Calculating input and output traffic for the previous minute");

        final long currentInputBytes = inputCounter.getCount();
        final long currentOutputBytes = outputCounter.getCount();
        final long currentDecodedBytes = decodedCounter.getCount();

        final long inputLastMinute = currentInputBytes - previousInputBytes;
        previousInputBytes = currentInputBytes;
        final long outputBytesLastMinute = currentOutputBytes - previousOutputBytes;
        previousOutputBytes = currentOutputBytes;
        final long decodedBytesLastMinute = currentDecodedBytes - previousDecodedBytes;
        previousDecodedBytes = currentDecodedBytes;

        if (LOG.isDebugEnabled()) {
            final Size in = Size.bytes(inputLastMinute);
            final Size out = Size.bytes(outputBytesLastMinute);
            final Size decoded = Size.bytes(decodedBytesLastMinute);
            LOG.debug(//from   w w  w .  ja v a2  s  . c o  m
                    "Traffic in the last minute: in: {} bytes ({} MB), out: {} bytes ({} MB}), decoded: {} bytes ({} MB})",
                    in, in.toMegabytes(), out, out.toMegabytes(), decoded, decoded.toMegabytes());
        }
        final DateTime previousMinute = now.minusMinutes(1);
        trafficService.updateTraffic(previousMinute, nodeId, inputLastMinute, outputBytesLastMinute,
                decodedBytesLastMinute);
    }
}