@Test public void basicPeriodBarriersCrossed() { RollingCalendar rc = new RollingCalendar(dailyPattern, TimeZone.getTimeZone("CET"), Locale.US); long start = 1485456418969L; long end = start+CoreConstants.MILLIS_IN_ONE_DAY; assertEquals(1, rc.periodBarriersCrossed(start, end)); }
public long periodBarriersCrossed(long start, long end) { if (start > end) throw new IllegalArgumentException("Start cannot come before end"); long startFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(start, getTimeZone()); long endFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(end, getTimeZone()); long diff = endFloored - startFloored; switch (periodicityType) { case TOP_OF_MILLISECOND: return diff; case TOP_OF_SECOND: return diff / MILLIS_IN_ONE_SECOND; case TOP_OF_MINUTE: return diff / MILLIS_IN_ONE_MINUTE; case TOP_OF_HOUR: return diff / MILLIS_IN_ONE_HOUR; case TOP_OF_DAY: return diff / MILLIS_IN_ONE_DAY; case TOP_OF_WEEK: return diff / MILLIS_IN_ONE_WEEK; case TOP_OF_MONTH: return diffInMonths(start, end); default: throw new IllegalStateException("Unknown periodicity type."); } }
RollingCalendar extends GregorianCalendar { public long periodBarriersCrossed(long start, long end) { if (start > end) throw new IllegalArgumentException("Start cannot come before end"); long startFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(start, getTimeZone()); long endFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(end, getTimeZone()); long diff = endFloored - startFloored; switch (periodicityType) { case TOP_OF_MILLISECOND: return diff; case TOP_OF_SECOND: return diff / MILLIS_IN_ONE_SECOND; case TOP_OF_MINUTE: return diff / MILLIS_IN_ONE_MINUTE; case TOP_OF_HOUR: return diff / MILLIS_IN_ONE_HOUR; case TOP_OF_DAY: return diff / MILLIS_IN_ONE_DAY; case TOP_OF_WEEK: return diff / MILLIS_IN_ONE_WEEK; case TOP_OF_MONTH: return diffInMonths(start, end); default: throw new IllegalStateException("Unknown periodicity type."); } } }
RollingCalendar extends GregorianCalendar { public long periodBarriersCrossed(long start, long end) { if (start > end) throw new IllegalArgumentException("Start cannot come before end"); long startFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(start, getTimeZone()); long endFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(end, getTimeZone()); long diff = endFloored - startFloored; switch (periodicityType) { case TOP_OF_MILLISECOND: return diff; case TOP_OF_SECOND: return diff / MILLIS_IN_ONE_SECOND; case TOP_OF_MINUTE: return diff / MILLIS_IN_ONE_MINUTE; case TOP_OF_HOUR: return diff / MILLIS_IN_ONE_HOUR; case TOP_OF_DAY: return diff / MILLIS_IN_ONE_DAY; case TOP_OF_WEEK: return diff / MILLIS_IN_ONE_WEEK; case TOP_OF_MONTH: return diffInMonths(start, end); default: throw new IllegalStateException("Unknown periodicity type."); } } RollingCalendar(String datePattern);  RollingCalendar(String datePattern, TimeZone tz, Locale locale); }
RollingCalendar extends GregorianCalendar { public long periodBarriersCrossed(long start, long end) { if (start > end) throw new IllegalArgumentException("Start cannot come before end"); long startFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(start, getTimeZone()); long endFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(end, getTimeZone()); long diff = endFloored - startFloored; switch (periodicityType) { case TOP_OF_MILLISECOND: return diff; case TOP_OF_SECOND: return diff / MILLIS_IN_ONE_SECOND; case TOP_OF_MINUTE: return diff / MILLIS_IN_ONE_MINUTE; case TOP_OF_HOUR: return diff / MILLIS_IN_ONE_HOUR; case TOP_OF_DAY: return diff / MILLIS_IN_ONE_DAY; case TOP_OF_WEEK: return diff / MILLIS_IN_ONE_WEEK; case TOP_OF_MONTH: return diffInMonths(start, end); default: throw new IllegalStateException("Unknown periodicity type."); } } RollingCalendar(String datePattern);  RollingCalendar(String datePattern, TimeZone tz, Locale locale); PeriodicityType getPeriodicityType(); PeriodicityType computePeriodicityType(); boolean isCollisionFree(); void printPeriodicity(ContextAwareBase cab); long periodBarriersCrossed(long start, long end); static int diffInMonths(long startTime, long endTime); Date getEndOfNextNthPeriod(Date now, int periods); Date getNextTriggeringDate(Date now); long getStartOfCurrentPeriodWithGMTOffsetCorrection(long now, TimeZone timezone); }
RollingCalendar extends GregorianCalendar { public long periodBarriersCrossed(long start, long end) { if (start > end) throw new IllegalArgumentException("Start cannot come before end"); long startFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(start, getTimeZone()); long endFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(end, getTimeZone()); long diff = endFloored - startFloored; switch (periodicityType) { case TOP_OF_MILLISECOND: return diff; case TOP_OF_SECOND: return diff / MILLIS_IN_ONE_SECOND; case TOP_OF_MINUTE: return diff / MILLIS_IN_ONE_MINUTE; case TOP_OF_HOUR: return diff / MILLIS_IN_ONE_HOUR; case TOP_OF_DAY: return diff / MILLIS_IN_ONE_DAY; case TOP_OF_WEEK: return diff / MILLIS_IN_ONE_WEEK; case TOP_OF_MONTH: return diffInMonths(start, end); default: throw new IllegalStateException("Unknown periodicity type."); } } RollingCalendar(String datePattern);  RollingCalendar(String datePattern, TimeZone tz, Locale locale); PeriodicityType getPeriodicityType(); PeriodicityType computePeriodicityType(); boolean isCollisionFree(); void printPeriodicity(ContextAwareBase cab); long periodBarriersCrossed(long start, long end); static int diffInMonths(long startTime, long endTime); Date getEndOfNextNthPeriod(Date now, int periods); Date getNextTriggeringDate(Date now); long getStartOfCurrentPeriodWithGMTOffsetCorrection(long now, TimeZone timezone);  }