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

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

Introduction

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

Prototype

public static DateTimeFormatter dateOptionalTimeParser() 

Source Link

Document

Returns a generic ISO datetime parser where the date is mandatory and the time is optional.

Usage

From source file:org.loklak.android.data.AbstractIndexEntry.java

License:Open Source License

public static Date parseDate(Object d) {
    if (d == null)
        return new Date();
    if (d instanceof Date)
        return (Date) d;
    if (d instanceof Long)
        return new Date(((Long) d).longValue());
    if (d instanceof String)
        return ISODateTimeFormat.dateOptionalTimeParser().parseDateTime((String) d).toDate();
    assert false;
    return new Date();
}

From source file:org.loklak.android.data.AbstractIndexEntry.java

License:Open Source License

public static Date parseDate(Object d, Date dflt) {
    if (d == null)
        return dflt;
    if (d instanceof Long)
        return new Date(((Long) d).longValue());
    if (d instanceof String)
        return ISODateTimeFormat.dateOptionalTimeParser().parseDateTime((String) d).toDate();
    assert false;
    return dflt;/*ww  w  .j a v a  2 s  .com*/
}

From source file:org.loklak.objects.AbstractObjectEntry.java

License:Open Source License

public static Date parseDate(Object d, Date dflt) {
    if (d == null)
        return dflt;
    if (d instanceof Long)
        return new Date(((Long) d).longValue());
    if (d instanceof String)
        return ISODateTimeFormat.dateOptionalTimeParser().parseDateTime((String) d).toDate();
    if (d instanceof Date)
        return (Date) d;
    assert false;
    return dflt;/*  www .  j  a v  a2  s .c  o  m*/
}

From source file:org.n52.iceland.util.DateTimeHelper.java

License:Open Source License

/**
 * Parses a time String to a Joda Time DateTime object
 *
 * @param timeString/*from  w  w w .j a  va 2  s  . c o m*/
 *            Time String
 * @return DateTime object
 * @throws DateTimeParseException
 *             If an error occurs.
 */
public static DateTime parseIsoString2DateTime(final String timeString) throws DateTimeParseException {
    checkForValidity(timeString);
    if (Strings.isNullOrEmpty(timeString)) {
        return null;
    }
    try {
        if (timeString.contains("+") || Pattern.matches("-\\d", timeString) || timeString.contains(Z)
                || timeString.contains("z")) {
            return ISODateTimeFormat.dateOptionalTimeParser().withOffsetParsed().parseDateTime(timeString);
        } else {
            return ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC)
                    .parseDateTime(timeString);
        }
    } catch (final RuntimeException uoe) {
        throw new DateTimeParseException(timeString, uoe);
    }
}

From source file:org.n52.janmayen.Times.java

License:Apache License

public static DateTime decodeDateTime(String string) {
    if (Strings.isNullOrEmpty(string)) {
        return null;
    }//  w ww.  j  a  va  2  s  .  co  m
    if (string.contains("+") || Pattern.matches("-\\d", string) || string.contains(Z) || string.contains("z")) {
        return ISODateTimeFormat.dateOptionalTimeParser().withOffsetParsed().parseDateTime(string);
    } else {
        return ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC).parseDateTime(string);
    }
}

From source file:org.n52.shetland.util.DateTimeHelper.java

License:Apache License

public static DateTime parseString2DateTime(final String timeString, final String dateFormat)
        throws DateTimeParseException {
    checkForValidity(timeString);/*from  w  w  w  .j a  v  a2s  .c  o  m*/
    if (Strings.isNullOrEmpty(timeString)) {
        return null;
    }
    try {
        if (!Strings.isNullOrEmpty(dateFormat)) {
            if (checkOffset(timeString)) {
                return DateTimeFormat.forPattern(dateFormat).withOffsetParsed().parseDateTime(timeString);
            } else {
                return DateTimeFormat.forPattern(dateFormat).withZone(DateTimeZone.UTC)
                        .parseDateTime(timeString);
            }
        }
        if (checkOffset(timeString)) {
            return ISODateTimeFormat.dateOptionalTimeParser().withOffsetParsed().parseDateTime(timeString);
        } else {
            return ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC)
                    .parseDateTime(timeString);
        }
    } catch (final RuntimeException uoe) {
        throw new DateTimeParseException(timeString, uoe);
    }
}

From source file:org.n52.sos.SosDateTimeUtilities.java

License:Open Source License

/**
 * parses an iso8601 time String to a DateTime Object.
 * //  w  w  w. ja  v  a2 s.  c  om
 * @param timeString the time String
 * @return Returns a DateTime Object.
 * @throws OwsExceptionReport 
 */
public static DateTime parseIsoString2DateTime(String timeString) throws OwsExceptionReport {
    if (timeString == null || timeString.equals("")) {
        return null;
    }
    try {
        return ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(timeString);
    } catch (IllegalArgumentException iae) {
        OwsExceptionReport se = new OwsExceptionReport(ExceptionLevel.DetailedExceptions);
        log.error("Error while parse time String to DateTime!", iae);
        se.addCodedException(ExceptionCode.InvalidParameterValue, null, iae);
        throw se;
    } catch (UnsupportedOperationException uoe) {
        OwsExceptionReport owser = new OwsExceptionReport(ExceptionLevel.DetailedExceptions);
        log.error("Error while parse time String to DateTime!", uoe);
        owser.addCodedException(ExceptionCode.InvalidParameterValue, null, uoe);
        throw owser;
    }
}

From source file:org.vpac.ndg.query.Query.java

License:Open Source License

private DateTime[] determineTemporalBounds(QueryDefinition qd) {
    DateTime temporalBounds[] = new DateTime[2];
    DateTimeFormatter fmt = ISODateTimeFormat.dateOptionalTimeParser().withZoneUTC();
    GridDefinition gd = qd.output.grid;/* w w  w  .j a va 2  s . co m*/
    if (gd.timeMin != null && !gd.timeMin.isEmpty())
        temporalBounds[0] = fmt.parseDateTime(qd.output.grid.timeMin);
    if (gd.timeMax != null && !gd.timeMax.isEmpty())
        temporalBounds[1] = fmt.parseDateTime(qd.output.grid.timeMax);
    return temporalBounds;
}

From source file:se.softhouse.jargo.addons.DateTimeParser.java

License:Apache License

DateTimeParser(DateTimeZone timeZone) {
    this.timeZone = requireNonNull(timeZone);
    this.formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(timeZone);
}