实行一年假期功能?

时间:2013-03-01 11:03:29

标签: php datepicker

我有一个假期列表,如:

var holiDays =[[2013,01,01,'New Years Day'],[2013-05-27, 'Memorial Day']]

并在celender上显示,但这个列表是硬编码所以我想要一个PHP的功能,以便所有假期列出可见年度明智。 $(function() { $("#id_holiday_date").datepicker({ beforeShowDay: setHoliDays });

      // set holidays function which is configured in beforeShowDay
     function setHoliDays(date) {
       for (i = 0; i < holiDays.length; i++) {
         if (date.getFullYear() == holiDays[i][0]
              && date.getMonth() == holiDays[i][1] - 1
              && date.getDate() == holiDays[i][2]) {
            return [true, 'holiday', holiDays[i][3]];
         }
       }
      return [true, ''];
    }

 });


this function work properly in date picker.this date picker takes date from hardcoded array.
I want a function like that:
function calculateHolidays($year = '') {

      // set holidays function which is configured in beforeShowDay
     function setHoliDays(date) {
       for (i = 0; i < holiDays.length; i++) {
         if (date.getFullYear() == holiDays[i][0]
              && date.getMonth() == holiDays[i][1] - 1
              && date.getDate() == holiDays[i][2]) {
            return [true, 'holiday', holiDays[i][3]];
         }
       }
      return [true, ''];
    }

 });

提前致谢

2 个答案:

答案 0 :(得分:1)

如果我是你,我会看一下PEAR date holidays

答案 1 :(得分:0)

这是一种方法 - 如果你想找到给定年份的所有括号[]

function display_holidays($year,$list){
    echo "<ul>";
    $list=str_replace(array('[[',']]','],['),array('[',']',']|['),$list);
    $list=explode("|",$list);
    foreach($list as $item){
        // find the items with the correct year
        if(strstr($item,"[".$year)){
            echo "<li>".$item."</li>";
        }
    }
    echo "</ul>";
}

用法示例:

$list="[[2012,01,01,'New Years Day'],[2013,05,27, 'Memorial Day']]";
$year=2013;
display_holidays($year,$list);

结果将是:

<ul>
   <li>[2013,05,27, 'Memorial Day']</li>
</ul>

ps :但请详细说明您想要达到的目标。