Example usage for org.joda.time.format DateTimeFormatter print

List of usage examples for org.joda.time.format DateTimeFormatter print

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter print.

Prototype

public String print(ReadablePartial partial) 

Source Link

Document

Prints a ReadablePartial to a new String.

Usage

From source file:org.elasticsearch.util.json.JsonBuilder.java

License:Apache License

public T value(ReadableInstant date, DateTimeFormatter dateTimeFormatter) throws IOException {
    return value(dateTimeFormatter.print(date));
}

From source file:org.elasticsearch.util.json.JsonBuilder.java

License:Apache License

public T value(Date date, DateTimeFormatter dateTimeFormatter) throws IOException {
    return value(dateTimeFormatter.print(date.getTime()));
}

From source file:org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils.java

License:Open Source License

/**
 * Get the index name given a specific date format, a monitored system and a timestamp.
 *
 * @param formatter the {@link DateTimeFormatter} to use to compute the timestamped index name
 * @param system the {@link MonitoredSystem} for which the index name is computed
 * @param timestamp the timestamp value to use to compute the timestamped index name
 * @return the index name as a @{link String}
 *///from  w w w  .ja v a  2  s . co m
public static String indexName(final DateTimeFormatter formatter, final MonitoredSystem system,
        final long timestamp) {
    return ".monitoring-" + system.getSystem() + "-" + TEMPLATE_VERSION + "-" + formatter.print(timestamp);
}

From source file:org.elasticsearch.xpack.monitoring.cleaner.AbstractIndicesCleanerTestCase.java

License:Open Source License

/**
 * Creates a watcher history index from the specified version.
 *///from w w  w.  j a  v a 2 s . co m
protected void createWatcherHistoryIndex(final DateTime creationDate, final String version) {
    final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC();
    final String index = ".watcher-history-" + version + "-" + formatter.print(creationDate.getMillis());

    createIndex(index, creationDate);
}

From source file:org.elasticsearch.xpack.monitoring.cleaner.AbstractIndicesCleanerTestCase.java

License:Open Source License

/**
 * Creates a monitoring timestamped index using a given template version.
 *///from  w w w  .  jav a2 s  .c o m
protected void createTimestampedIndex(DateTime creationDate, String version) {
    final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC();
    final String index = ".monitoring-es-" + version + "-" + formatter.print(creationDate.getMillis());
    createIndex(index, creationDate);
}

From source file:org.emonocot.model.registry.Resource.java

License:Open Source License

@Override
public SolrInputDocument toSolrInputDocument() {
    DateTimeFormatter solrDateTimeFormat = DateTimeFormat.forPattern("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");
    SolrInputDocument sid = new SolrInputDocument();
    sid.addField("id", getClassName() + "_" + getId());
    sid.addField("base.id_l", getId());
    sid.addField("base.class_searchable_b", false);
    sid.addField("base.class_s", getClass().getName());

    if (getDuration() != null) {
        sid.addField("resource.duration_l", getDuration().getStandardSeconds());
    }/*from w w w  .  j  a  v  a  2s. c  o  m*/
    sid.addField("resource.exit_code_s", getExitCode());
    sid.addField("resource.exit_description_t", getExitDescription());
    if (getLastHarvested() != null) {
        sid.addField("resource.last_harvested_dt", solrDateTimeFormat.print(getLastHarvested()));
    }
    if (getNextAvailableDate() != null) {
        sid.addField("resource.next_available_date_dt", solrDateTimeFormat.print(getNextAvailableDate()));
    }
    sid.addField("resource.process_skip_l", getProcessSkip());
    sid.addField("resource.records_read_l", getRecordsRead());
    sid.addField("resource.resource_type_s", getResourceType());
    sid.addField("resource.scheduled_b", getScheduled());
    sid.addField("resource.scheduling_period_s", getSchedulingPeriod());
    if (getOrganisation() != null) {
        sid.addField("resource.organisation_s", getOrganisation().getIdentifier());
    }
    if (getStartTime() != null) {
        sid.addField("resource.start_time_dt", solrDateTimeFormat.print(getStartTime()));
    }
    sid.addField("resource.status_s", getStatus());
    sid.addField("resource.title_t", getTitle());
    sid.addField("resource.write_skip_l", getWriteSkip());
    sid.addField("resource.written_l", getWritten());
    sid.addField("searchable.label_sort", getTitle());
    StringBuilder summary = new StringBuilder().append(getExitDescription()).append(" ").append(getTitle());
    sid.addField("searchable.solrsummary_t", summary);
    return sid;
}

From source file:org.emonocot.portal.view.Functions.java

License:Open Source License

public static String formatDateRange(String dateRange) {

    Matcher matcher = pattern.matcher(dateRange);

    if (matcher.matches()) {
        String beginningString = matcher.group(1);
        String endString = matcher.group(2);

        DateTime beginning = solrDateTimeFormatter.parseDateTime(beginningString);
        DateTime end = solrDateTimeFormatter.parseDateTime(endString);
        Integer gap = Integer.parseInt(matcher.group(3));
        String increment = matcher.group(4);
        DateTimeFormatter dateTimeFormatter = null;
        switch (increment) {
        case "DAY":
            end = end.plusDays(gap);//from   w  w  w . j a va2s .  c  om
            dateTimeFormatter = DateTimeFormat.shortDate();
            break;
        case "WEEK":
            end = end.plusWeeks(gap);
            dateTimeFormatter = DateTimeFormat.shortDate();
            break;
        case "MONTH":
            end = end.plusMonths(gap);
            dateTimeFormatter = DateTimeFormat.forPattern("yyyy/MM");
            break;
        case "YEAR":
            end = end.plusYears(gap);
            dateTimeFormatter = DateTimeFormat.forPattern("yyyy");
            break;
        }

        return dateTimeFormatter.print(beginning) + " - " + dateTimeFormatter.print(end);

    } else {
        return dateRange;
    }

}

From source file:org.epics.archiverappliance.common.TimeUtils.java

public static String convertToISO8601String(java.sql.Timestamp ts) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    DateTime dateTime = new DateTime(ts.getTime(), DateTimeZone.UTC);
    String retval = fmt.print(dateTime);
    return retval;
}

From source file:org.epics.archiverappliance.common.TimeUtils.java

public static String convertToISO8601String(long epochSeconds) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.UTC);
    String retval = fmt.print(dateTime);
    return retval;
}

From source file:org.epics.archiverappliance.common.TimeUtils.java

public static String convertToHumanReadableString(java.sql.Timestamp ts) {
    if (ts == null || ts.getTime() == 0)
        return "Never";
    DateTimeFormatter fmt = DateTimeFormat.forPattern("MMM/dd/yyyy HH:mm:ss z");
    DateTime dateTime = new DateTime(ts.getTime(), DateTimeZone.getDefault());
    String retval = fmt.print(dateTime);
    return retval;
}