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();
}
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;
}
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));
}
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);
}
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());
}
Aggregations