List of usage examples for org.joda.time.format DateTimeFormatter parseLocalDateTime
public LocalDateTime parseLocalDateTime(String text)
From source file:me.vertretungsplan.parser.ParserUtils.java
License:Mozilla Public License
static LocalDateTime parseDateTime(String string) { if (string == null) return null; reinitIfNeeded();/* ww w . j av a 2 s. c o m*/ string = string.replace("Stand:", "").replace("Import:", "").trim(); int i = 0; for (DateTimeFormatter f : dateTimeFormatters) { try { LocalDateTime dt = f.parseLocalDateTime(string); if (dateTimeFormats[i].contains("yyyy")) { return dt; } else { Duration currentYearDifference = abs(new Duration(DateTime.now(), dt.toDateTime())); Duration lastYearDifference = abs(new Duration(DateTime.now(), dt.minusYears(1).toDateTime())); Duration nextYearDifference = abs(new Duration(DateTime.now(), dt.plusYears(1).toDateTime())); if (lastYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateTimeFormats[i]).withLocale(Locale.GERMAN) .withDefaultYear(f.getDefaultYear() - 1).parseLocalDateTime(string); } else if (nextYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateTimeFormats[i]).withLocale(Locale.GERMAN) .withDefaultYear(f.getDefaultYear() + 1).parseLocalDateTime(string); } else { return dt; } } } catch (IllegalArgumentException e) { // Does not match this format, try the next one } i++; } // Does not match any known format :( return null; }
From source file:name.martingeisse.admin.application.converter.LocalDateTimeConverter.java
License:Open Source License
@Override public LocalDateTime convertToObject(String value, Locale locale) { try {//from w ww . ja va 2 s. co m DateTimeFormatter formatter = getFormatter(locale); return formatter.parseLocalDateTime(value); } catch (Exception e) { throw new ConversionException(e); } }
From source file:name.martingeisse.sql.config.CustomMysqlLocalDateTimeType.java
License:Open Source License
@Override protected LocalDateTime parse(final DateTimeFormatter formatter, final String value) { return formatter.parseLocalDateTime(value); }
From source file:org.apache.isis.applib.fixturescripts.clock.ClockFixture.java
License:Apache License
private static LocalDateTime parseAsLocalDateTime(String dateStr) { for (DateTimeFormatter formatter : new DateTimeFormatter[] { DateTimeFormat.fullDateTime(), DateTimeFormat.mediumDateTime(), DateTimeFormat.shortDateTime(), DateTimeFormat.forPattern("yyyyMMddhhmmss"), DateTimeFormat.forPattern("yyyyMMddhhmm") }) { try {/*w ww. j a v a 2s . c o m*/ return formatter.parseLocalDateTime(dateStr); } catch (Exception e) { // continue; } } return null; }
From source file:org.apache.isis.core.metamodel.facets.value.datetimejodalocal.JodaLocalDateTimeUtil.java
License:Apache License
private static LocalDateTime parseDateTime(String dateStr, Iterable<DateTimeFormatter> formatters) { for (DateTimeFormatter formatter : formatters) { try {//w w w . ja v a 2 s . com return formatter.parseLocalDateTime(dateStr); } catch (final IllegalArgumentException e) { // continue to next } } throw new TextEntryParseException("Not recognised as a date: " + dateStr); }
From source file:org.openmastery.publisher.resources.EventResource.java
License:Open Source License
@GET @Path(ResourcePaths.EVENT_BATCH_PATH) public List<NewBatchEvent> getLatestEvents(@QueryParam("afterDate") String afterDate, @QueryParam("limit") Integer limit) { Long userId = invocationContext.getUserId(); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd_HHmmss"); LocalDateTime jodaAfterDate = formatter.parseLocalDateTime(afterDate); return eventService.getLatestEvents(userId, jodaAfterDate, limit); }