webtoucher / calendar
用于高级操作日历天的库。
1.1.2
2016-05-05 11:55 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-14 21:25:29 UTC
README
此库有助于计算考虑假日的时间差。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
$ php composer.phar require webtoucher/calendar "*"
或
"webtoucher/calendar": "*"
将以下内容添加到您的 composer.json
文件的 require
部分中。
使用方法
为您的国家创建日历
$calendar = new Calendar(new Schedule('ru'));
您还可以使用您的外部规则。只需创建包含您的规则的目录 - 例如 2016.json 或 default.json。当不存在该年的规则时,将使用默认规则。使用目录完整路径来初始化计划。
$calendar = new Calendar(new Schedule('/var/www/my-site/rules/pl'));
以下方式之一计算工作日数量
echo $calendar->calendarToWorkingDays(new \DateTime('2016-02-24'), new \DateTime('2016-02-29')); // 3
echo $calendar->calendarToWorkingDays(new \DateTime('2016-02-29'), new \DateTime('2016-02-24')); // -3
echo $calendar->calendarToWorkingDays(new \DateTime('2016-02-24'), 5); // 3
echo $calendar->calendarToWorkingDays(new \DateTime('2016-02-29'), -5); // -3
以下方式之一计算工作日数日历天数
echo $calendar->workingToCalendarDays(new \DateTime('2016-02-24'), 3); // 5
echo $calendar->workingToCalendarDays(new \DateTime('2016-02-29'), -3); // -5
附加信息
您可以通过添加其他国家的规则来帮助此项目。向我发送您的pull requests。但请使用与json文件相同的格式。