-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathapi.php
148 lines (143 loc) · 4.11 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* 加入节假日时间段,节假日不放假
* 1.节假日当天前后几天能放假的都算节假日
* 如:10.1国庆节,但是放假7天,所以10.1-10.7都算节假日
* 2.有些节假日不放假,算工作日
* 如:2.2世界湿地日,但是不放假,所以算工作日
* 修正返回格式
* 节假日配置
*
* @author zhusaidong [zhusaidong@gmail.com]
* @version 0.2.0.0
*/
date_default_timezone_set('Asia/Shanghai');
require_once("./config.php");
require_once("./function.php");
require_once("./Lunar.class.php");
!isset($_GET['date']) and exit(json_encode([
'code'=>-1,
'info'=>'输入日期',
'describe'=>[],
],JSON_UNESCAPED_UNICODE));
$dates = $_GET['date'];
$dates == "" and $dates = date('Y-m-d',time());
$lunar = new Lunar();
$return = [];
foreach(explode(',',$dates) as $key => $date)
{
//不正确的日期格式
if(($time = strtotime($date)) === FALSE)
{
exit('不正确的日期格式:'.$date);
}
$oldDate = $date;
$date = date('Y-m-d',$time);
//返回的格式
$return[$key]['date'] = $date;
//工作日
$return[$key]['code'] = 0;
$return[$key]['info'] = '工作日';
$return[$key]['describe'] = ['Name'=>'周一至周五'];
//判断是否为阳历节假日
foreach($GregorianCalendarHoliday as $GregorianCalendarHolidayList)
{
//time
$time = $GregorianCalendarHolidayList["Time"];
$time = date('Y-',strtotime($oldDate)).str_replace(array('月','日'),array('-',''),$time);
$time = strtotime($time);
//start end
$start= $time - abs($GregorianCalendarHolidayList["Start"]) * 86400;
$end = $time + abs($GregorianCalendarHolidayList["End"]) * 86400;
//判断
if(strtotime($date) >= $start && strtotime($date) <= $end)
{
//节假日
if($GregorianCalendarHolidayList["IsNotWork"])
{
$return[$key]['code'] = 1;
$return[$key]['info'] = '节假日';
}
$return[$key]['describe'] = $GregorianCalendarHolidayList;
break;
}
}
//判断是否为特殊节假日
foreach($SpecialHoliday as $SpecialHolidaylist)
{
//time
$time = $SpecialHolidaylist["Time"];
preg_match('/^(.*)月(.*)星期(.*)$/iUs',$time,$match);
if(!isset($match[2]))
{
break;
}
if($match[2] == "最后一个")
{
$match[2] = 7;
}
$gdwnm = GetDateByWeekNumberOfMonth(strtotime($oldDate),$match[2],WeekChinese2Number($match[3]));
if(date('m',$gdwnm) != date('m',strtotime($date)))
{
$match[2] = 6;
$gdwnm = GetDateByWeekNumberOfMonth(strtotime($oldDate),$match[2],WeekChinese2Number($match[3]));
}
$time = $gdwnm;
//start end
$start= $time - abs($SpecialHolidaylist["Start"]) * 86400;
$end = $time + abs($SpecialHolidaylist["End"]) * 86400;
//判断
if(strtotime($date) >= $start && strtotime($date) <= $end)
{
//节假日
if($SpecialHolidaylist["IsNotWork"])
{
$return[$key]['code'] = 1;
$return[$key]['info'] = '节假日';
}
$return[$key]['describe'] = $SpecialHolidaylist;
break;
}
}
//判断是否为阴历节假日
foreach($LunarCalendarHoliday as $LunarCalendarHolidayList)
{
//time
$time = $LunarCalendarHolidayList["Time"];
$time = explode('月',$time);
//农历转数字
$y = date('Y',strtotime($date));
$LunarCalendarHolidayList["Name"] == '除夕' and $y--;//除夕是上一年的阴历日期
$time = $lunar->convertLunarToSolar($y,LMonName($time[0]),LDayName($time[1]));
$time = strtotime(implode('-',$time));
//start end
$start= $time - abs($LunarCalendarHolidayList["Start"]) * 86400;
$end = $time + abs($LunarCalendarHolidayList["End"]) * 86400;
//判断
if(strtotime($date) >= $start && strtotime($date) <= $end)
{
//节假日
if($LunarCalendarHolidayList["IsNotWork"])
{
$return[$key]['code'] = 1;
$return[$key]['info'] = '节假日';
}
$return[$key]['describe'] = $LunarCalendarHolidayList;
break;
}
}
//不是节假日,则判断是否为非工作日(周六周日)
if($return[$key]['code'] == 0)
{
//星期
$w = date('w',strtotime($date));
if($w == 0 || $w == 6)
{
//双休日
$return[$key]['code'] = 2;
$return[$key]['info'] = '双休日';
$return[$key]['describe'] = ['Name'=>'周六周日'];
}
}
}
echo json_encode($return,JSON_UNESCAPED_UNICODE);