Search in sources :

Example 56 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project Activiti by Activiti.

the class TypeConverterImpl method coerceToString.

protected String coerceToString(Object value) {
    if (value == null) {
        return "";
    }
    if (value instanceof String) {
        return (String) value;
    }
    if (value instanceof Enum<?>) {
        return ((Enum<?>) value).name();
    }
    if (value instanceof Date) {
        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
        DateTime dt = new DateTime(value);
        return fmt.print(dt);
    }
    return value.toString();
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 57 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project gerrit by GerritCodeReview.

the class ScheduleConfig method initialDelay.

private static long initialDelay(Config rc, String section, String subsection, String keyStartTime, DateTime now, long interval) {
    long delay = MISSING_CONFIG;
    String start = rc.getString(section, subsection, keyStartTime);
    try {
        if (start != null) {
            DateTimeFormatter formatter;
            MutableDateTime startTime = now.toMutableDateTime();
            try {
                formatter = ISODateTimeFormat.hourMinute();
                LocalTime firstStartTime = formatter.parseLocalTime(start);
                startTime.hourOfDay().set(firstStartTime.getHourOfDay());
                startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour());
            } catch (IllegalArgumentException e1) {
                formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US);
                LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start);
                startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek());
                startTime.hourOfDay().set(firstStartDateTime.getHourOfDay());
                startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour());
            }
            startTime.secondOfMinute().set(0);
            startTime.millisOfSecond().set(0);
            long s = startTime.getMillis();
            long n = now.getMillis();
            delay = (s - n) % interval;
            if (delay <= 0) {
                delay += interval;
            }
        } else {
            log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section, keyStartTime));
        }
    } catch (IllegalArgumentException e2) {
        log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime), e2);
        delay = INVALID_CONFIG;
    }
    return delay;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalTime(org.joda.time.LocalTime) MutableDateTime(org.joda.time.MutableDateTime) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 58 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project uPortal by Jasig.

the class StatisticsPortletController method initBinder.

@InitBinder
public void initBinder(WebDataBinder binder) {
    final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("M/d/yyyy").toFormatter();
    binder.registerCustomEditor(DateMidnight.class, new CustomDateMidnightEditor(formatter, false));
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeFormatterBuilder(org.joda.time.format.DateTimeFormatterBuilder) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 59 with DateTimeFormatter

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

the class RulesApplier method generateRandomDate.

public String generateRandomDate(String min, String max) throws Exception {
    DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN).withZone(DateTimeZone.UTC);
    DateTime minDt;
    DateTime maxDt;
    DateTime dt;
    minDt = fmtr.parseDateTime(checkDatePattern(min));
    maxDt = fmtr.parseDateTime(checkDatePattern(max));
    // Get Ms Date between min and max
    synchronized (randomDataGenerator) {
        //Make sure date generated is exactly between the passed limits
        long rndLong = randomDataGenerator.nextLong(minDt.getMillis() + 1, maxDt.getMillis() - 1);
        dt = new DateTime(rndLong, PherfConstants.DEFAULT_TIME_ZONE);
    }
    return fmtr.print(dt);
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime)

Example 60 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)209 DateTime (org.joda.time.DateTime)95 Date (java.util.Date)40 Test (org.junit.Test)25 DateTimeZone (org.joda.time.DateTimeZone)19 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)12 IndexSchema (org.apache.solr.schema.IndexSchema)12 DateTimeFormatterBuilder (org.joda.time.format.DateTimeFormatterBuilder)12 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