这是我最终使用的,并且足够灵活,可以在将来进行修改,我可能仍会将其转换为带有 GUI 的数据库驱动系统,以添加未来的日期,但就目前而言,这很好用。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" />
<script>
$(document).ready(function(){
$( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true
});
});
</script>
</head>
<body>
<cfoutput>
<form action="#cgi.SCRIPT_NAME#" method="post">
Start Date: <input type="text" name="StartDate" class="datepicker" /> (mm-dd-yyyy)<br />
End Date: <input type="text" name="EndDate" class="datepicker" /> (mm-dd-yyyy) <br />
<input type="submit" value="Save Appointment" />
</form>
<cfif structkeyexists(form,'startDate')>
<cfdump var="#form#" expand="no">
<hr />
<cfscript>
/**
* Returns the day of the month(1-31) of an Nth Occurrence of a day (1-sunday,2-monday etc.)in a given month. *
* @param NthOccurrence A number representing the nth occurrence.1-5.
* @param TheDayOfWeek A number representing the day of the week (1=Sunday, 2=Monday, etc.).
* @param TheMonth A number representing the Month (1=January, 2=February, etc.).
* @param TheYear The year.
* @return Returns a numeric value.
* @author Ken McCafferty (mccjdk@yahoo.com)
* @version 1, August 28, 2001
*/
function GetNthOccOfDayInMonth(NthOccurrence,TheDayOfWeek,TheMonth,TheYear)
{
Var TheDayInMonth=0;
if(TheDayOfWeek lt DayOfWeek(CreateDate(TheYear,TheMonth,1))){
TheDayInMonth= 1 + NthOccurrence*7 + (TheDayOfWeek - DayOfWeek(CreateDate(TheYear,TheMonth,1))) MOD 7;
}
else {
TheDayInMonth= 1 + (NthOccurrence-1)*7 + (TheDayOfWeek - DayOfWeek(CreateDate(TheYear,TheMonth,1))) MOD 7;
}
//If the result is greater than days in month or less than 1, return -1
if(TheDayInMonth gt DaysInMonth(CreateDate(TheYear,TheMonth,1)) OR TheDayInMonth lt 1){
return -1;
}
else {
return TheDayInMonth;
}
}
/**
* Returns the date for Easter in a given year.
* Minor edits by Rob Brooks-Bilson (rbils@amkor.com).
*
* @param TheYear The year to get Easter for.
* @return Returns a date object.
* @author Ken McCafferty (rbils@amkor.commccjdk@yahoo.com)
* @version 1, September 4, 2001
*/
function GetEaster() {
Var TheYear=iif(arraylen(arguments) gt 0,"arguments[1]", "Year(Now())");
Var century = Int(TheYear/100);
Var G = TheYear MOD 19;
Var K = Int((century - 17)/25);
Var I = (century - Int(century/4) - Int((century - K)/3) + 19*G + 15) MOD 30;
Var H = I - Int((I/28))*(1 - Int((I/28))*Int((29/(I + 1)))*Int(((21 - G)/11)));
Var J = (TheYear + Int(TheYear/4) + H + 2 - century + Int(century/4)) MOD 7;
Var L = H - J;
Var EasterMonth = 3 + Int((L + 40)/44);
Var EasterDay = L + 28 - 31*Int((EasterMonth/4));
return CreateDate(TheYear,EasterMonth,EasterDay);
}
function LastDayOfMonth(strMonth) {
var strYear=Year(Now());
if (ArrayLen(Arguments) gt 1)
strYear=Arguments[2];
return DateAdd("d", -1, DateAdd("m", 1, CreateDate(strYear, strMonth, 1)));
}
</cfscript>
<cfset StartYear = listlast(StartDate,'/')>
<cfset EndYear = listlast(endDate,'/')>
<cfset HolidaySchedule = structnew()>
<cfloop index="currentYear" from="#dateformat(StartDate,'yyyy')#" to="#dateformat(EndDate,'yyyy')#" step="1">
<cfset val = StructInsert( HolidaySchedule, "Independence (#currentYear#)", createDate(currentYear,7,4) )/>
<cfset val = StructInsert( HolidaySchedule, "New Year (#currentYear#)", createdate(currentYear,1,1) )/>
<cfset val = StructInsert( HolidaySchedule, "Easter (#currentYear#)", GetEaster(currentYear) )/>
<cfset val = StructInsert( HolidaySchedule, "Spring Break (#currentYear#)", createDate(currentYear,3,GetNthOccOfDayInMonth(2,2,3,currentYear)) )/>
<cfset val = StructInsert( HolidaySchedule, "Labor Day (#currentYear#)", createDate(currentYear,9,GetNthOccOfDayInMonth(1,2,9,currentYear)) )/>
<cfset val = StructInsert( HolidaySchedule, "Thanksgiving (#currentYear#)", createDate(currentYear,11,GetNthOccOfDayInMonth(4,6,11,currentYear)) )/>
<cfset val = StructInsert( HolidaySchedule, "Christmas Day (#currentYear#)", createdate(currentYear,12,25) )/>
</cfloop>
<cfdump var="#HolidaySchedule#" expand="no">
<cfset normalweek = 'true'>
<cfloop index="x" from="#startDate#" to="#endDate#" step="1">
Checking date: #dateformat(x,'yyyy-mm-dd')#<br />
<cfif NOT arrayIsEmpty(structFindValue(HolidaySchedule,createDate(year(x),month(x),day(x))))>
<div style="background-color:##009900; color:##ffffff">#dateformat(x, 'mm/dd/yyyy')# is a holiday.</div>
<cfset normalweek = 'false'>
</cfif>
</cfloop>
<cfif normalweek eq 'false'>
Remember to add on the Holiday Fee.
<cfelse>
No additional charges for this appointment.
</cfif>
</cfif>
</cfoutput>
</body>
</html>