Example usage for org.joda.time DateTime now

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

Introduction

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

Prototype

public static DateTime now(Chronology chronology) 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using the specified chronology.

Usage

From source file:com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition.java

License:Open Source License

public DateTime getDateTimeForCurrentYear() {
    return this.getDateTimeForYear(DateTime.now(this.dateTimeZone).getYear());
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition.java

License:Open Source License

public DateTime getDateTimeForNextTransition() {
    final DateTime now = DateTime.now(this.dateTimeZone);
    final DateTime thisYearsTransition = this.getDateTimeForYear(now.getYear());
    if (now.isAfter(thisYearsTransition)) {
        return this.getDateTimeForYear(now.getYear() + 1);
    }// w  w w . jav a  2 s.  co m
    return thisYearsTransition;
}

From source file:com.altoukhov.svsync.engines.Analyzer.java

License:Apache License

private static Snapshot loadFromCacheOrScan(Map<String, String> infoParams, String snapshotFilePath,
        IScannableFileSpace fileSpace, Collection<String> filters) {
    boolean isCacheEnabled = infoParams.containsKey("cache-days");
    boolean shouldScan = true;

    Snapshot snap = Snapshot.fromFile(snapshotFilePath);

    if (snap != null) {
        if (isCacheEnabled) {
            DateTime cacheExpiration = snap.getTimestamp()
                    .plusDays(Integer.parseInt(infoParams.get("cache-days")));
            shouldScan = cacheExpiration.isBefore(DateTime.now(DateTimeZone.UTC));
        }/* www .ja v  a 2 s  .  com*/
    }

    if (shouldScan) {
        snap = fileSpace.scan(filters);
        if ((snap != null) && isCacheEnabled) {
            snap.toFile(snapshotFilePath);
        }
    }

    return snap;
}

From source file:com.altoukhov.svsync.Snapshot.java

License:Apache License

public Snapshot(Map<String, FileSnapshot> files, Set<String> dirs) {
    this.files = files;
    this.directories = dirs;
    this.timestamp = DateTime.now(DateTimeZone.UTC);
}

From source file:com.appdynamics.extensions.cloudwatch.metricsmanager.MetricsManager.java

License:Apache License

/**
 * Create a GetMetricStatisticsRequest for a particular namespace
 * @param namespace             Name of the Namespace
 * @param metricName            Name of the Metric
 * @param statisticsType        Type of Statistics (i.e. Average, Sum)
 * @param dimensions            List of dimensions used to filter metrics
 * @return GetMetricStatisticsRequest/*from  ww w .  j a  v a2  s .  c  o  m*/
 */
protected GetMetricStatisticsRequest createGetMetricStatisticsRequest(String namespace, String metricName,
        String statisticsType, List<Dimension> dimensions) {
    GetMetricStatisticsRequest getMetricStatisticsRequest = new GetMetricStatisticsRequest()
            .withStartTime(DateTime.now(DateTimeZone.UTC).minusMinutes(10).toDate()).withNamespace(namespace)
            .withDimensions(dimensions).withPeriod(60).withMetricName(metricName).withStatistics(statisticsType)
            .withEndTime(DateTime.now(DateTimeZone.UTC).minusMinutes(5).toDate());
    return getMetricStatisticsRequest;
}

From source file:com.auditbucket.engine.repo.neo4j.model.TxRefNode.java

License:Open Source License

private TxStatus setStatus(TxStatus txStatus) {
    TxStatus previous = this.txStatus;
    this.txStatus = txStatus;
    this.txDate = DateTime.now(DateTimeZone.UTC).getMillis();
    return previous;
}

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 {/*from w w  w. j a v  a2s. co 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 {/*from   w ww  .  j a  v a 2 s  . c  om*/
        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.cyngn.mods.opentsdb.MetricsParser.java

License:Apache License

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

    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;
}