devmakis/prodcalendar

俄罗斯、白俄罗斯、哈萨克斯坦和乌兹别克斯坦生产日历处理的库

1.3.4 2024-04-11 07:40 UTC

README

俄罗斯、白俄罗斯、哈萨克斯坦和乌兹别克斯坦生产日历处理的库。实现了两个数据源的客户 - Data.gov.ruxmlcalendar.ru。可以实现自己的客户端以从其他来源获取数据。

安装

composer require devmakis/prodcalendar

使用示例

use Devmakis\ProdCalendar\Clients\DataGovClient;
use Devmakis\ProdCalendar\Calendar;

$client = new DataGovClient('YOUR_TOKEN');
$calendar = new Calendar($client);
use Devmakis\ProdCalendar\Cache\FileJsonCache;
use Devmakis\ProdCalendar\Clients\XmlCalendarClient;
use Devmakis\ProdCalendar\Calendar;
use Devmakis\ProdCalendar\Country;

$cache = new FileJsonCache('FILE_PATH', 3600);
$client = new XmlCalendarClient(Country::RUSSIA, $cache);
$calendar = new Calendar($client);

检查是否为非工作日(周末 | 节假日 | 调休日)

$calendar->isNonWorking(new DateTime('01-01-2018'));
$calendar->isWeekend(new DateTime('01-01-2018'));
$calendar->isHoliday(new DateTime('01-01-2018'));
$calendar->isTransferredHoliday(new DateTime('24-03-2020'));

检查是否为节假日前的日子

$calendar->isPreHoliday(new DateTime('22-02-2018'));

获取特定时间段内的工作日 | 非工作日的数量

$dateBegin = new DateTime('31-01-2018');
$dateEnd = new DateTime('08-05-2018');
$countWorkingDays = $calendar->countWorkingDaysForPeriod($dateBegin, $dateEnd);
$countNonWorkingDays = $calendar->countNonWorkingDaysForPeriod($dateBegin, $dateEnd);

获取特定年份的生产日历,了解该年以及月份的工作日 | 非工作日的数量

$year2018 = $calendar->getYear('2018');
$countWorkingDays = $year2018->countWorkingDays();
$countNonWorkingDays = $year2018->countNonWorkingDays();
$countWorkingDaysInMay = $year2018->getMonth('05')->countWorkingDays();