Search in sources :

Example 71 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project joda-time by JodaOrg.

the class AbstractInterval method toString.

/**
     * Output a string in ISO8601 interval format.
     * <p>
     * From version 2.1, the string includes the time zone offset.
     *
     * @return re-parsable string (in the default zone)
     */
public String toString() {
    DateTimeFormatter printer = ISODateTimeFormat.dateTime();
    printer = printer.withChronology(getChronology());
    StringBuffer buf = new StringBuffer(48);
    printer.printTo(buf, getStartMillis());
    buf.append('/');
    printer.printTo(buf, getEndMillis());
    return buf.toString();
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 72 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project joda-time by JodaOrg.

the class GJChronology method toString.

// Output
//-----------------------------------------------------------------------
/**
     * Gets a debugging toString.
     * 
     * @return a debugging string
     */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    return sb.toString();
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 73 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project drill by apache.

the class JodaDateValidatorTest method parseDateFromPostgres.

private DateTime parseDateFromPostgres(String date, String pattern) {
    String jodaFormat = toJodaFormat(pattern);
    DateTimeFormatter format = forPattern(jodaFormat);
    return parse(date, format).withZoneRetainFields(DateTimeZone.UTC);
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 74 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project drill by apache.

the class DateUtility method getDateTimeFormatter.

// Function returns the date time formatter used to parse date strings
public static DateTimeFormatter getDateTimeFormatter() {
    if (dateTimeTZFormat == null) {
        DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
        DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser();
        DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
        DateTimeParser optionalZone = DateTimeFormat.forPattern(" ZZZ").getParser();
        dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime).appendOptional(optionalSec).appendOptional(optionalZone).toFormatter();
    }
    return dateTimeTZFormat;
}
Also used : DateTimeParser(org.joda.time.format.DateTimeParser) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeFormatterBuilder(org.joda.time.format.DateTimeFormatterBuilder)

Example 75 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project lucene-solr by apache.

the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedDate.

public void testFailedParseMixedDate() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateOptionalTimeParser().withZoneUTC();
    Map<Object, Object> mixed = new HashMap<>();
    String[] dateStrings = { "2020-05-13T18:47", "1989-12-14", "1682-07-22T18:33:00.000Z" };
    for (String dateString : dateStrings) {
        mixed.put(dateTimeFormatter.parseDateTime(dateString).toDate(), dateString);
    }
    Double extraDouble = 29.554d;
    // Double-typed field value
    mixed.put(extraDouble, extraDouble);
    SolrInputDocument d = processAdd("parse-date-no-run-processor", doc(f("id", "7201"), f("not_in_schema", mixed.values())));
    assertNotNull(d);
    boolean foundDouble = false;
    for (Object o : d.getFieldValues("not_in_schema")) {
        if (extraDouble == o) {
            foundDouble = true;
        } else {
            assertTrue(o instanceof String);
        }
        mixed.values().remove(o);
    }
    assertTrue(foundDouble);
    assertTrue(mixed.isEmpty());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IndexSchema(org.apache.solr.schema.IndexSchema) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Aggregations

DateTimeFormatter (org.joda.time.format.DateTimeFormatter)189 DateTime (org.joda.time.DateTime)88 Date (java.util.Date)40 Test (org.junit.Test)25 DateTimeZone (org.joda.time.DateTimeZone)19 ArrayList (java.util.ArrayList)14 SolrInputDocument (org.apache.solr.common.SolrInputDocument)12 IndexSchema (org.apache.solr.schema.IndexSchema)12 DateTimeFormatterBuilder (org.joda.time.format.DateTimeFormatterBuilder)12 HashMap (java.util.HashMap)10 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)10 IOException (java.io.IOException)9 Calendar (java.util.Calendar)8 Map (java.util.Map)8 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)7 FormatDateTimeFormatter (org.elasticsearch.common.joda.FormatDateTimeFormatter)7 Test (org.testng.annotations.Test)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 FilterType (net.opengis.filter.v_1_1_0.FilterType)6 Deployment (org.activiti.engine.test.Deployment)6