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

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

Introduction

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

Prototype

public static DateTimeFormatter dateTime() 

Source Link

Document

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

Usage

From source file:io.druid.timeline.DataSegmentUtils.java

License:Apache License

/**
 * Parses a segment identifier into its components: dataSource, interval, version, and any trailing tags. Ignores
 * shard spec.// w w w.j  a  va2  s . co m
 *
 * It is possible that this method may incorrectly parse an identifier, for example if the dataSource name in the
 * identifier contains a DateTime parseable string such as 'datasource_2000-01-01T00:00:00.000Z' and dataSource was
 * provided as 'datasource'. The desired behavior in this case would be to return null since the identifier does not
 * actually belong to the provided dataSource but a non-null result would be returned. This is an edge case that would
 * currently only affect paged select queries with a union dataSource of two similarly-named dataSources as in the
 * given example.
 *
 * @param dataSource the dataSource corresponding to this identifier
 * @param identifier segment identifier
 * @return a {@link DataSegmentUtils.SegmentIdentifierParts} object if the identifier could be parsed, null otherwise
 */
public static SegmentIdentifierParts valueOf(String dataSource, String identifier) {
    if (!identifier.startsWith(StringUtils.format("%s_", dataSource))) {
        return null;
    }

    String remaining = identifier.substring(dataSource.length() + 1);
    String[] splits = remaining.split(DataSegment.delimiter);
    if (splits.length < 3) {
        return null;
    }

    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();

    try {
        DateTime start = formatter.parseDateTime(splits[0]);
        DateTime end = formatter.parseDateTime(splits[1]);
        String version = splits[2];
        String trail = splits.length > 3 ? join(splits, DataSegment.delimiter, 3, splits.length) : null;

        return new SegmentIdentifierParts(dataSource, new Interval(start.getMillis(), end.getMillis()), version,
                trail);
    } catch (IllegalArgumentException e) {
        return null;
    }
}

From source file:io.fabric8.maven.docker.util.Timestamp.java

License:Apache License

/**
 * Create a timestamp by parsing the given string representation which must be in an extended ISO 8601 Format
 * with Nanoseconds since this is the format used by Docker for logging (e.g. "2014-11-24T22:34:00.761764812Z")
 *
 * @param spec date specification to parse
 *//*ww w  . ja va 2  s .  co  m*/
public Timestamp(String spec) {
    //
    Matcher matcher = TS_PATTERN.matcher(spec);
    if (!matcher.matches()) {
        throw new IllegalArgumentException("Invalid timestamp '" + spec + "' given.");
    }
    String millis = matcher.group(2);
    String rest = matcher.group(3);
    this.rest = rest != null ? Integer.parseInt(rest) : 0;
    DateTimeFormatter parser = ISODateTimeFormat.dateTime();
    date = parser.parseDateTime(matcher.group(1) + (millis != null ? "." + millis : ".000") + matcher.group(4));
}

From source file:io.jawg.osmcontributor.rest.mappers.JodaTimeDateTimeDeserializer.java

License:Open Source License

@Override
public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    DateTime dateTime = null;//ww  w  .j  av  a  2s.  c om
    if (!json.isJsonNull()) {
        try {
            dateTime = DateTime.parse(json.getAsString(), ISODateTimeFormat.dateTime());
        } catch (Exception e) {
            Timber.e(e, "Joda-Time DateTime Transform failed.");
            throw new JsonParseException(e);
        }
    }
    return dateTime;
}

From source file:io.konig.dao.core.BoundaryPoint.java

License:Apache License

public DateTime toDateTime() {
    return ISODateTimeFormat.dateTime().parseDateTime(value);
}

From source file:io.konig.gae.datastore.impl.SemanticDatastoreImpl.java

License:Apache License

public SemanticDatastoreImpl(EntityNamer entityNamer) {
    this.entityNamer = entityNamer;
    timeFormat = ISODateTimeFormat.dateTime();
}

From source file:io.macgyver.core.util.CertChecker.java

License:Apache License

