|
From: <be...@us...> - 2006-10-06 16:09:44
|
Revision: 198
http://svn.sourceforge.net/objectlabkit/?rev=198&view=rev
Author: benoitx
Date: 2006-10-06 09:09:38 -0700 (Fri, 06 Oct 2006)
Log Message:
-----------
Add JDK Example, will upload tonight.
Modified Paths:
--------------
trunk/src/site/index.xml
Modified: trunk/src/site/index.xml
===================================================================
--- trunk/src/site/index.xml 2006-09-22 17:51:05 UTC (rev 197)
+++ trunk/src/site/index.xml 2006-10-06 16:09:38 UTC (rev 198)
@@ -117,8 +117,9 @@
</pre></li>
</ol>
</subsection>
+ </section>
- <subsection name="How do I use it?">
+ <section name="How do I use it?">
<p>There are several steps</p>
<ul>
<li>Register holidays in the factory by calling registerHolidays(final String name, Set<Date> holidays)</li>
@@ -128,6 +129,9 @@
the result of your calculations. If the startDate is a non-working day, it may be moved automatically according to the HolidayHandler.</li>
<li>when you call moveByDays(..), moveByBusinessDays(..) the currentDate is moved in the Calculator.</li>
</ul>
+
+ <subsection name="Using Joda-time LocalDate">
+
<pre>
// create or get the Holidays
final Set<LocalDate> holidays = new HashSet<LocalDate>();
@@ -147,8 +151,41 @@
LocalDate newCurrent = cal.moveByDays(4).getCurrentBusinessDate(); // 4 Sept 06 due to weekend!
</pre>
-
+
+ </subsection>
+
+
+ <subsection name="Using JDK Calendar">
+ <pre>
+// create or get the Holidays
+final Set<Calendar> holidays = new HashSet<Calendar>();
+Calendar calendar = Calendar.getInstance();
+calendar.set(Calendar.DAY_OF_MONTH,28);
+calendar.set(Calendar.MONTH,Calendar.AUGUST);
+calendar.set(Calendar.YEAR,2006);
+holidays.add(calendar);
+
+// register the holidays (any calculator with name "UK" asked from now on will receive a reference to this set
+DefaultDateCalculatorFactory.getDefaultInstance().registerHolidays("UK", holidays);
+
+// ask for a LocalDate calculator for "UK" (even if a new set of holidays is registered, this one calculator is not affected
+DateCalculator<Calendar> cal = LocalDateKitCalculatorsFactory.getDefaultInstance().getDateCalculator("UK", HolidayHandlerType.FORWARD);
+Calendar initial = Calendar.getInstance();
+initial.set(Calendar.DAY_OF_MONTH,28);
+initial.set(Calendar.MONTH,Calendar.AUGUST);
+initial.set(Calendar.YEAR,2006);
+
+cal.setStartDate(initial); // this also sets the current business date.
+
+// the startDate stays 28 Aug 06 BUT the currentDate has moved,
+// according to Forward handler to 29 Aug 2006.
+Calendar start = cal.getStartDate(); // 28 Aug 06
+Calendar current = cal.getCurrentBusinessDate(); // 29 Aug 06
+
+Calendar newCurrent = cal.moveByDays(4).getCurrentBusinessDate(); // 4 Sept 06 due to weekend!
+ </pre>
+
</subsection>
</section>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|