Example usage for org.joda.time.format ISODateTimeFormat dateTimeNoMillis

List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeNoMillis

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat dateTimeNoMillis.

Prototype

public static DateTimeFormatter dateTimeNoMillis() 

Source Link

Document

Returns a formatter that combines a full date and time without millis, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZZ).

Usage

From source file:com.google.caliper.runner.OutputFileDumper.java

License:Apache License

private String createTimestamp() {
    return ISODateTimeFormat.dateTimeNoMillis().print(run.startTime());
}

From source file:com.google.devtools.moe.client.dvcs.git.GitWriter.java

License:Apache License

@Override
protected void commitChanges(RevisionMetadata rm) throws CommandException {
    List<String> args = Lists.newArrayList("commit", "--all", "--message", rm.description(), "--date",
            ISODateTimeFormat.dateTimeNoMillis().print(rm.date()));
    if (rm.author() != null) {
        args.add("--author");
        args.add(rm.author());/*from w  w  w.  j  a  v  a 2s .com*/
    }
    revClone.runGitCommand(args.toArray(new String[args.size()]));
}

From source file:com.helger.peppol.DateAdapter.java

License:Mozilla Public License

@Nullable
public static String getAsStringXSD(@Nullable final LocalDateTime aLocalDateTime) {
    return aLocalDateTime == null ? null
            : ISODateTimeFormat.dateTimeNoMillis().withOffsetParsed().print(aLocalDateTime);
}

From source file:com.hurence.logisland.processor.elasticsearch.ElasticsearchRecordConverter.java

License:Apache License

/**
 * Converts an Event into an Elasticsearch document
 * to be indexed later/*from  w w  w  .j av  a2 s .  co  m*/
 *
 * @param record
 * @return
 */
public static String convertToString(Record record) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        String document = "";

        // convert event_time as ISO for ES
        if (record.hasField(FieldDictionary.RECORD_TIME)) {
            try {
                DateTimeFormatter dateParser = ISODateTimeFormat.dateTimeNoMillis();
                document += "@timestamp : ";
                document += dateParser.print(record.getField(FieldDictionary.RECORD_TIME).asLong()) + ", ";
            } catch (Exception ex) {
                logger.error("unable to parse record_time iso date for {}", record);
            }
        }

        // add all other records
        for (Iterator<Field> i = record.getAllFieldsSorted().iterator(); i.hasNext();) {
            Field field = i.next();
            String fieldName = field.getName().replaceAll("\\.", "_");

            switch (field.getType()) {

            case STRING:
                document += fieldName + " : " + field.asString();
                break;
            case INT:
                document += fieldName + " : " + field.asInteger().toString();
                break;
            case LONG:
                document += fieldName + " : " + field.asLong().toString();
                break;
            case FLOAT:
                document += fieldName + " : " + field.asFloat().toString();
                break;
            case DOUBLE:
                document += fieldName + " : " + field.asDouble().toString();
                break;
            case BOOLEAN:
                document += fieldName + " : " + field.asBoolean().toString();
                break;
            default:
                document += fieldName + " : " + field.getRawValue().toString();
                break;
            }
        }

        return document;
    } catch (Throwable ex) {
        logger.error("unable to convert record : {}, {}", record, ex.toString());
    }
    return null;
}

From source file:com.hurence.logisland.service.elasticsearch.ElasticsearchRecordConverter.java

License:Apache License

/**
 * Converts an Event into an Elasticsearch document
 * to be indexed later//from  w w w  .ja v a  2s  . c  o  m
 *e
 * @param record to convert
 * @return the json converted record
 */
static String convertToString(Record record) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        XContentBuilder document = jsonBuilder().startObject();
        final float[] geolocation = new float[2];

        // convert event_time as ISO for ES
        if (record.hasField(FieldDictionary.RECORD_TIME)) {
            try {
                DateTimeFormatter dateParser = ISODateTimeFormat.dateTimeNoMillis();
                document.field("@timestamp",
                        dateParser.print(record.getField(FieldDictionary.RECORD_TIME).asLong()));
            } catch (Exception ex) {
                logger.error("unable to parse record_time iso date for {}", record);
            }
        }

        // add all other records
        record.getAllFieldsSorted().forEach(field -> {
            try {
                // cleanup invalid es fields characters like '.'
                String fieldName = field.getName().replaceAll("\\.", "_");

                switch (field.getType()) {

                case STRING:
                    document.field(fieldName, field.asString());
                    break;
                case INT:
                    document.field(fieldName, field.asInteger().intValue());
                    break;
                case LONG:
                    document.field(fieldName, field.asLong().longValue());
                    break;
                case FLOAT:
                    document.field(fieldName, field.asFloat().floatValue());
                    if (fieldName.equals("lat") || fieldName.equals("latitude"))
                        geolocation[0] = field.asFloat();
                    if (fieldName.equals("long") || fieldName.equals("longitude"))
                        geolocation[1] = field.asFloat();

                    break;
                case DOUBLE:
                    document.field(fieldName, field.asDouble().doubleValue());
                    if (fieldName.equals("lat") || fieldName.equals("latitude"))
                        geolocation[0] = field.asFloat();
                    if (fieldName.equals("long") || fieldName.equals("longitude"))
                        geolocation[1] = field.asFloat();

                    break;
                case BOOLEAN:
                    document.field(fieldName, field.asBoolean().booleanValue());
                    break;
                default:
                    document.field(fieldName, field.getRawValue());
                    break;
                }

            } catch (Throwable ex) {
                logger.error("unable to process a field in record : {}, {}", record, ex.toString());
            }
        });

        if ((geolocation[0] != 0) && (geolocation[1] != 0)) {
            GeoPoint point = new GeoPoint(geolocation[0], geolocation[1]);
            document.latlon("location", geolocation[0], geolocation[1]);
        }

        String result = document.endObject().string();
        document.flush();
        return result;
    } catch (Throwable ex) {
        logger.error("unable to convert record : {}, {}", record, ex.toString());
    }
    return null;
}