protected ObjectNode checkCertificates(ObjectNode nx, List<X509Certificate> certs, String alternateHost) {
    int fewestDaysToExpiration = Integer.MAX_VALUE;
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode problems = (ArrayNode) nx.get("problems");
    ArrayNode certArray = (ArrayNode) nx.get("certs");

    try {/*from w ww  .  j a  va 2s. c  om*/

        for (X509Certificate cert : certs) {
            ObjectNode n = mapper.createObjectNode();
            String subjectDN = cert.getSubjectDN().getName();
            n.put("subjectDN", subjectDN);

            n.put("subjectCN", extractCN(cert));
            n.put("version", cert.getVersion());
            n.put("issuerDN", cert.getIssuerDN().getName());
            n.put("notValidAfter", ISODateTimeFormat.dateTime().print(cert.getNotAfter().getTime()));
            n.put("notValidAfterTimestamp", cert.getNotAfter().getTime());
            n.put("notValidBefore", ISODateTimeFormat.dateTime().print(cert.getNotBefore().getTime()));
            n.put("notValidBeforeTimestamp", cert.getNotBefore().getTime());
            n.put("serial", cert.getSerialNumber().toString());
            n.put("isDateValid", true);
            n.put("version", cert.getVersion());
            n.put("type", cert.getType());

            if (System.currentTimeMillis() < cert.getNotBefore().getTime()) {
                problems.add(mapper.createObjectNode().put(DESCRIPTION, "certificate not yet valid").put("type",
                        "error"));

                n.put("isDateValid", false);
            }
            if (System.currentTimeMillis() > cert.getNotAfter().getTime()) {

                problems.add(
                        mapper.createObjectNode().put(DESCRIPTION, "certificate expired").put("type", "error"));

                n.put("isDateValid", false);
            }
            int daysToExpiration = Math.max(0,
                    Days.daysBetween(new DateTime(System.currentTimeMillis()), new DateTime(cert.getNotAfter()))
                            .getDays());
            n.put("daysToExpiration", daysToExpiration);
            fewestDaysToExpiration = Math.min(fewestDaysToExpiration, daysToExpiration);

            certArray.add(n);

            Collection<List<?>> altNames = cert.getSubjectAlternativeNames();
            ArrayNode altNameArray = mapper.createArrayNode();
            n.set("subjectAlternativeNames", altNameArray);
            // http://stackoverflow.com/questions/18775206/extracting-subjectalternativename-from-x509-in-java
            if (altNames != null) {
                for (List altList : altNames) {
                    if (altList.size() == 2) {
                        ObjectNode altData = mapper.createObjectNode();
                        altData.put("type", Integer.parseInt(altList.get(0).toString()));
                        altData.put("value", altList.get(1).toString());

                        altNameArray.add(altData);
                    }
                }
            }

        }

    } catch (Exception e) {
        problems.add(mapper.createObjectNode().put("type", "error").put(DESCRIPTION, e.toString()));
    }

    if (!doesCertificateHostnameMatch(certs, alternateHost)) {
        problems.add(mapper.createObjectNode().put(DESCRIPTION, "host name does not match certificate")
                .put("type", "error"));

    }
    if (fewestDaysToExpiration <= getCertExpirationWarningDays()) {
        problems.add(mapper.createObjectNode()
                .put(DESCRIPTION, "certificate will expire in " + fewestDaysToExpiration + " days")
                .put("type", "warning"));
    }

    nx.put("daysToExpiration", fewestDaysToExpiration);
    return nx;
}

From source file:io.pivotal.github.IsoDateTimeSerializer.java

License:Apache License

@Override
public void serialize(DateTime value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    gen.writeString(ISODateTimeFormat.dateTime().print(value));
}

From source file:io.prestosql.operator.scalar.DateTimeFunctions.java

License:Apache License

@ScalarFunction("to_iso8601")
@SqlType("varchar(35)")
// YYYY-MM-DDTHH:MM:SS.mmm+HH:MM is a standard notation, and it requires 29 characters.
// However extended notation with format (Y)+-MM-DDTHH:MM:SS.mmm+HH:MM is also acceptable and as
// the maximum year represented by 64bits timestamp is ~584944387 it may require up to 35 characters.
public static Slice toISO8601FromTimestamp(ConnectorSession session,
        @SqlType(StandardTypes.TIMESTAMP) long timestamp) {
    if (session.isLegacyTimestamp()) {
        DateTimeFormatter formatter = ISODateTimeFormat.dateTime()
                .withChronology(getChronology(session.getTimeZoneKey()));
        return utf8Slice(formatter.print(timestamp));
    } else {/* w  w w.j  av a 2  s . c  om*/
        DateTimeFormatter formatter = ISODateTimeFormat.dateHourMinuteSecondMillis()
                .withChronology(UTC_CHRONOLOGY);
        return utf8Slice(formatter.print(timestamp));
    }
}

From source file:io.prestosql.operator.scalar.DateTimeFunctions.java

License:Apache License

@ScalarFunction("to_iso8601")
@SqlType("varchar(35)")
// YYYY-MM-DDTHH:MM:SS.mmm+HH:MM is a standard notation, and it requires 29 characters.
// However extended notation with format (Y)+-MM-DDTHH:MM:SS.mmm+HH:MM is also acceptable and as
// the maximum year represented by 64bits timestamp is ~584944387 it may require up to 35 characters.
public static Slice toISO8601FromTimestampWithTimeZone(
        @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) {
    long millisUtc = unpackMillisUtc(timestampWithTimeZone);
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime()
            .withChronology(getChronology(unpackZoneKey(timestampWithTimeZone)));
    return utf8Slice(formatter.print(millisUtc));
}

From source file:io.smalldata.ohmageomh.surveys.domain.ISOW3CDateTimeFormat.java

License:Apache License

/**
 * Returns a formatter that combines a full date, two digit hour of the
 * day, two digit minute of the hour, two digit second of the minute,
 * three digit milliseconds of the second and a time zone.
 * //from w  w  w. jav  a 2s.c o m
 * @return A formatter for the date, hour, minute, second, millisecond,
 *          and time zone.
 */
public static DateTimeFormatter dateHourMinuteSecondMillisZone() {
    if (yearMonthDayHourMinuteSecondMillisZone == null) {
        yearMonthDayHourMinuteSecondMillisZone = ISODateTimeFormat.dateTime().withOffsetParsed();
    }
    return yearMonthDayHourMinuteSecondMillisZone;
}