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

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

Introduction

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

Prototype

public static DateTimeFormatter localDateOptionalTimeParser() 

Source Link

Document

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

Usage

From source file:com.jbirdvegas.mgerrit.search.AgeSearch.java

License:Apache License

private void parseDate(String param) {
    try {// ww  w  .j  a  v  a  2s  .  co m
        if (param.endsWith("Z")) {
            /* The string representation of an instant includes a Z at the end, but this is not
             *  a valid format for the parser. */
            String newParam = param.substring(0, param.length() - 1);
            mInstant = Instant.parse(newParam, ISODateTimeFormat.localDateOptionalTimeParser());
        } else {
            mInstant = Instant.parse(param, ISODateTimeFormat.localDateOptionalTimeParser());
        }
        mPeriod = null;
    } catch (IllegalArgumentException ignored) {
        mPeriod = toPeriod(param);
        mInstant = null;
    }
}

From source file:io.mapsquare.osmcontributor.rest.mappers.PoiStorageConverter.java

License:Open Source License

public Poi convertPoi(PoiDto poiDto) {
    PoiType type = poiTypeDao.findByBackendId(poiDto.getTypeBackendId());

    // We don't keep the Poi if we don't know it's PoiType
    if (type == null) {
        return null;
    }/*from  w  ww .  j  a  v  a2 s.c om*/

    Poi poi = new Poi();

    poi.setType(type);
    poi.setBackendId(poiDto.getBackendId());
    poi.setLatitude(poiDto.getLatLng().getLatitude());
    poi.setLongitude(poiDto.getLatLng().getLongitude());
    poi.setLevel(poiDto.getLevel().toString());
    poi.setVersion(poiDto.getRevision().toString());
    poi.setUpdateDate(ISODateTimeFormat.localDateOptionalTimeParser().parseDateTime(poiDto.getLastUpdate()));
    poi.setName(poiDto.getName());
    poi.setUpdated(false);

    if (poiDto.getFields() != null) {
        poi.setTags(new ArrayList<PoiTag>(poiDto.getFields().size()));
        for (Map.Entry<String, String> field : poiDto.getFields().entrySet()) {
            PoiTag poiTag = new PoiTag();
            poiTag.setKey(field.getKey());
            poiTag.setValue(field.getValue());
            poiTag.setPoi(poi);
            poi.getTags().add(poiTag);
        }
    } else {
        poi.setTags(new ArrayList<PoiTag>());
    }

    return poi;
}

From source file:it.d4nguard.rgrpg.util.dynacast.adapters.DateTimeAdapter.java

License:Open Source License

/**
 * {@inheritDoc}//from   ww w. j a v  a  2s.c o  m
 */
@Override
public ReadableInstant adapt(String value) {
    // value is a string formatted as: "07/04/1987[dd/MM/yyyy]"
    String date = "";
    DateTimeFormatter fmt;
    Triplet<String, String, String> tri = StringUtils.getBetween(value, '[', ']');
    date = tri.getLeft();
    if (tri.hasCenter())
        fmt = DateTimeFormat.forPattern(tri.getCenter());
    else
        fmt = ISODateTimeFormat.localDateOptionalTimeParser();
    fmt = fmt.withLocale(Locale.getDefault());
    if (getType().equals(DateTime.class))
        return DateTime.parse(date, fmt);
    else if (getType().equals(DateMidnight.class))
        return DateMidnight.parse(date, fmt);
    else if (getType().equals(Instant.class))
        return Instant.parse(date, fmt);
    else if (getType().equals(MutableDateTime.class))
        return MutableDateTime.parse(date, fmt);
    else
        throw new UnsupportedOperationException("type");
}