public BusinessCalendarImpl(Properties configuration, SessionClock clock) { this.businessCalendarConfiguration = configuration; this.clock = clock; init(); }
@Override public void internalSchedule(TimerJobInstance timerJobInstance) { this.delegate.internalSchedule(timerJobInstance); }
@Test public void testCalculateDaysPassingOverHolidayAtYearEndWithWildcards() { Properties config = new Properties(); config.setProperty(BusinessCalendarImpl.HOLIDAYS, "*-12-31:*-01-01"); String expectedDate = "2013-01-02 09:15"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime("2012-12-28 16:45").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("2d30m"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testCalculateDays() { Properties config = new Properties(); String expectedDate = "2012-05-14 09:00"; SessionPseudoClock clock = new StaticPseudoClock(parseToDate("2012-05-04").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("6d"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testSingleHolidayWithinGivenTime() { final Properties props = new Properties(); props.put(BusinessCalendarImpl.HOLIDAYS, "2015-01-13"); String expectedDate = "2015-01-15 11:38"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTimeAndMillis("2015-01-08 11:38:30.198").getTime()); BusinessCalendarImpl businessCalendarImpl = new BusinessCalendarImpl(props, clock); Date result = businessCalendarImpl.calculateBusinessTimeAsDate("4d"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test(expected = IllegalArgumentException.class) public void testMissingConfigurationDualArgConstructor() { SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime("2012-05-04 13:45").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(null, clock); }
public JobHandle buildJobHandleForContext(NamedJobContext ctx) { return this.schedulerService.buildJobHandleForContext(ctx); }
@Test public void testCalculateMinutesPassingWeekend() { Properties config = new Properties(); String currentDate = "2018-05-06 13:51:33"; String duration = "10m"; String expectedDate = "2018-05-07 09:10:00"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime(currentDate).getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate(duration); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm:ss", result)); }
@Test public void testCalculateDaysHoursMinutes() { Properties config = new Properties(); String expectedDate = "2012-05-14 14:20"; SessionPseudoClock clock = new StaticPseudoClock(parseToDate("2012-05-04").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("6d4h80m"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testCalculateMillisecondsAsDefault() { Properties config = new Properties(); String expectedDate = "2012-05-04 16:45:10.000"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTimeAndMillis("2012-05-04 16:45:00.000").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("10000"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm:ss.SSS", result)); }
public BusinessCalendarImpl(Properties configuration) { this.businessCalendarConfiguration = configuration; init(); }
@Test public void testCalculateISOHours() { Properties config = new Properties(); String expectedDate = "2012-05-04 16:45"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime("2012-05-04 13:45").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("PT3H"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testCalculateDaysStartingInWeekend() { Properties config = new Properties(); String expectedDate = "2012-05-09 09:00"; SessionPseudoClock clock = new StaticPseudoClock(parseToDate("2012-05-05").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("2d"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testCalculateTimeDaysHoursMinutesSingleDayHolidaysInMiddleOfWeek() { Properties config = new Properties(); config.setProperty(BusinessCalendarImpl.HOLIDAYS, "2012-05-09"); String expectedDate = "2012-05-10 15:30"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime("2012-05-08 11:10").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("1d4h20m"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testCalculateTimeDaysHoursMinutesHolidays() { Properties config = new Properties(); config.setProperty(BusinessCalendarImpl.HOLIDAYS, "2012-05-10:2012-05-19"); String expectedDate = "2012-05-21 14:20"; SessionPseudoClock clock = new StaticPseudoClock(parseToDate("2012-05-04").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("6d4h80m"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testCalculateHoursPassingOverWeekend() { Properties config = new Properties(); String expectedDate = "2012-05-07 12:45"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime("2012-05-04 13:45").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("7h"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testCalculateMinutesPassingAfterHour() { Properties config = new Properties(); String currentDate = "2018-05-02 19:51:33"; String expectedDate = "2018-05-03 09:01:00"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime(currentDate).getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("1m"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm:ss", result)); }
@Test public void testCalculateDaysPassingOverHolidayAtYearEnd() { Properties config = new Properties(); config.setProperty(BusinessCalendarImpl.HOLIDAYS, "2012-12-31:2013-01-01"); String expectedDate = "2013-01-04 09:15"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime("2012-12-28 16:45").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("2d30m"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }
@Test public void testCalculateDaysCustomWorkingDays() { Properties config = new Properties(); config.setProperty(BusinessCalendarImpl.DAYS_PER_WEEK, "4"); config.setProperty(BusinessCalendarImpl.WEEKEND_DAYS, Calendar.FRIDAY + ","+Calendar.SATURDAY + "," +Calendar.SUNDAY); String expectedDate = "2012-05-15 14:30"; SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTime("2012-05-03 14:30").getTime()); BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock); Date result = businessCal.calculateBusinessTimeAsDate("6d"); assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result)); }