CFLib.org – Common Function Library Project

isDateList(nList[, strDelim])

Last updated May 9, 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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson