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.collective.celos.ScheduledTime.java

License:Apache License

public static ScheduledTime now() {
    return new ScheduledTime(DateTime.now(DateTimeZone.UTC));
}

From source file:com.collective.celos.servlet.AbstractServlet.java

License:Apache License

protected ScheduledTime getRequestTime(HttpServletRequest req) {
    String t = req.getParameter(CelosClient.TIME_PARAM);
    if (t == null) {
        return new ScheduledTime(DateTime.now(DateTimeZone.UTC));
    } else {/*www  .j a va  2s  . c  o  m*/
        return new ScheduledTime(t);
    }
}

From source file:com.collective.celos.servlet.JSONWorkflowSlotsServlet.java

License:Apache License

protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException {
    String id = req.getParameter(CelosClient.ID_PARAM);
    try {//w w  w  .  j  a v a 2  s.  c o  m
        if (id == null) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST, CelosClient.ID_PARAM + " parameter missing.");
            return;
        }
        Scheduler scheduler = getOrCreateCachedScheduler();
        Workflow wf = scheduler.getWorkflowConfiguration().findWorkflow(new WorkflowID(id));
        if (wf == null) {
            res.sendError(HttpServletResponse.SC_NOT_FOUND, "Workflow not found: " + id);
            return;
        }

        ScheduledTime endTime = getTimeParam(req, CelosClient.END_TIME_PARAM,
                new ScheduledTime(DateTime.now(DateTimeZone.UTC)));
        ScheduledTime startTime = getTimeParam(req, CelosClient.START_TIME_PARAM,
                scheduler.getWorkflowStartTime(wf, endTime));

        if (startTime.plusHours(scheduler.getSlidingWindowHours()).getDateTime()
                .isBefore(endTime.getDateTime())) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    "Time interval between start and end is limited to: " + scheduler.getSlidingWindowHours()
                            + " hours");
            return;
        }
        try (StateDatabaseConnection connection = getStateDatabase().openConnection()) {
            List<SlotState> slotStates = scheduler.getSlotStates(wf, startTime, endTime, connection);
            List<JsonNode> objectNodes = Lists.newArrayList();
            for (SlotState state : Lists.reverse(slotStates)) {
                objectNodes.add(state.toJSONNode());
            }

            ObjectNode node = Util.MAPPER.createObjectNode();
            node.put(CelosClient.INFO_NODE, (JsonNode) Util.MAPPER.valueToTree(wf.getWorkflowInfo()));
            node.put(CelosClient.PAUSE_NODE, connection.isPaused(wf.getID()));
            node.putArray(CelosClient.SLOTS_NODE).addAll(objectNodes);
            writer.writeValue(res.getOutputStream(), node);
        }
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.collective.celos.Util.java

License:Apache License

public static ScheduledTime fromTimestamp(Timestamp timestamp) {
    return new ScheduledTime(new DateTime(timestamp.getTime()).withZone(DateTimeZone.UTC));
}

From source file:com.common.mybatis.typehandler.DateTimeTypeHandler.java

License:Apache License

public Object getResult(ResultSet rs, String columnName) throws SQLException {
    Timestamp ts = rs.getTimestamp(columnName);
    if (ts != null) {
        return new DateTime(ts.getTime(), DateTimeZone.UTC);
    } else {//w  ww. ja  va 2s .  c om
        return null;
    }
}

From source file:com.common.mybatis.typehandler.DateTimeTypeHandler.java

License:Apache License

public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
    Timestamp ts = cs.getTimestamp(columnIndex);
    if (ts != null) {
        return new DateTime(ts.getTime(), DateTimeZone.UTC);
    } else {/*  w ww .j av a  2  s.c om*/
        return null;
    }
}

From source file:com.common.mybatis.typehandler.DateTimeTypeHandler.java

License:Apache License

public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
    Timestamp ts = rs.getTimestamp(columnIndex);
    if (ts != null) {
        return new DateTime(ts.getTime(), DateTimeZone.UTC);
    } else {//from ww w.j ava2 s .c o m
        return null;
    }
}

From source file:com.confighub.core.utils.DateTimeUtils.java

License:Open Source License

public static Date parseISO8601Date(String dateString, Date cutoff) throws ConfigException {
    if (Utils.isBlank(dateString))
        return null;

    try {//from www . j a  va 2s. co  m
        DateTimeFormatter parser = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ");
        DateTime dt = parser.parseDateTime(dateString);
        dt = dt.toDateTime(DateTimeZone.UTC);
        Date date = dt.toDate();

        if (null != cutoff && date.before(cutoff))
            return cutoff;

        return date;
    } catch (Exception e) {
        throw new ConfigException(Error.Code.DATE_API_FORMAT_ERROR);
    }
}

From source file:com.culvereq.vimp.util.Deserializer.java

public ServiceRecord deserializeService(JSONObject jsonObject, String sourceJSON) throws JSONException {
    JSONObject serviceTypeJSON = jsonObject.getJSONObject("type");
    int id = jsonObject.getInt("id");
    ServiceType type = deserializeServiceType(serviceTypeJSON);
    String description = jsonObject.getString("description");
    String timestampStr = jsonObject.getString("timestamp");
    String dateStr = jsonObject.getString("service-date");
    long timestamp = Long.parseLong(timestampStr) * 1000L;
    long date = Long.parseLong(dateStr) * 1000L;
    int mileage = jsonObject.getInt("mileage");
    return new ServiceRecord(id, type, description, new DateTime(date, DateTimeZone.UTC),
            new DateTime(timestamp, DateTimeZone.UTC), mileage, sourceJSON);
}

From source file:com.cyngn.mods.opentsdb.MetricsParser.java

License:Apache License

public String createMetricString(Message<JsonObject> message) {
    JsonObject body = message.body();//from w  w  w  .  j a  va 2 s .c  o m

    String metricName = body.getString(NAME_FIELD, "");
    if (metricName.length() == 0) {
        errorHandler.accept(message, "All metrics need a 'name' field");
        return null;
    }

    String metricValue = body.getString(VALUE_FIELD, "");
    if (metricValue.length() == 0) {
        errorHandler.accept(message, "All metrics need a 'value' field");
        return null;
    }

    String tags = defaultTags;
    if (body.containsField(TAGS_FIELD)) {
        String padding = tags.equals("") ? "" : " ";
        tags += padding + Util.createTagsFromJson(body.getObject(TAGS_FIELD));
    }

    // this is an OpenTsDB requirement
    if ("".equals(tags.trim())) {
        errorHandler.accept(message, "You must specify at least one tag");
        return null;
    }

    String metric = (hasPrefix)
            ? String.format("put %s.%s %d %s %s\n", prefix, metricName,
                    DateTime.now(DateTimeZone.UTC).toDate().getTime(), metricValue, tags)
            : String.format("put %s %d %s %s\n", metricName, DateTime.now(DateTimeZone.UTC).toDate().getTime(),
                    metricValue, tags);

    return metric;
}