vij-klim/appointed

检查所需预约时段是否开放或提供最近的可用时段

0.7.0 2022-06-25 15:38 UTC

This package is not auto-updated.

Last update: 2024-09-30 00:38:20 UTC


README

GitHub tag license Packagist

安装

composer require applicazza/appointed

用法

  • 设置默认时区,例如
date_default_timezone_set('Asia/Jerusalem');
  • 实例化工作日
use Applicazza\Appointed\BusinessDay;

// ...
$business_day = new BusinessDay;
  • 创建一些运营时段并将它们添加到工作日。如果某些运营时段无法添加,则返回false,并且将不应用任何更改
use Applicazza\Appointed\Period;

// ...

$period_0900_1400 = Period::make(today( 9, 00), today(14, 00));
$period_1600_1900 = Period::make(today(16, 00), today(19, 00));

$business_day->addOperatingPeriods(
    $period_1600_1900,
    $period_0900_1400
);
  • 创建一些预约并将它们添加到工作日。如果某些预约无法添加,则返回false,并且将不应用任何更改
use Applicazza\Appointed\Appointment;

// ...

$appointment_1100_1130 = Appointment::make(today( 11, 00), today(11, 30));
$appointment_1200_1330 = Appointment::make(today( 12, 00), today(13, 30));

$business_day->addAppointments(
    $appointment_1100_1130,
    $appointment_1200_1330
);
  • 要适应之前失败的预约,请使用BusinessDay::fit(Appointment $appointment, $direction = 'forward'),这将返回null或推荐的预约
$business_day->fit($appointment_1300_1330, 'backward');
$business_day->fit($appointment_1300_1330);
  • 要删除预约(s),请使用BusinessDay::deleteAppointments(Appointment ...$appointment),这将返回布尔值
$business_day->deleteAppointments($appointment_1300_1330);
  • 要删除运营时段,请使用BusinessDay::deleteOperatingPeriod(Period $period),这将返回布尔值
$business_day->deleteOperatingPeriod($period_0900_1400)
  • 要编辑运营时段,请使用BusinessDay::editOperatingPeriod(Period $old_period, Period $new_period),这将返回布尔值
$business_day->editOperatingPeriod($period_1330_1400, $period_1330_1430)
  • 要获取全天日程,请使用BusinessDay::getAgenda(),这将返回一个Period和/或Appointment的数组,按升序排列。由于底层类实现了JsonSerializable接口,因此这些数据可以轻松编码为json。
$agenda = $business_day->getAgenda();
// To pretty print results
echo json_encode($business_day->getAgenda(), JSON_PRETTY_PRINT), PHP_EOL;

辅助函数

use function Applicazza\Appointed\interval;
use function Applicazza\Appointed\today;
// ...
interval($hours = 0, $minutes = 0, $seconds = 0);
today($hours = 0, $minutes = 0, $seconds = 0);