List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:org.apache.solr.update.processor.ParseDateFieldUpdateProcessorFactory.java
License:Apache License
@Override public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {/*from w w w. ja va 2 s .c o m*/ return new AllValuesOrNoneFieldMutatingUpdateProcessor(getSelector(), next) { @Override protected Object mutateValue(Object srcVal) { if (srcVal instanceof CharSequence) { String srcStringVal = srcVal.toString(); for (Map.Entry<String, DateTimeFormatter> format : formats.entrySet()) { DateTimeFormatter parser = format.getValue(); try { DateTime dateTime = parser.parseDateTime(srcStringVal); return dateTime.withZone(DateTimeZone.UTC).toDate(); } catch (IllegalArgumentException e) { log.debug("value '{}' is not parseable with format '{}'", new Object[] { srcStringVal, format.getKey() }); } } log.debug("value '{}' was not parsed by any configured format, thus was not mutated", srcStringVal); return SKIP_FIELD_VALUE_LIST_SINGLETON; } if (srcVal instanceof Date) { return srcVal; } return SKIP_FIELD_VALUE_LIST_SINGLETON; } }; }
From source file:org.apache.streams.data.util.RFC3339Utils.java
License:Apache License
private static DateTime parseUTC(DateTimeFormatter formatter, String toParse) { return formatter.parseDateTime(toParse); }
From source file:org.apache.streams.jackson.StreamsDateTimeDeserializer.java
License:Apache License
/** * Applies each additional format in turn, until it can provide a non-null DateTime *//*from www. j av a 2 s. c o m*/ @Override public DateTime deserialize(JsonParser jpar, DeserializationContext context) throws IOException { DateTime result = RFC3339Utils.parseToUTC(jpar.getValueAsString()); Iterator<DateTimeFormatter> iterator = formatters.iterator(); while (result == null && iterator.hasNext()) { DateTimeFormatter formatter = iterator.next(); result = formatter.parseDateTime(jpar.getValueAsString()); } return result; }
From source file:org.apache.streams.juneau.JodaDateSwap.java
License:Apache License
@Override /* PojoSwap */ public DateTime unswap(BeanSession session, String f, ClassMeta<?> hint) throws ParseException { DateTimeFormatter dateFormatter = this.dateFormatter; if (StringUtils.isNotBlank( session.getProperty("format", String.class, RFC3339Utils.UTC_STANDARD_FMT.toString()))) { dateFormatter = DateTimeFormat.forPattern( session.getProperty("format", String.class, RFC3339Utils.UTC_STANDARD_FMT.toString())); }/*w ww .j av a 2 s . c o m*/ return dateFormatter.parseDateTime(f); }
From source file:org.apache.streams.util.DateUtil.java
License:Apache License
public static Set<String> getAliasesForDateRange(String starDate, String endDate, String prefix) throws ParseException { DateTime start = null;//w w w. j a va 2 s . c o m DateTime end = null; DateTimeFormatter df = ISODateTimeFormat.dateTimeNoMillis(); try { start = df.parseDateTime(starDate); } catch (Exception e) { //do nothing. try to parse with other parsers } if (start == null) { start = determineDateTime(starDate); } if (endDate != null) { try { end = df.parseDateTime(endDate); } catch (Exception e) { //do nothing. try to parse with other parsers } if (end == null) end = determineDateTime(endDate); } return getAliasesForDateRange(start, end, prefix); }
From source file:org.apache.wicket.datetime.DateConverter.java
License:Apache License
/** * @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String, * java.util.Locale)//from w ww .ja v a2 s. c om */ public Date convertToObject(String value, Locale locale) { if (Strings.isEmpty(value)) { return null; } DateTimeFormatter format = getFormat(locale); if (format == null) { throw new IllegalStateException("format must be not null"); } if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); DateTime dateTime = null; // set time zone for client format = format.withZone(getTimeZone()); try { // parse date retaining the time of the submission dateTime = format.parseDateTime(value); } catch (RuntimeException e) { throw new ConversionException(e); } // apply the server time zone to the parsed value if (zone != null) { dateTime = dateTime.withZoneRetainFields(DateTimeZone.forTimeZone(zone)); } return dateTime.toDate(); } else { try { DateTime date = format.parseDateTime(value); return date.toDate(); } catch (RuntimeException e) { throw new ConversionException(e); } } }
From source file:org.archfirst.common.datetime.DateTimeUtil.java
License:Apache License
public static final LocalDate parseLocalDate(String strDate) { DateTimeFormatter fmt = DateTimeFormat.forPattern(DateTimeUtil.DATE_PATTERN); return fmt.parseDateTime(strDate).toLocalDate(); }
From source file:org.archfirst.common.datetime.DateTimeUtil.java
License:Apache License
public static final DateTime parseDateTime(String strDateTime) { DateTimeFormatter fmt = DateTimeFormat.forPattern(DateTimeUtil.DATE_TIME_PATTERN); return fmt.parseDateTime(strDateTime); }
From source file:org.archfirst.common.datetime.DateTimeUtil.java
License:Apache License
public static final DateTime parseDateTimeSecond(String strDateTime) { DateTimeFormatter fmt = DateTimeFormat.forPattern(DateTimeUtil.DATE_TIME_SEC_PATTERN); return fmt.parseDateTime(strDateTime); }
From source file:org.archfirst.common.datetime.DateTimeUtil.java
License:Apache License
public static final DateTime parseISODateTime(String strDateTime) { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return fmt.parseDateTime(strDateTime); }