SpreadsheetDate.isInRange()

A discussion forum for the JCommon class library.

SpreadsheetDate.isInRange()

Postby wildepete » Thu Sep 04, 2003 6:31 pm

This method has not been implemented (simply returns false), which is causing a problem with the method SerialDateUtilities.countFeb29s().

This means that I cannot calculate an accurate Actual/Actual day count fraction :?

It seems like this would be fairly easy to implement using the compareTo() method, but nobody bothered to.
wildepete
 
Posts: 3
Joined: Tue May 27, 2003 4:31 pm
Location: NYC

Postby david.gilbert » Fri Sep 05, 2003 12:43 am

Here's what I've written (not tested yet!):
Code: Select all
    /**
     * Returns <code>true</code> if this {@link SerialDate} is within the specified range
     * (INCLUSIVE).  The date order of d1 and d2 is not important.
     *
     * @param d1  a boundary date for the range.
     * @param d2  the other boundary date for the range.
     *
     * @return A boolean.
     */
    public boolean isInRange(SerialDate d1, SerialDate d2) {
        return isInRange(d1, d2, SerialDate.INCLUDE_BOTH);
    }

    /**
     * Returns true if this SerialDate is within the specified range (caller
     * specifies whether or not the end-points are included).  The order of d1
     * and d2 is not important.
     *
     * @param d1  one boundary date for the range.
     * @param d2  a second boundary date for the range.
     * @param include  a code that controls whether or not the start and end dates are
     *                 included in the range.
     *
     * @return <code>true</code> if this SerialDate is within the specified range.
     */
    public boolean isInRange(SerialDate d1, SerialDate d2, int include) {
        int s1 = d1.toSerial();
        int s2 = d2.toSerial();
        int start = Math.min(s1, s2);
        int end = Math.max(s1, s2);
       
        int s = toSerial();
        if (include == SerialDate.INCLUDE_BOTH) {
            return (s >= start && s <= end);
        }
        else if (include == SerialDate.INCLUDE_FIRST){
            return (s >= start && s < end);           
        }
        else if (include == SerialDate.INCLUDE_SECOND) {
            return (s > start && s <= end);           
        }
        else {
            return (s > start && s < end);           
        }   
    }
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11655
Joined: Fri Mar 14, 2003 10:29 am


Return to JCommon

Who is online

Users browsing this forum: No registered users and 1 guest