Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You may want to consider using <a href="http://objectlabkit.sourceforge.net" rel="noreferrer">ObjectLab Kit</a> to do the heavy lifting for you.</p> <p>Assuming the requirement is simply to return the next business day when the computed date falls on a non-business day:</p> <pre><code>package bizdays.example; import java.util.HashSet; import net.objectlab.kit.datecalc.common.DateCalculator; import net.objectlab.kit.datecalc.common.DefaultHolidayCalendar; import net.objectlab.kit.datecalc.common.HolidayHandlerType; import net.objectlab.kit.datecalc.joda.LocalDateKitCalculatorsFactory; import static org.junit.Assert.assertThat; import org.junit.Before; import org.junit.Test; import static org.hamcrest.Matchers.equalTo; import org.joda.time.LocalDate; public class BizDayTest { private DateCalculator&lt;LocalDate&gt; dateCalculator; private final LocalDate startDate = new LocalDate(2009, 12, 23); @Before public void setUp() { HashSet&lt;LocalDate&gt; holidays = new HashSet&lt;LocalDate&gt;(); holidays.add(new LocalDate(2009, 12, 25)); // Friday DefaultHolidayCalendar&lt;LocalDate&gt; holidayCalendar = new DefaultHolidayCalendar&lt;LocalDate&gt;(holidays); LocalDateKitCalculatorsFactory.getDefaultInstance() .registerHolidays("example", holidayCalendar); dateCalculator = LocalDateKitCalculatorsFactory.getDefaultInstance() .getDateCalculator("example", HolidayHandlerType.FORWARD); dateCalculator.setStartDate(startDate); } @Test public void should_not_change_calendar_start_date_even_after_moving() { assertThat( dateCalculator.moveByBusinessDays(6).getStartDate(), equalTo(startDate)); } @Test public void moveByBusinessDays_will_return_24_dec_2009_as_next_business_day() { assertThat( dateCalculator.moveByBusinessDays(1).getCurrentBusinessDate(), equalTo(new LocalDate(2009, 12, 24))); } @Test public void moveByBusinessDays_will_return_28_dec_2009_as_two_business_days_later() { assertThat( dateCalculator.moveByBusinessDays(2).getCurrentBusinessDate(), equalTo(new LocalDate(2009, 12, 28))); } @Test public void moveByDays_will_also_return_28_dec_2009_as_two_business_days_later() { assertThat( dateCalculator.moveByDays(2).getCurrentBusinessDate(), equalTo(new LocalDate(2009, 12, 28))); } @Test public void moveByBusinessDays_will_exclude_25_26_and_27_dec_when_computing_business_days() { assertThat( dateCalculator.moveByBusinessDays(5).getCurrentBusinessDate(), equalTo(new LocalDate(2009, 12, 31))); } @Test public void moveByDays_will_include_25_26_and_27_dec_when_computing_business_days() { assertThat( dateCalculator.moveByDays(5).getCurrentBusinessDate(), equalTo(new LocalDate(2009, 12, 28))); } } </code></pre> <p>The library defaults the working week to be from Monday to Friday, but you can change the defaults by supplying a custom <a href="http://objectlabkit.sourceforge.net/apidocs/net/objectlab/kit/datecalc/common/WorkingWeek.html" rel="noreferrer">WorkingWeek</a> to <a href="http://objectlabkit.sourceforge.net/apidocs/net/objectlab/kit/datecalc/common/DateCalculator.html" rel="noreferrer">DateCalculator</a>'s <a href="http://objectlabkit.sourceforge.net/apidocs/net/objectlab/kit/datecalc/common/DateCalculator.html#setWorkingWeek%28net.objectlab.kit.datecalc.common.WorkingWeek%29" rel="noreferrer">setWorkingWeek()</a>.</p> <p>As shown in the last two examples, moveByDays() includes the weekends when moving the days, whereas moveByBusinessDays() excludes weekends.</p> <p>The library also allows you to use java.util.Calendar instead of <a href="http://joda-time.sourceforge.net" rel="noreferrer">Joda Time</a>'s LocalDate. The example uses <a href="http://joda-time.sourceforge.net" rel="noreferrer">Joda Time</a> library because it is the preferred library to use when handling dates in Java.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload