SpreadsheetDate.isInRange()

A discussion forum for the JCommon class library.
Locked
wildepete
Posts: 3
Joined: Tue May 27, 2003 4:31 pm
Location: NYC
Contact:

SpreadsheetDate.isInRange()

Post by 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.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by 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: Support JFree via the Github sponsorship program

Locked