用于识别节假日或纪念日期(国家、州、市)的日期库,自动计算工作日和办公时间。

1.0.5 2019-09-25 18:22 UTC

This package is auto-updated.

Last update: 2024-09-26 05:17:20 UTC


README

Software License

用于识别来自国家、州和城市的节假日和纪念日期的协作日期库,可自动计算工作日和办公时间,无需为每个地区编写新类。事件将从CSV文件加载,未来可能通过协作API更新。

此库受到了checkdomain/holiday项目的启发,完全重写以支持来自国家、州和城市的节假日和纪念日期,以及自动计算工作日和办公时间,无需为每个地区编写新类。事件将从CSV文件加载,未来可能通过协作API更新。

目前支持的国家

  • 🇧🇷 BR 巴西
    • 国家节假日
    • 夏季节假日
    • 城市节假日
    • 纪念日期
    • 工作日
    • 办公时间

您的国家、州或城市不受支持吗?

joaosalless/dates 是开源的。如果您使用此库,那么对目前尚未实现您熟悉的国家的支持将非常感激。拉取请求将被快速审查和合并。

安装

通过 Composer

$ composer require joaosalless/dates

用法

节假日

$dates = new Joaosalless\Dates\Dates('BR');

// Get only national holidays
$dates->getHolidays('2019-09-07');

// Check if a given date is holiday only national holidays
$dates->isHoliday('2019-09-07');

// Get national and state holidays
$dates->getHolidays(
   '2019-09-07', // Date
   'SP'          // State code
);

// Check if a given date is holiday in national and state holidays
$dates->isHoliday(
   '2019-09-07', // Date
   'SP'          // State code
);

// Get national, state and city holidays
$dates->getHolidays(
   '2019-09-07', // Date
   'SP',         // State code
   '3550308'     // City code
);

// Check if a given date is holiday in national, state and city holidays
$dates->isHoliday(
   '2019-09-07', // Date
   'SP',         // State code
   '3550308'     // City code
);

纪念日期

$dates = new Joaosalless\Dates\Dates('BR');

// Get only national commemorative dates
$dates->getCommemorativeDates('2019-09-07');

// Get national and state commemorative dates
$dates->getCommemorativeDates(
   '2019-09-07', // Date
   'SP'          // State code
);

// Get national, state and city commemorative dates
$dates->getCommemorativeDates(
   '2019-09-07', // Date
   'SP',         // State code
   '3550308'     // City code
);

工作日

从开始日期计算指定天数的工作日

// Configure business days and office hours
$config = [
    'week' => [
        'office_hours_start' => '09:00',
        'office_hours_end' => '18:00',
        'check_office_hours' => false,
        'days' => [
            'sun' => [
                'business_day' => false,
            ],
            'mon' => [
                'business_day' => true,
            ],
            'tue' => [
                'business_day' => true,
            ],
            'wed' => [
                'business_day' => false,
            ],
            'thu' => [
                'business_day' => true,
            ],
            'fri' => [
                'business_day' => true,
            ],
            'sat' => [
                'business_day' => true,
                'office_hours_start' => '09:00',
                'office_hours_end' => '14:00',
            ],
        ]
    ]
];

$dates = new Dates('BR', $config);

$dates->calculateBusinessDays(
    10,           // Number of days
    '2019-09-07', // Start date
    'SP',         // Check state holidays
    '3550308',    // Check city holidays
);

$dateTime = new DateTime('2019-07-31 08:23:00');

// Check if given DateTime instance is a business day
$dates->isBusinessDay($dateTime); // Returns bool

// Check if given datetime string is a business day
$dates->isBusinessDay('2019-07-31 08:23:00'); // Returns bool

// Returns \DateTime;

办公时间

检查给定的 DateTime 实例或 datetime 字符串是否为办公时间

$dates = new Joaosalless\Dates\Dates('BR');

$dateTime = new DateTime('2019-07-31 08:23:00');

// Check if given DateTime instance is a office hour
$dates->isOfficeHour($dateTime); // Returns bool

// Check if given string date is office hours
$dates->isOfficeHour('2019-07-31 08:23:00'); // Returns bool

变更日志

请参阅 CHANGELOG 以获取有关最近更改的更多信息。

测试

$ composer test

贡献

请参阅 CONTRIBUTINGCODE_OF_CONDUCT 以获取详细信息。

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件 joaosalless@gmail.com 联系,而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证(MIT)。请参阅 许可证文件 以获取更多信息。