ソデック/调度器

调度库

v0.1.2 2024-02-24 22:15 UTC

This package is auto-updated.

Last update: 2024-09-24 23:32:47 UTC


README

简介

ソデック调度器是一个用于创建和管理可定制时间段的PHP库。它特别适用于需要精确控制运营时间、预约、休息时间和调度约束的应用程序。利用Carbon库进行日期和时间操作,索德克调度器提供了一种强大而灵活的方法来处理复杂的调度需求。

特性

  • 灵活的时间段配置(例如,1小时或15分钟块)。
  • 可定制的工作日和运营时间。
  • 在调度中管理午餐休息时间。
  • 能够排除特定时间段。
  • 与Carbon集成,提供强大的日期和时间处理。

安装

要安装索德克调度器,您需要Composer,PHP的依赖关系管理器。

在您的项目目录中运行以下命令

composer require sodecl/scheduler

使用方法

基本设置

首先,确保您从库中导入必要的类

use Sodecl\Scheduler\Schedule;
use Sodecl\Scheduler\ScheduleConfig;
use Sodecl\Scheduler\TimeSlot;

调度配置

创建一个ScheduleConfig对象来定义您的调度参数

$scheduleConfig = ScheduleConfig::make()
    ->openingHour('08:00')
    ->closingHour('17:00')
    ->lunchBreak()
    ->lunchBreakStart('12:00')
    ->lunchBreakDuration(60) // in minutes
    ->slotMinutes(60)
    ->days(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
    ->scheduleStart(now()->startOfMonth())
    ->scheduleEnd(now()->endOfMonth());

创建调度

使用您的配置实例化Schedule

$schedule = new Schedule($scheduleConfig);

生成时间段

为特定一天生成时间段

$date = today(); // Carbon instance for the date
$slotsTaken = []; // Array of TimeSlot objects representing booked slots

$timeSlots = $schedule->timeSlotsFor($date, $slotsTaken);

示例

示例1:1小时时间段

此示例演示了设置带有1小时块并排除午餐时间的调度

$scheduleConfig = ScheduleConfig::make()
    ->openingHour('08:00')
    ->closingHour('17:00')
    ->lunchBreak()
    ->lunchBreakStart('12:00')
    ->lunchBreakDuration(60) // in minutes
    ->slotMinutes(60)
    ->days(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
    ->scheduleStart(now()->startOfMonth())
    ->scheduleEnd(now()->endOfMonth());

示例2:15分钟时间段

在此示例中,调度设置为15分钟时间段,没有午餐休息时间

$scheduleConfig = ScheduleConfig::make()
    ->openingHour('08:00')
    ->closingHour('17:00')
    ->lunchBreak()
    ->lunchBreakStart('12:00')
    ->lunchBreakDuration(60) // in minutes
    ->slotMinutes(15)
    ->days(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
    ->scheduleStart(now()->startOfMonth())
    ->scheduleEnd(now()->endOfMonth());

贡献

欢迎为索德克调度器做出贡献。请确保遵循项目的代码标准,并提交您的pull请求以供审查。

许可

MIT