Добавил функцию isHolyday(), которая учитывает это дело на основе производственного календаря.
Область определения 2016-2019 гг. РФ
Код: Выделить всё
//производственный календарь 2016 России
//с сайта http://data.gov.ru/opendata/7708660670-proizvcalendar
//выходные дни по-месячно, рабочие короткие помечены *
//грузим в таблицу pr_calendar
//Создаём сценарий и выполняем его один раз
SQLExec("create table IF NOT EXISTS pr_calendar ( n_year int(4) NOT NULL, n_month int(2) NOT NULL, holidays varchar(150) NOT NULL);");
//
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,1,'1,2,3,4,5,6,7,8,9,10,16,17,23,24,30,31')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,2,'6,7,13,14,20*,21,22,23,27,28')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,3,'5,6,7,8,12,13,19,20,26,27')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,4,'2,3,9,10,16,17,23,24,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,5,'1,2,3,7,8,9,14,15,21,22,28,29')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,6,'4,5,11,12,13,18,19,25,26')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,7,'2,3,9,10,16,17,23,24,30,31')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,8,'6,7,13,14,20,21,27,28')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,9,'3,4,10,11,17,18,24,25')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,10,'1,2,8,9,15,16,22,23,29,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,11,'3*,4,5,6,12,13,19,20,26,27')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2016,12,'3,4,10,11,17,18,24,25,31')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,1,'1,2,3,4,5,6,7,8,9,10,11,14,15,21,22,28,29')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,2,'4,5,11,12,18,19,22*,23,25,26')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,3,'4,5,7*,8,11,12,18,19,25,26')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,4,'1,2,8,9,15,16,22,23,29,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,5,'1,6*,7,8,9,13,14,20,21,27,28')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,6,'3,4,10,11,12*,17,18,24,25')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,7,'1,2,8,9,15,16,22,23,29,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,8,'5,6,12,13,19,20,26,27')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,9,'2,3,9,10,16,17,23,24,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,10,'1,7,8,14,15,21,22,28,29')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,11,'3*,4,5,6,11,12,18,19,25,26')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2017,12,'2,3,9,10,16,17,23,24,30,31')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,1,'1,2,3,4,5,6,7,8,9,10,13,14,20,21,27,28')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,2,'3,4,10,11,17,18,22*,23,24,25')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,3,'3,4,7*,8,10,11,17,18,24,25,31')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,4,'1,7,8,14,15,21,22,28,29,30*')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,5,'1,5,6,8*,9,12,13,19,20,26,27')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,6,'2,3,9,10,11*,12,16,17,23,24,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,7,'1,7,8,14,15,21,22,28,29')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,8,'4,5,11,12,18,19,25,26')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,9,'1,2,8,9,15,16,22,23,29,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,10,'6,7,13,14,20,21,27,28')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,11,'3,4,5,10,11,17,18,24,25')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2018,12,'1,2,8,9,15,16,22,23,29,30,31*')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,1,'1,2,3,4,5,6,7,8,9,10,12,13,19,20,26,27')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,2,'2,3,9,10,16,17,22*,23,24,25')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,3,'2,3,7*,8,9,10,16,17,23,24,30,31')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,4,'6,7,13,14,20,21,27,28,30*')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,5,'1,4,5,8*,9,11,12,18,19,25,26')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,6,'1,2,8,9,11*,12,15,16,22,23,29,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,7,'6,7,13,14,20,21,27,28')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,8,'3,4,10,11,17,18,24,25,31')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,9,'1,7,8,14,15,21,22,28,29')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,10,'5,6,12,13,19,20,26,27')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,11,'2,3,4,9,10,16,17,23,24,30')");
SQLExec("insert into pr_calendar (n_year,n_month,holidays) values (2019,12,'1,7,8,14,15,21,22,28,29,31*')");
Код: Выделить всё
//определяет, является ли день нерабочим = 1 или нет = 0
//На основе производственного календаря
//Чтобы дополнить isWeekEnd(),isWeekDay()
//isHoliday(mktime(0,0,0,1,1,2016)) or isHoliday()
// @return int
function isHoliday($dt = null){
if (!isset($dt)) $dt = time();
$resp = 0;
$ye = date('Y',$dt); // год
$mn = date('n',$dt); // месяц 1-12
$d = date('j',$dt); // число
$Record = SQLSelectOne("Select holidays from pr_calendar where n_year=".$ye." and n_month=".$mn);
$clnd=','.$Record['holidays'].','; // добавим запятых в начало и конец для единообразия
$pos = strpos($clnd,','.$d.','); //есть ли нужный нам день месяца в числах выходных?
if($pos === false){ //нет, не выходной((
$pos = strpos($clnd,','.$d.'*,'); //а, может, суббота или воскресенье стали коротким рабочим днём?
if($pos>0) {
$resp = 0; //увы, рабочий, хоть и короткий
}
}else{
$resp = 1; //да, выходной!
}
return $resp ;
}
Для рабочих дней 0, для нерабочих 1.
Код: Выделить всё
isHoliday(mktime(0,0,0,1,1,2016)) //Праздник ли 1 января?
Result: 1 //Да
isHoliday() //Праздник ли сегодня?
Result: 0 //Нет