List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeParser
public static DateTimeFormatter dateTimeParser()
From source file:org.eol.globi.data.StudyImporterForINaturalist.java
private DateTime parseUTCDateTime(String timeObservedAtUtc) { return ISODateTimeFormat.dateTimeParser().parseDateTime(timeObservedAtUtc).withZone(DateTimeZone.UTC); }
From source file:org.fao.geonet.domain.ISODate.java
License:Open Source License
public static DateTime parseBasicOrFullDateTime(String input1) throws Exception { DateTimeFormatter bd = ISODateTimeFormat.basicDate(); DateTimeFormatter bt = ISODateTimeFormat.basicTime(); DateTimeFormatter bdt = ISODateTimeFormat.basicDateTime(); DateTimeFormatter dtp = ISODateTimeFormat.dateTimeParser(); DateTime idt;//from ww w. j a va2 s. co m Matcher matcher; if (input1.length() == 8 && !input1.startsWith("T")) { idt = bd.parseDateTime(input1); } else if (input1.startsWith("T") && !input1.contains(":")) { idt = bt.parseDateTime(input1); } else if (input1.contains("T") && !input1.contains(":") && !input1.contains("-")) { idt = bdt.parseDateTime(input1); } else if ((matcher = gsYearMonth.matcher(input1)).matches()) { String year = matcher.group(1); String month = matcher.group(2); String minute = "00"; String hour = "00"; String timezone = "Z"; if (matcher.group(4) != null) { minute = matcher.group(5); hour = matcher.group(4); timezone = matcher.group(6); } idt = generateDate(year, month, minute, hour, timezone); } else if ((matcher = gsYear.matcher(input1)).matches()) { String year = matcher.group(1); String month = "01"; String minute = "00"; String hour = "00"; String timezone = "Z"; if (matcher.group(3) != null) { minute = matcher.group(4); hour = matcher.group(3); timezone = matcher.group(5); } idt = generateDate(year, month, minute, hour, timezone); } else if ((matcher = htmlFormat.matcher(input1)).matches()) { // Fri Jan 01 2010 00:00:00 GMT+0100 (CET) String month = matcher.group(2); switch (month) { case "Jan": month = "1"; break; case "Feb": month = "2"; break; case "Mar": month = "3"; break; case "Apr": month = "4"; break; case "May": month = "5"; break; case "Jun": month = "6"; break; case "Jul": month = "7"; break; case "Aug": month = "8"; break; case "Sep": month = "9"; break; case "Oct": month = "10"; break; case "Nov": month = "11"; break; default: month = "12"; break; } String day = matcher.group(3); String year = matcher.group(4); String hour = matcher.group(5); String minute = matcher.group(6); String second = matcher.group(7); String timezone = matcher.group(8); idt = generateDate(year, month, day, second, minute, hour, timezone); } else { idt = dtp.parseDateTime(input1); } return idt; }
From source file:org.fao.geonet.util.JODAISODate.java
License:Open Source License
private static DateTime parseBasicOrFullDateTime(String input1) throws Exception { DateTimeFormatter bd = ISODateTimeFormat.basicDate(); DateTimeFormatter bt = ISODateTimeFormat.basicTime(); DateTimeFormatter bdt = ISODateTimeFormat.basicDateTime(); DateTimeFormatter dtp = ISODateTimeFormat.dateTimeParser(); DateTime idt;//from www.j av a 2 s.c o m if (input1.length() == 8 && !input1.startsWith("T")) { idt = bd.parseDateTime(input1); } else if (input1.startsWith("T") && !input1.contains(":")) { idt = bt.parseDateTime(input1); } else if (input1.contains("T") && !input1.contains(":") && !input1.contains("-")) { idt = bdt.parseDateTime(input1); } else { idt = dtp.parseDateTime(input1); } return idt; }
From source file:org.filteredpush.qc.date.DateUtils.java
License:Apache License
/** * Does eventDate match an ISO date that contains a time (including the instant of * midnight (a time with all zero elements)). * /*www .j a v a 2s.c o m*/ * @param eventDate string to check for an ISO date with a time. * @return true if eventDate is an ISO date that includes a time, or if eventDate is an * ISO date range either the start or end of which contains a time. */ public static boolean containsTime(String eventDate) { boolean result = false; if (!isEmpty(eventDate)) { if (eventDate.endsWith("UTC")) { eventDate = eventDate.replace("UTC", "Z"); } DateTimeParser[] parsers = { ISODateTimeFormat.dateHour().getParser(), ISODateTimeFormat.dateTimeParser().getParser(), ISODateTimeFormat.dateHourMinute().getParser(), ISODateTimeFormat.dateHourMinuteSecond().getParser(), ISODateTimeFormat.dateTime().getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); if (eventDate.matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) { try { LocalDate match = LocalDate.parse(eventDate, formatter); result = true; logger.debug(match); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } if (isRange(eventDate) && eventDate.contains("/") && !result) { String[] bits = eventDate.split("/"); if (bits != null && bits.length > 1) { // does either start or end date contain a time? if (bits[0].matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) { try { LocalDate match = LocalDate.parse(bits[0], formatter); result = true; logger.debug(match); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } if (bits[1].matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) { try { LocalDate match = LocalDate.parse(bits[1], formatter); result = true; logger.debug(match); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } } } } return result; }
From source file:org.filteredpush.qc.date.DateUtils.java
License:Apache License
/** * Attempt to extract a time from an eventDate that could contain time information. * //from ww w .j av a 2 s . c om * @param eventDate dwc:eventDate from which to try to extract a time (in UTC). * @return a string containing a time in UTC or null */ public static String extractZuluTime(String eventDate) { String result = null; if (!isEmpty(eventDate)) { if (eventDate.endsWith("UTC")) { eventDate = eventDate.replace("UTC", "Z"); } DateTimeParser[] parsers = { ISODateTimeFormat.dateHour().getParser(), ISODateTimeFormat.dateTimeParser().getParser(), ISODateTimeFormat.dateHourMinute().getParser(), ISODateTimeFormat.dateHourMinuteSecond().getParser(), ISODateTimeFormat.dateTime().getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); if (eventDate.matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) { try { result = instantToStringTime(Instant.parse(eventDate, formatter)); logger.debug(result); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } if (isRange(eventDate) && eventDate.contains("/") && result != null) { String[] bits = eventDate.split("/"); if (bits != null && bits.length > 1) { // does either start or end date contain a time? if (bits[0].matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) { try { result = instantToStringTime(Instant.parse(bits[0], formatter)); logger.debug(result); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } if (bits[1].matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+") && result != null) { try { result = instantToStringTime(Instant.parse(bits[1], formatter)); logger.debug(result); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } } } } return result; }
From source file:org.finra.herd.rest.DateTimeEditor.java
License:Apache License
@Override public void setAsText(String text) throws IllegalArgumentException { setValue(StringUtils.isBlank(text) ? null : ISODateTimeFormat.dateTimeParser().parseDateTime(text.trim())); }
From source file:org.finra.herd.rest.HerdBaseController.java
License:Apache License
/** * Parses a date-time from the given text, returning a new DateTime. * * @param text the text to parse, may be null * * @return the parsed date-time, or null if text is null *//*from w w w. j a va 2 s.c o m*/ DateTime getDateTime(String text) { return StringUtils.isBlank(text) ? null : ISODateTimeFormat.dateTimeParser().parseDateTime(text.trim()); }
From source file:org.flowable.common.engine.impl.calendar.BusinessCalendarImpl.java
License:Apache License
@Override public Date resolveEndDate(String endDateString) { return ISODateTimeFormat.dateTimeParser() .withZone(DateTimeZone.forTimeZone(clockReader.getCurrentTimeZone())).parseDateTime(endDateString) .toCalendar(null).getTime(); }
From source file:org.flowable.common.engine.impl.calendar.DurationHelper.java
License:Apache License
protected Calendar parseDate(String date) throws Exception { Calendar dateCalendar = null; try {//from www.j a v a 2s . co m dateCalendar = ISODateTimeFormat.dateTimeParser() .withZone(DateTimeZone.forTimeZone(clockReader.getCurrentTimeZone())).parseDateTime(date) .toCalendar(null); } catch (IllegalArgumentException e) { // try to parse a java.util.date to string back to a java.util.date dateCalendar = new GregorianCalendar(); dateCalendar.setTime(DATE_FORMAT.parse(date)); } return dateCalendar; }
From source file:org.fuin.objects4j.common.DateTimeAdapter.java
License:Open Source License
@Override public final DateTime unmarshal(final String str) { if (str == null) { return null; }//from w w w. j a va2 s .c o m return DateTime.parse(str, ISODateTimeFormat.dateTimeParser()); }