nuxia / business-day-manipulator
工作日操作器
v0.1.0
2015-03-13 11:02 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ~4.0
Suggests
- intl: Required to use localized manipulator
This package is not auto-updated.
Last update: 2024-09-23 07:29:11 UTC
README
轻松操作工作日
- 查找一段时间内的工作日数量。
- 通过将天数加到起始日期上找到结束日期
安装
- 如果您使用Composer来管理依赖项,可以使用
composer require nuxia/business-day-manipulator
简单操作器
use Nuxia\BusinessDayManipulator\Manipulator; $holidays = [ new DatePeriod(new \DateTime('2015-02-02'), new \DateTime('2015-02-06')), new \DateTime('2015-02-20') ]; $freeDays = [ new DatePeriod(new \DateTime('2015-02-24'), new \DateTime('2015-02-27')) ]; $freeWeekDays = [ Manipulator::SATURDAY, Manipulator::SUNDAY ]; $manipulator = new Manipulator($freeDays, $freeWeekDays, $holidays);
- 免费周日在每周重复
- 节假日每年重复
- 免费日不重复
本地化操作器
use Nuxia\BusinessDayManipulator\LocalizedManipulator; $holidays = [ new DatePeriod(new \DateTime('2015-02-02'), new \DateTime('2015-02-06')), new \DateTime('2015-02-20') ]; $freeDays = [ new DatePeriod(new \DateTime('2015-02-24'), new \DateTime('2015-02-27')) ]; $freeWeekDays = null; //If null, we will automatically set free week days from the locale. //Guess automatically free week days. $localizedManipulator = new LocalizedManipulator('Europe/Paris', 'fr', $freeDays, $freeWeekDay, $holidays);
工作日日期预测器
$manipulator->setStartDate(new \DateTime('2015-02-01')); $manipulator->addBusinessDays(15); $manipulator->getDate()->format('Y-m-d'); //2015-03-06
$manipulator->setStartDate(new \DateTime('2015-03-06')); $manipulator->subBusinessDays(15); $manipulator->getDate()->format('Y-m-d'); //2015-02-01
工作日数量预测器
$manipulator->setStartDate(new \DateTime('2015-02-01')); $manipulator->setEndDate(new \DateTime('2015-03-02')); $manipulator->getBusinessDays(); //12 $manipulator->getBusinessDaysDate()); //Array of DateTime instance
Manipulator::isBusinessDay()
$manipulator->isBusinessDay(new \DateTime('2015-02-08')); //false
Manipualtor::getTypeOfDay()
$manipulator->getTypeOfDay(new \DateTime('2015-02-08')); // free_week_day
运行测试
只需运行phpunit
来执行单元测试
许可证
The MIT License (MIT) Copyright (c) 2015 Nuxia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.