From source file:com.hurence.logisland.util.elasticsearch.ElasticsearchRecordConverter.java

License:Apache License

/**
 * Converts an Event into an Elasticsearch document
 * to be indexed later/*from  w w  w . j  av a 2s  . c om*/
 *
 * @param record
 * @return
 */
public static String convert(Record record) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        XContentBuilder document = jsonBuilder().startObject();

        // convert event_time as ISO for ES
        if (record.hasField(FieldDictionary.RECORD_TIME)) {
            try {
                DateTimeFormatter dateParser = ISODateTimeFormat.dateTimeNoMillis();
                document.field("@timestamp",
                        dateParser.print(record.getField(FieldDictionary.RECORD_TIME).asLong()));
            } catch (Exception ex) {
                logger.error("unable to parse record_time iso date for {}", record);
            }
        }

        // add all other records
        record.getAllFieldsSorted().forEach(field -> {
            try {
                // cleanup invalid es fields characters like '.'
                String fieldName = field.getName().replaceAll("\\.", "_");

                switch (field.getType()) {

                case STRING:
                    document.field(fieldName, field.asString());
                    break;
                case INT:
                    document.field(fieldName, field.asInteger().intValue());
                    break;
                case LONG:
                    document.field(fieldName, field.asLong().longValue());
                    break;
                case FLOAT:
                    document.field(fieldName, field.asFloat().floatValue());
                    break;
                case DOUBLE:
                    document.field(fieldName, field.asDouble().doubleValue());
                    break;
                case BOOLEAN:
                    document.field(fieldName, field.asBoolean().booleanValue());
                    break;
                default:
                    document.field(fieldName, field.getRawValue());
                    break;
                }

            } catch (Throwable ex) {
                logger.error("unable to process a field in record : {}, {}", record, ex.toString());
            }
        });

        String result = document.endObject().string();
        document.flush();
        return result;
    } catch (Throwable ex) {
        logger.error("unable to convert record : {}, {}", record, ex.toString());
    }
    return null;
}

From source file:com.palantir.atlasdb.cli.command.TimestampCommand.java

License:Open Source License

@Override
public int execute(AtlasDbServices services) {
    if (dateTime && !immutable) {
        System.err.println("You can't use --date-time without also using --immutable");
        return 1;
    }/*from  w  ww.  j  a  v a  2s . com*/

    long latestTimestamp = services.getTimestampService().getFreshTimestamp();

    if (fresh || !(fresh || immutable)) {
        System.out.println("Fresh timestamp is: " + latestTimestamp);
    }

    if (immutable) {
        long immutableTimestamp = services.getTransactionManager().getImmutableTimestamp();
        System.out.println("Current immutable timestamp is: " + immutableTimestamp);

        if (dateTime) {
            long timeMillis = KeyValueServicePuncherStore.getMillisForTimestamp(services.getKeyValueService(),
                    immutableTimestamp);
            DateTime dt = new DateTime(timeMillis);
            String stringTime = ISODateTimeFormat.dateTimeNoMillis().print(dt);
            System.out.printf("Real date time of immutable timestamp is: " + stringTime);
        }
    }

    return 0;
}

From source file:com.pinterest.deployservice.scm.GithubManager.java

License:Apache License

private long getDate(Map<String, Object> jsonMap) {
    Map<String, Object> commiterMap = (Map<String, Object>) jsonMap.get("committer");
    String dateGMTStr = (String) commiterMap.get("date");
    DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis();
    DateTime dt = parser.parseDateTime(dateGMTStr);
    return dt.getMillis();
}

From source file:com.sappenin.utils.appengine.customernotifications.framework.scheduler.payload.AggregatableNotificationTaskPayload.java

License:Apache License

/**
 * @return The unique task name for aggregating notifications. This is essentially the ancestorGroupingKey, as a
 *         String. In other words, for any NotificationTarget+NotificationType+AnticipatedSendDate, there should
 *         only be a single task in the queue.
 *///from w  ww. ja v  a2  s  . com
@JsonIgnore
@Override
public String getAggregatedTaskName() {
    // We do this as part of the framework so that framework users don't have to worry abou it.
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    String timestamp = fmt.print(this.getEtaScheduledDateTime());

    // No Need to append the DateTime because the framework will handle this for us. See javadoc above.
    return (this.ancestorGroupingKey.getString() + timestamp).replace(":", "");
}

From source file:com.sheepdog.mashmesh.util.FusionTableContentWriter.java

License:Apache License

private static String serializeObjectForFusionTables(Object object) {
    if (object instanceof GeoPt) {
        GeoPt geoPt = (GeoPt) object;//from www .  java  2s  .c  o  m
        return String.format("%f %f", geoPt.getLatitude(), geoPt.getLongitude());
    } else if (object instanceof DateTime) {
        DateTime dateTime = (DateTime) object;
        DateTimeFormatter iso8601Formatter = ISODateTimeFormat.dateTimeNoMillis();
        return iso8601Formatter.print(dateTime);
    } else {
        return object.toString();
    }
}