@Test public void testWeeksBetween() throws Exception { CoveringInfo weeks; weeks = getWeeklyCoveringInfo(DATE_FMT.parse("2013-May-26"), DATE_FMT.parse("2013-Jun-2")); assertEquals(weeks, new CoveringInfo(1, true), "2013-May-26 to 2013-Jun-2"); weeks = getWeeklyCoveringInfo(DATE_FMT.parse("2013-May-27"), DATE_FMT.parse("2013-Jun-3")); assertEquals(weeks, new CoveringInfo(0, false), "2013-May-26 to 2013-Jun-2"); weeks = getWeeklyCoveringInfo(DATE_FMT.parse("2013-May-27"), DATE_FMT.parse("2013-Jun-9")); assertEquals(weeks, new CoveringInfo(1, false), "2013-May-26 to 2013-Jun-2"); weeks = getWeeklyCoveringInfo(DATE_FMT.parse("2013-May-27"), DATE_FMT.parse("2013-Jun-1")); assertEquals(weeks, new CoveringInfo(0, false), "2013-May-27 to 2013-Jun-1"); weeks = getWeeklyCoveringInfo(DATE_FMT.parse("2013-May-25"), DATE_FMT.parse("2013-Jun-2")); assertEquals(weeks, new CoveringInfo(1, false), "2013-May-25 to 2013-Jun-1"); weeks = getWeeklyCoveringInfo(DATE_FMT.parse("2013-May-26"), DATE_FMT.parse("2013-Jun-9")); assertEquals(weeks, new CoveringInfo(2, true), "2013-May-26 to 2013-Jun-8"); weeks = getWeeklyCoveringInfo(DATE_FMT.parse("2013-May-26"), DATE_FMT.parse("2013-Jun-10")); assertEquals(weeks, new CoveringInfo(2, false), "2013-May-26 to 2013-Jun-10"); weeks = getWeeklyCoveringInfo(DATE_FMT.parse("2015-Dec-27"), DATE_FMT.parse("2016-Jan-03")); assertEquals(weeks, new CoveringInfo(1, true), "2015-Dec-27 to 2016-Jan-03"); }
public static CoveringInfo getWeeklyCoveringInfo(Date from, Date to) { int dayDiff = 0; Date tmpFrom = from; while (tmpFrom.before(to)) { tmpFrom = DateUtils.addDays(tmpFrom, 1); dayDiff++; } if (dayDiff < 7) { return new CoveringInfo(0, false); } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromDay = cal.get(Calendar.DAY_OF_WEEK); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date fromWeekStartDate = cal.getTime(); boolean coverable = dayDiff % 7 == 0; if (fromWeekStartDate.before(from)) { dayDiff -= (cal.getActualMaximum(Calendar.DAY_OF_WEEK) - (fromDay - Calendar.SUNDAY)); coverable = false; } return new CoveringInfo(dayDiff / 7, coverable); }
DateUtil { public static CoveringInfo getWeeklyCoveringInfo(Date from, Date to) { int dayDiff = 0; Date tmpFrom = from; while (tmpFrom.before(to)) { tmpFrom = DateUtils.addDays(tmpFrom, 1); dayDiff++; } if (dayDiff < 7) { return new CoveringInfo(0, false); } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromDay = cal.get(Calendar.DAY_OF_WEEK); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date fromWeekStartDate = cal.getTime(); boolean coverable = dayDiff % 7 == 0; if (fromWeekStartDate.before(from)) { dayDiff -= (cal.getActualMaximum(Calendar.DAY_OF_WEEK) - (fromDay - Calendar.SUNDAY)); coverable = false; } return new CoveringInfo(dayDiff / 7, coverable); } }
DateUtil { public static CoveringInfo getWeeklyCoveringInfo(Date from, Date to) { int dayDiff = 0; Date tmpFrom = from; while (tmpFrom.before(to)) { tmpFrom = DateUtils.addDays(tmpFrom, 1); dayDiff++; } if (dayDiff < 7) { return new CoveringInfo(0, false); } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromDay = cal.get(Calendar.DAY_OF_WEEK); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date fromWeekStartDate = cal.getTime(); boolean coverable = dayDiff % 7 == 0; if (fromWeekStartDate.before(from)) { dayDiff -= (cal.getActualMaximum(Calendar.DAY_OF_WEEK) - (fromDay - Calendar.SUNDAY)); coverable = false; } return new CoveringInfo(dayDiff / 7, coverable); } private  DateUtil(); }
DateUtil { public static CoveringInfo getWeeklyCoveringInfo(Date from, Date to) { int dayDiff = 0; Date tmpFrom = from; while (tmpFrom.before(to)) { tmpFrom = DateUtils.addDays(tmpFrom, 1); dayDiff++; } if (dayDiff < 7) { return new CoveringInfo(0, false); } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromDay = cal.get(Calendar.DAY_OF_WEEK); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date fromWeekStartDate = cal.getTime(); boolean coverable = dayDiff % 7 == 0; if (fromWeekStartDate.before(from)) { dayDiff -= (cal.getActualMaximum(Calendar.DAY_OF_WEEK) - (fromDay - Calendar.SUNDAY)); coverable = false; } return new CoveringInfo(dayDiff / 7, coverable); } private  DateUtil(); static String getAbsDateFormatString(String str); static Date resolveDate(String str, Date now); static String relativeToAbsolute(String relative); static String relativeToAbsolute(String relative, Date now); static String formatAbsDate(Date date); static Date resolveAbsoluteDate(final String str); static Date resolveRelativeDate(String str, Date now); static Date getCeilDate(Date date, UpdatePeriod interval); static Date getFloorDate(Date date, UpdatePeriod interval); static CoveringInfo getMonthlyCoveringInfo(Date from, Date to); static CoveringInfo getQuarterlyCoveringInfo(Date from, Date to); static CoveringInfo getYearlyCoveringInfo(Date from, Date to); static CoveringInfo getWeeklyCoveringInfo(Date from, Date to); static int getTimeDiff(Date fromDate, Date toDate, UpdatePeriod updatePeriod); }
DateUtil { public static CoveringInfo getWeeklyCoveringInfo(Date from, Date to) { int dayDiff = 0; Date tmpFrom = from; while (tmpFrom.before(to)) { tmpFrom = DateUtils.addDays(tmpFrom, 1); dayDiff++; } if (dayDiff < 7) { return new CoveringInfo(0, false); } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromDay = cal.get(Calendar.DAY_OF_WEEK); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date fromWeekStartDate = cal.getTime(); boolean coverable = dayDiff % 7 == 0; if (fromWeekStartDate.before(from)) { dayDiff -= (cal.getActualMaximum(Calendar.DAY_OF_WEEK) - (fromDay - Calendar.SUNDAY)); coverable = false; } return new CoveringInfo(dayDiff / 7, coverable); } private  DateUtil(); static String getAbsDateFormatString(String str); static Date resolveDate(String str, Date now); static String relativeToAbsolute(String relative); static String relativeToAbsolute(String relative, Date now); static String formatAbsDate(Date date); static Date resolveAbsoluteDate(final String str); static Date resolveRelativeDate(String str, Date now); static Date getCeilDate(Date date, UpdatePeriod interval); static Date getFloorDate(Date date, UpdatePeriod interval); static CoveringInfo getMonthlyCoveringInfo(Date from, Date to); static CoveringInfo getQuarterlyCoveringInfo(Date from, Date to); static CoveringInfo getYearlyCoveringInfo(Date from, Date to); static CoveringInfo getWeeklyCoveringInfo(Date from, Date to); static int getTimeDiff(Date fromDate, Date toDate, UpdatePeriod updatePeriod); static final String UNIT; static final Date MAX_DATE; static final Date MIN_DATE; static final String GRANULARITY; static final String RELATIVE; static final Pattern P_RELATIVE; static final String WSPACE; static final String OPTIONAL_WSPACE; static final String SIGNAGE; static final Pattern P_SIGNAGE; static final String QUANTITY; static final Pattern P_QUANTITY; static final Pattern P_UNIT; static final String RELDATE_VALIDATOR_STR; static final Pattern RELDATE_VALIDATOR; static final Pattern TIMESTAMP_VALIDATOR; static final String YEAR_FMT; static final String MONTH_FMT; static final String DAY_FMT; static final String HOUR_FMT; static final String MINUTE_FMT; static final String SECOND_FMT; static final String MILLISECOND_FMT; static final String ABSDATE_FMT; static final String HIVE_QUERY_DATE_FMT; static final ThreadLocal<DateFormat> ABSDATE_PARSER; static final ThreadLocal<DateFormat> HIVE_QUERY_DATE_PARSER; }