2

我的客户通常会提前几个月为她的客户安排约会。如果预订发生在美国假日日/周期间,我的客户希望获悉计划日期在美国假日期间(她在假日期间的服务收费更高)。

我的客户只关心以下日期:

  • 新年 12 月 30 日至 1 月 2 日
  • 三月春假周(三月第三周)
  • 复活节周末(这个日期每年都不同)
  • 五月阵亡将士纪念日周末
  • 七月的独立日周末
  • 九月的劳动节周末
  • 11 月的周一至周日的感恩节周
  • 圣诞周 12 月 22 日至 28 日

我想尽可能自动化,这样她就不必每年更新数据库,但这不是她的要求,而是我的要求。:D 最好将假期日期/规则输入数据库或使用规则来确定约会日期是否在安排约会时的假期日/周内?

如果数据库是答案,我需要一些关于数据库设计以及如何设置事件重复发生的帮助。如果基于规则,我也需要一些帮助(例如确定春假、复活节等的时间)。

我正在使用 MSSQL 2005(可能很快就会迁移到 mssql 2008)和 ColdFusion 9。

TIA

4

4 回答 4

3

我上个月写了一个 UDF来帮助处理许多美国假期,但它并没有涵盖所有内容。这应该给你一个体面的开始。

您还可以使用CFLib中的这个 UDF 来获得复活节

一旦你有阵亡将士纪念日,你可以做一个简单的dateadd()并带走 1 和 2 天来获得完整的周末。

<cffunction name="getUSBankHolidays" access="public" output="false" returntype="struct" hint="general bank holidays for US">
  <cfargument name="iYear" default="#Year(now())#" />

    <cfset var currentYear = arguments.iYear />

    <!--- Static dates per year --->
    <cfset var strResult = 
      { NewYears1      = createDate(currentYear,12,30),
        NewYears2      = createDate(currentYear,12,31),
        NewYears3      = createDate(currentYear,1,1),
        NewYears4      = createDate(currentYear,1,2),
        Independence   = createDate(currentYear,7,4),
        Christmas1     = createDate(currentYear,12,22),
        Christmas2     = createDate(currentYear,12,23),
        Christmas3     = createDate(currentYear,12,24),
        Christmas4     = createDate(currentYear,12,25),
        Christmas5     = createDate(currentYear,12,26),
        Christmas6     = createDate(currentYear,12,27),
        Christmas7     = createDate(currentYear,12,28)
  } />

    <cfset strResult.SpringBreak          = createDate(currentYear,3,GetNthOccOfDayInMonth(3,1,3,currentYear)) />
    <cfset strResult.MemorialDay          = createDate(currentYear,5,(DaysInMonth(createDate(2012,5,1))) - (DayOfWeek(createDate(2012,5,DaysInMonth(createDate(2012,5,1)))) - 2)) />
    <cfset strResult.LaborDay             = createDate(currentYear,9,GetNthOccOfDayInMonth(1,2,9,currentYear)) />
    <cfset strResult.Thanksgiving         = createDate(currentYear,11,GetNthOccOfDayInMonth(4,6,11,currentYear)) />

    <cfreturn strResult />
</cffunction>

<cfdump var="#getUSBankHolidays()#">

<!-- This code will tell you if the date is holiday or not --->
<cfset Today = '2012-01-01' />
<cfdump var="#NOT arrayIsEmpty(structFindValue(getUSBankHolidays(),createDate(year(Today),month(Today),day(Today))))#">

您还需要来自 CFLib.org 的UDF来获得一个月中一天的第 n 次出现。

于 2012-12-13T19:03:37.673 回答
1

数据库表将为您提供更多的灵活性。

我帮助维护的数据仓库有一个名为 period 的表,其中包含主键的日期。其他领域包括假期、一些财政年度的东西,以及对我们很重要的其他一些领域。其他表具有对表的外键引用。

除了使我们能够轻松生成必要的报告之外,该表还允许我们使用左连接来识别未发生事件的日期。类似的东西可能对您的情况有用。

就更新而言,我们手动进行。当像圣诞节这样的事情在周末降临时,我们等待被告知我们是周五还是周一休息。

于 2012-12-13T19:55:19.307 回答
0

在我看来,我会把它放在代码中。几年前我发现了这一点,并根据其许可协议使用了它。它是基于 Java 的,但我相信您可以根据需要更改为 Coldfusion。它目前列出了 66 个假期的代码,并且确保您可以对其进行一些操作来计算您需要的一周。

http://mindprod.com/applet/holidays.html

http://mindprod.com/precis/holidays.txt

https://wush.net/websvn/mindprod/listing.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fholidays%2F

于 2012-12-13T18:58:48.723 回答
0

这是我最终使用的,并且足够灵活,可以在将来进行修改,我可能仍会将其转换为带有 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>
于 2012-12-14T16:37:01.753 回答