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

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

Introduction

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

Prototype

public static DateTimeFormatter date() 

Source Link

Document

Returns a formatter for a full date as four digit year, two digit month of year, and two digit day of month (yyyy-MM-dd).

Usage

From source file:org.overlord.sramp.client.SrampClientQuery.java

License:Apache License

/**
 * Sets a parameter on the query - this should match up to a ? in the
 * query template provided.  Note: this will add a date to the query.  In
 * order to be more precise and send a full DateTime, use the Calendar
 * form of this method:  <code>parameter(Calendar param)</code>
 * @param param//from   w ww. j av  a2 s .  c  o  m
 */
public SrampClientQuery parameter(Date param) {
    String val = ISODateTimeFormat.date().print(new DateTime(param));
    replacementParams.add("'" + val + "'"); //$NON-NLS-1$ //$NON-NLS-2$
    return this;
}

From source file:org.overlord.sramp.repository.query.AbstractSrampQueryImpl.java

License:Apache License

/**
 * @see org.overlord.sramp.repository.query.SrampQuery#setDate(java.util.Date)
 *///from   ww  w.  j  av  a 2  s .  com
@Override
public void setDate(Date date) {
    String val = ISODateTimeFormat.date().print(new DateTime(date));
    this.replacementParams.add(new StringReplacementParam(val));
}

From source file:org.phenotips.data.internal.controller.Biospecimen.java

License:Open Source License

/**
 * Populates this Biospecimen object with the contents of the given JSONObject.
 * @param jsonObject the JSONObject to parse (can be null)
 * @throws IllegalArgumentException if incoming object is invalid
 * @throws UnsupportedOperationException if any field parsing fails
 *//*from ww w  . j  ava 2 s  . co  m*/
public Biospecimen(JSONObject jsonObject) throws IllegalArgumentException, UnsupportedOperationException {
    if (jsonObject == null) {
        return;
    }

    DateTimeFormatter formatter = ISODateTimeFormat.date();

    for (String property : Biospecimen.PROPERTIES) {
        String value = jsonObject.optString(property);

        if (StringUtils.isBlank(value)) {
            continue;
        }

        switch (property) {
        case Biospecimen.TYPE_PROPERTY_NAME:
            this.setType(value);
            break;
        case Biospecimen.DATE_COLLECTED_PROPERTY_NAME:
            this.setDateCollected(formatter.parseDateTime(value));
            break;
        case Biospecimen.DATE_RECEIVED_PROPERTY_NAME:
            this.setDateReceived(formatter.parseDateTime(value));
            break;
        default:
            break;
        }
    }
}

From source file:org.phenotips.data.internal.controller.Biospecimen.java

License:Open Source License

/**
 * Converts this biospecimen object into a JSONObject.
 * @param propertiesToInclude a list of properties to include, if null/empty, all properties will be added to the
 *                              resulting JSONObject
 * @return a JSONObject or null if the resulting JSONObject is empty
 *///from   w ww .  j av  a2  s . c o  m
public JSONObject toJSON(Collection<String> propertiesToInclude) {

    Collection<String> propertiesToIterateOver = propertiesToInclude;
    if (CollectionUtils.isEmpty(propertiesToIterateOver)) {
        propertiesToIterateOver = Biospecimen.PROPERTIES;
    }

    JSONObject jsonObject = new JSONObject();
    DateTimeFormatter jsonDateFormat = ISODateTimeFormat.date();

    for (String propertyName : propertiesToIterateOver) {

        switch (propertyName) {
        case Biospecimen.TYPE_PROPERTY_NAME:
            if (this.hasType()) {
                jsonObject.put(propertyName, this.getType());
            }
            break;
        case Biospecimen.DATE_COLLECTED_PROPERTY_NAME:
            if (this.hasDateCollected()) {
                jsonObject.put(propertyName, jsonDateFormat.print(this.getDateCollected()));

            }
            break;
        case Biospecimen.DATE_RECEIVED_PROPERTY_NAME:
            if (this.hasDateReceived()) {
                jsonObject.put(propertyName, jsonDateFormat.print(this.getDateReceived()));
            }
            break;
        default:
            break;
        }
    }

    if (jsonObject.length() == 0) {
        return null;
    }

    return jsonObject;
}

From source file:org.springframework.format.datetime.joda.DateTimeFormatterFactory.java

License:Apache License

/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter//from  w w w .j a  va 2  s. com
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
    DateTimeFormatter dateTimeFormatter = null;
    if (StringUtils.hasLength(this.pattern)) {
        dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
    } else if (this.iso != null && this.iso != ISO.NONE) {
        switch (this.iso) {
        case DATE:
            dateTimeFormatter = ISODateTimeFormat.date();
            break;
        case TIME:
            dateTimeFormatter = ISODateTimeFormat.time();
            break;
        case DATE_TIME:
            dateTimeFormatter = ISODateTimeFormat.dateTime();
            break;
        case NONE:
            /* no-op */
            break;
        default:
            throw new IllegalStateException("Unsupported ISO format: " + this.iso);
        }
    } else if (StringUtils.hasLength(this.style)) {
        dateTimeFormatter = DateTimeFormat.forStyle(this.style);
    }

    if (dateTimeFormatter != null && this.timeZone != null) {
        dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
    }
    return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}

From source file:org.springframework.format.datetime.joda.JodaTimeFormattingConfigurer.java

License:Apache License

private DateTimeFormatter getJodaDateFormatter() {
    if (this.useIsoFormat) {
        return ISODateTimeFormat.date();
    }// ww w  .j a va2  s  .co  m
    if (this.dateStyle != null) {
        return DateTimeFormat.forStyle(this.dateStyle + "-");

    } else {
        return DateTimeFormat.shortDate();
    }
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

private static DateTimeParser dateTimeParser() {
    if (dtp == null) {
        dtp = new DateTimeFormatterBuilder().append(ISODateTimeFormat.date()).appendLiteral('T')
                .append(timeParser()).toParser();
    }//w ww  .j  a  v a2s . c  o m
    return dtp;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

private static DateTimePrinter dateTimePrinter() {
    if (dtprt == null) {
        dtprt = new DateTimeFormatterBuilder().append(ISODateTimeFormat.date()).appendLiteral('T')
                .append(timePrinter()).toPrinter();
    }/*w w  w . j  ava 2 s .c o m*/
    return dtprt;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

private static DateTimeParser dateParser() {
    if (dp == null) {
        dp = new DateTimeFormatterBuilder().append(ISODateTimeFormat.date())
                .appendOptional(new TimeZoneValidatingParser(timeZoneFormatter().getParser())).toParser();
    }/*from w  w  w  . j a v a2s  .c o m*/
    return dp;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

private static DateTimePrinter datePrinter() {
    if (dprt == null) {
        dprt = new DateTimeFormatterBuilder().append(ISODateTimeFormat.date()).append(timeZoneFormatter())
                .toPrinter();/* w w w .j a  va  2  s. c o  m*/
    }
    return dprt;
}