fastbolt/working-day-provider 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fastbolt/working-day-provider

最新稳定版本:v1.0.0

Composer 安装命令:

composer require fastbolt/working-day-provider

包简介

PHP package to ease calculation of number of working days between two dates.

README 文档

README

Composer version

Code Climate maintainability Test Coverage

Type Coverage Psalm Level

Github Build

Working day provider

PHP package to ease calculation of number of working days between two given dates.

Prerequisites

For now, the bundle is tested using PHP 7.4, 8.0 and 8.1.

Installation

The library can be installed via composer:

composer require fastbolt/working-day-provider

Usage

Basic usage

For the most basic usage, you can use the WorkingDayProvider without any configuration.

By default, it will not use any application or region specific holiday, but only consider monday to friday as working days.

use Fastbolt\WorkingDayProvider\WorkingDayProvider;

$workingDayProvider = new WorkingDayProvider();
$workingDays = $workingDayProvider->getWorkingDaysForPeriod(
    new DateTimeImmutable('2023-01-01'),
    new DateTimeImmutable('2023-01-07')
);

// $workingDays will be 5

Application / region specific holidays

The library is designed to include application / region specific holidays as "non-working days".

To do so, you need to create a class implementing the Fastbolt\WorkingDayProvider\Holiday\HolidayProvider interface.

The only interface method getHolidaysForDateRange must return an array of objects implementing the \Fastbolt\WorkingDayProvider\Holiday\Holiday interface.

use Acme\Provider\HolidayProvider;
use Fastbolt\WorkingDayProvider\WorkingDayProvider;

$holidayProvider = new HolidayProvider());

# Example `$holidayProvider->getHolidaysForDateRange(2022-12-24, 2022-12-26)` returns one holiday for 26th of december.
$workingDayProvider = new WorkingDayProvider($holidayProvider);
$workingDays = $workingDayProvider->getWorkingDaysForPeriod(
    new DateTimeImmutable('2022-12-24'),
    new DateTimeImmutable('2022-12-26')
);

// $workingDays will be 0 (days are saturday, sunday and holiday)

Custom configuration (not yet fully-implemented)

Optionally, you can provide a custom configuration to the WorkingDayProvider constructor.

use Fastbolt\WorkingDayProvider\Configuration;
use Fastbolt\WorkingDayProvider\WorkingDayProvider;

$configuration = new Configuration(['excludeWeekDays' => [1, 6, 7]);
$workingDayProvider = new WorkingDayProvider(null, $configuration);
$workingDays = $workingDayProvider->getWorkingDaysForPeriod(
    new DateTimeImmutable('2022-12-24'),
    new DateTimeImmutable('2022-12-26')
);

// $workingDays will be 0 (working days monday, saturday and sunday are all configured as non-working days)

统计信息

  • 总下载量: 149
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-13