CFLib.org – Common Function Library Project

isDateList(nList[, strDelim])

Last updated May 09, 2009

author

Laura Norris

Version: 0 | Requires: CF5 | Library: DateLib

Description:
Checks if a list consists of valid date values only. Useful if processing a CSV file and a column requires all fields to be dates. Based on isNumbericList().

Return Values:
returns a boolean

Example:

<cfoutput>
<!--- example of a basic date list --->
#isDateList("4/11/2008,12/5/2008,4/15/2009,11/29/2008")#<br>
<!--- example of a list with a pipe ('|') delimiter --->
#isDateList("4/11/2008|12/5/2008|4/15/2009|11/29/2008", "|" )#<br>
<!--- examples of an invalid date lists    --->
#isDateList("4/11/2008,12/34/2008,4/15/2009,11/29/2008")#<br>
#isDateList("4/11/2008,12/5/2008,4/15/2009,a")#<br>
</cfoutput>

Parameters:

Name Description Required
nList List of dates Yes
strDelim list delimiter No

Full UDF Source:

/**
 * Checks if a list consists of date values only.
 * 
 * @param nList      List of dates (Required)
 * @param strDelim      list delimiter (Optional)
 * @return returns a boolean 
 * @author Laura Norris (lnorris@tiffinweb.com) 
 * @version 0, May 9, 2009 
 */
function isDateList(nList) {
    var intIndex    = 0;
    var aryN        = arrayNew(1);
    var strDelim    = ",";

    /*    default list delimiter to a comma unless otherwise specified            */
    if (arrayLen(arguments) gte 2){
        strDelim    = arguments[2];
    }
  
    /*    faster to work with arrays vs lists                                        */
    aryN        = listToArray(nlist,strDelim);
    
    for (intIndex=1;intIndex LTE arrayLen(aryN);intIndex=incrementValue(intIndex)) {
        if (NOT isDate(aryN[intIndex])) {
            /*    hit a non-date list element, send the no-go back                */
            return false;
        }
    }
    /*    made it through the list at this point, send the ok back                */    
    return true;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson