示例#1
0
  @Test
  public void calendarDateAdd3() {
    CalendarDateAdd dateAdd = new CalendarDateAdd();

    dateAdd.addWorkingWeekDays();
    dateAdd.getExcludePeriods().add(new DayRange(2011, 4, 4, dateAdd.getTimeCalendar()));
    dateAdd.getWorkingHours().add(new HourRangeInDay(new Timepart(8, 30), new Timepart(12)));
    dateAdd.getWorkingHours().add(new HourRangeInDay(new Timepart(13, 30), new Timepart(18)));

    DateTime start = new DateTime(2011, 4, 1, 9, 0);

    assertThat(dateAdd.add(start, Durations.hours(3)))
        .isEqualTo(new DateTime(2011, 4, 1, 13, 30, 0));
    assertThat(dateAdd.add(start, Durations.hours(4)))
        .isEqualTo(new DateTime(2011, 4, 1, 14, 30, 0));
    assertThat(dateAdd.add(start, Durations.hours(8))).isEqualTo(new DateTime(2011, 4, 5, 9, 0, 0));
  }
示例#2
0
  @Test
  public void calendarDateAddSeekBoundaryMode() {
    CalendarDateAdd dateAdd = new CalendarDateAdd();

    dateAdd.addWorkingWeekDays();
    dateAdd.getExcludePeriods().add(new DayRange(2011, 4, 4, dateAdd.getTimeCalendar()));
    dateAdd.getWorkingHours().add(new HourRangeInDay(8, 18));

    DateTime start = new DateTime(2011, 4, 1, 9, 0);

    assertThat(dateAdd.add(start, Durations.hours(29), SeekBoundaryMode.Fill))
        .isEqualTo(new DateTime(2011, 4, 6, 18, 0, 0));
    assertThat(dateAdd.add(start, Durations.hours(29), SeekBoundaryMode.Next))
        .isEqualTo(new DateTime(2011, 4, 7, 8, 0, 0));
    assertThat(dateAdd.add(start, Durations.hours(29)))
        .isEqualTo(new DateTime(2011, 4, 7, 8, 0, 0));
  }