@Test public void testParseInterval() { DateTime now = new DateTime(); DateTime beg = now.minusMonths(2).withTimeAtStartOfDay(); DateTime end = now.plusMonths(2).withTimeAtStartOfDay(); String begStr = beg.toString(Dates.yMdFormat); String endStr = end.toString(Dates.yMdFormat); String invStr = "DEADBEEF"; Interval nowInterval = new Interval(now, now.plusSeconds(30)); assertTrue(nowInterval.contains(Dates.parseInterval(null, null))); assertEquals(new Interval(end, end), Dates.parseInterval(null, endStr)); assertEquals(new Interval(beg, beg), Dates.parseInterval(begStr, null)); assertEquals(new Interval(beg, end), Dates.parseInterval(begStr, endStr)); assertEquals(new Interval(beg, beg), Dates.parseInterval(endStr, begStr)); assertTrue(nowInterval.contains(Dates.parseInterval(invStr, invStr))); assertEquals(new Interval(end, end), Dates.parseInterval(invStr, endStr)); assertEquals(new Interval(beg, beg), Dates.parseInterval(begStr, invStr)); assertTrue(nowInterval.contains(Dates.parseInterval(invStr, null))); assertTrue(nowInterval.contains(Dates.parseInterval(null, invStr))); }
public static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format) { DateTime beg = null; DateTime end = null; boolean begFailed = false; boolean endFailed = false; try { beg = format.parseDateTime(begStr); } catch (Exception e) { begFailed = true; } try { end = format.parseDateTime(endStr); } catch (Exception e) { endFailed = true; } if (begFailed && endFailed) { end = beg = new DateTime(); } else if (begFailed) { beg = end; } else if (endFailed) { end = beg; } if (beg.isAfter(end)) { beg = end; } return new Interval(beg, end); }
Dates { public static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format) { DateTime beg = null; DateTime end = null; boolean begFailed = false; boolean endFailed = false; try { beg = format.parseDateTime(begStr); } catch (Exception e) { begFailed = true; } try { end = format.parseDateTime(endStr); } catch (Exception e) { endFailed = true; } if (begFailed && endFailed) { end = beg = new DateTime(); } else if (begFailed) { beg = end; } else if (endFailed) { end = beg; } if (beg.isAfter(end)) { beg = end; } return new Interval(beg, end); } }
Dates { public static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format) { DateTime beg = null; DateTime end = null; boolean begFailed = false; boolean endFailed = false; try { beg = format.parseDateTime(begStr); } catch (Exception e) { begFailed = true; } try { end = format.parseDateTime(endStr); } catch (Exception e) { endFailed = true; } if (begFailed && endFailed) { end = beg = new DateTime(); } else if (begFailed) { beg = end; } else if (endFailed) { end = beg; } if (beg.isAfter(end)) { beg = end; } return new Interval(beg, end); }  }
Dates { public static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format) { DateTime beg = null; DateTime end = null; boolean begFailed = false; boolean endFailed = false; try { beg = format.parseDateTime(begStr); } catch (Exception e) { begFailed = true; } try { end = format.parseDateTime(endStr); } catch (Exception e) { endFailed = true; } if (begFailed && endFailed) { end = beg = new DateTime(); } else if (begFailed) { beg = end; } else if (endFailed) { end = beg; } if (beg.isAfter(end)) { beg = end; } return new Interval(beg, end); }  static Period period(int length, PeriodType type); static Interval truncateInterval(Interval interval, int limit, PeriodType type); static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format); static Interval parseInterval(String begStr, String endStr); static Date endOfDay(Date d); static Date begOfDay(Date d); static Iterable<DateTime> iterableInterval(Interval interval, DTimeUnit type); static Iterator<DateTime> intervalIterator(Interval interval, DTimeUnit type); }
Dates { public static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format) { DateTime beg = null; DateTime end = null; boolean begFailed = false; boolean endFailed = false; try { beg = format.parseDateTime(begStr); } catch (Exception e) { begFailed = true; } try { end = format.parseDateTime(endStr); } catch (Exception e) { endFailed = true; } if (begFailed && endFailed) { end = beg = new DateTime(); } else if (begFailed) { beg = end; } else if (endFailed) { end = beg; } if (beg.isAfter(end)) { beg = end; } return new Interval(beg, end); }  static Period period(int length, PeriodType type); static Interval truncateInterval(Interval interval, int limit, PeriodType type); static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format); static Interval parseInterval(String begStr, String endStr); static Date endOfDay(Date d); static Date begOfDay(Date d); static Iterable<DateTime> iterableInterval(Interval interval, DTimeUnit type); static Iterator<DateTime> intervalIterator(Interval interval, DTimeUnit type); static final DateTimeFormatter rfc1123; static final DateTimeFormatter yMdFormat; static final DateTimeFormatter yMdHFormat; }