Example usage for org.joda.time DateTimeZone UTC

List of usage examples for org.joda.time DateTimeZone UTC

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone UTC.

Prototype

DateTimeZone UTC

To view the source code for org.joda.time DateTimeZone UTC.

Click Source Link

Document

The time zone for Universal Coordinated Time

Usage

From source file:com.boxedfolder.carrot.domain.util.DateTimeSerializer.java

License:Open Source License

@Override
public void serialize(DateTime value, JsonGenerator generator, SerializerProvider serializerProvider)
        throws IOException {
    generator.writeString(formatter.print(value.toDateTime(DateTimeZone.UTC)));
}

From source file:com.btoddb.flume.sinks.cassandra.CassandraSinkRepository.java

License:Apache License

private String createTimeStampAsString(long ts) {
    return DF_ISO.print(new DateTime(ts).withZone(DateTimeZone.UTC));
}

From source file:com.cfelde.aws.ddb.management.TableThroughput.java

License:Open Source License

public boolean isDownscaleAllowed() {
    // We allow 4 downscales within 24 hours:

    // Between 00:00 and 06:00 - 3 left after
    // Between 06:00 and 12:00 - 2 left after
    // Between 12:00 and 18:00 - 1 left after
    // Between 18:00 and 00:00 - 0 left after

    // First, based on current UTC time, find the number of
    // downscales we at most can use.
    DateTime dtNow = new DateTime(DateTimeZone.UTC);

    int hourNow = dtNow.getHourOfDay();
    long maxDownscales;
    if (hourNow >= 18)
        maxDownscales = 4;//from w  w  w .  ja  va 2s. c  o m
    else if (hourNow >= 12)
        maxDownscales = 3;
    else if (hourNow >= 6)
        maxDownscales = 2;
    else
        maxDownscales = 1;

    long usedDownscaled = downscaleCounter.get();

    return usedDownscaled < maxDownscales;
}

From source file:com.cfitzarl.cfjwed.data.model.AbstractIdBase.java

License:Open Source License

@PrePersist
public void handleLastUpdated() {
    if (id == null) {
        id = UUID.randomUUID();
    }
    lastUpdated = new DateTime(DateTimeZone.UTC);
}

From source file:com.cisco.devnetlabs.choochoo.impl.ChoochooMqttPlugin.java

License:Open Source License

private void handleMqttMessage(String topic, String message) {

    //LOG.info("handleMqttMessage: topic: {}, message: {}", topic, message);
    JSONObject jSensor = null;/*from  ww  w  .  j  a  va 2 s  .  c o m*/
    try {
        jSensor = new JSONObject(message);
    } catch (JSONException e) {
        LOG.error("{}", e.toString());
        return;
    }

    String sensorBlockId = jSensor.optString("block", null);
    if (sensorBlockId == null) {
        LOG.error("processSensor: missing block in Json String: {}", jSensor.toString());
        return;
    }
    String blockPosition = jSensor.optString("pos", null);
    if (blockPosition == null) {
        LOG.error("processSensor: missing pos in Json String: {}", jSensor.toString());
        return;
    } else if (blockPosition.contentEquals("0")) {
        savePosId = 0;
        return;
    }

    DateTime currTime = new DateTime(DateTimeZone.UTC);
    long diff = Seconds.secondsBetween(saveTime, currTime).getSeconds() % 60;
    if (diff < 2)
        return; // only sample sensor values at most every 2 seconds
    saveTime = currTime;

    // if nothing has changed, return as we have alredy handled entering this state
    if (saveBlockId == Integer.valueOf(sensorBlockId) && savePosId == Integer.valueOf(blockPosition)) {
        return;
    }

    saveBlockId = Integer.valueOf(sensorBlockId);
    savePosId = Integer.valueOf(blockPosition);

    Integer sensorId = (Integer.valueOf(sensorBlockId) - 1) * 3 + Integer.valueOf(blockPosition);

    onem2mManager.processSensor(topic, sensorId);
}

From source file:com.claresco.tinman.sql.XapiStatementSQLReader.java

License:Open Source License

/**
 * /*from w  w  w. ja va  2s. c  o m*/
 * Definition:
 *   Helper method that will create a hashmap from result
 *
 * Params:
 *
 *
 */
private HashMap<Integer, XapiStatement> getStatementFromResult() throws SQLException {
    HashMap<Integer, XapiStatement> statementArray = new HashMap<Integer, XapiStatement>();

    while (myResult.next()) {
        UUID theId = UUID.fromString(myResult.getString("statementuuid"));
        XapiActor theActor = myActorReader.retrieveByID(myResult.getInt("actorid"));
        XapiVerb theVerb = myVerbReader.retrieveByID(myResult.getInt("verbid"));
        XapiObject theObject = myObjectReader.retrieveByID(myResult.getInt("objectid"));
        XapiResult theResult = null;
        int theResultID = myResult.getInt("resultid");
        if (!myResult.wasNull()) {
            theResult = myResultReader.retrieveByID(theResultID);
        }

        XapiContext theContext = null;
        int theContextID = myResult.getInt("contextid");
        if (!myResult.wasNull()) {
            theContext = myContextReader.retrieveByID(theContextID);
        }

        String theTSString = null;

        Timestamp theTS = myResult.getTimestamp("sttime");
        if (!myResult.wasNull()) {
            DateTime theTimestamp = SQLUtility.getDatetime(theTS);
            theTSString = theTimestamp.withZoneRetainFields(DateTimeZone.UTC).toString();
        }

        // Voided statement should not be returned
        int isVoided = myResult.getInt("isVoided");
        if (isVoided == 0) {
            statementArray.put(myResult.getInt("statementid"),
                    new XapiStatement(theId, theActor, theVerb, theObject, theResult, theContext, theTSString));
        }
    }

    return statementArray;
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Null-safe method of converting a SQL Timestamp into a DateTime that
 * it set specifically to be in UTC.// www .  ja  v  a2  s.c  om
 * <br>
 * NOTE: The timestamp also should be in UTC.
 * @return A UTC DateTime
 */
public static DateTime toDateTime(Timestamp value) {
    if (value == null) {
        return null;
    } else {
        return new DateTime(value.getTime(), DateTimeZone.UTC);
    }
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Null-safe method of copying a DateTime
 * <br>//from w  w w.  j  a va2s.c o  m
 * NOTE: The timestamp also should be in UTC.
 * @return A UTC DateTime
 */
public static DateTime copy(DateTime value) {
    if (value == null) {
        return null;
    } else {
        return new DateTime(value.getMillis(), DateTimeZone.UTC);
    }
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Get the current time as a DateTime./*from   w ww . j  av  a 2  s.c om*/
 * 
 * @return A UTC DateTime
 */
public static DateTime now() {
    return new DateTime(DateTimeZone.UTC);
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Parses a string for an embedded date and/or time contained within a
 * string such as "app.2008-05-01.log". This method expects the string
 * to contain a pattern of "yyyy-MM-dd".  All dates will be interpreted to
 * be in the UTC timezone.//ww  w .  ja  va 2  s  .c o  m
 * @param string0 The string to parse
 * @return The parsed DateTime value
 * @throws IllegalArgumentException Thrown if the string did not contain
 *      an embedded date.
 */
public static DateTime parseEmbedded(String string0) throws IllegalArgumentException {
    return parseEmbedded(string0, "yyyy-MM-dd", DateTimeZone.UTC);
}