sodecl/scheduler

Scheduler library

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

This package is auto-updated.

Last update: 2024-06-24 23:00:08 UTC


README

Sodecl Scheduler Library

Introduction

Sodecl Scheduler is a PHP library designed for creating and managing a customizable schedule of time slots. It's particularly useful for applications that require precise control over operational hours, appointments, breaks, and scheduling constraints. Leveraging the Carbon library for date and time manipulation, Sodecl Scheduler offers a powerful yet flexible way to handle complex scheduling needs.

Features

  • Flexible time slot configuration (e.g., 1 hour or 15 minutes blocks).
  • Customizable working days and operational hours.
  • Support for managing lunch breaks within the schedule.
  • Ability to exclude specific time slots.
  • Integration with Carbon for robust date and time handling.

Installation

To install the Sodecl Scheduler, you will need Composer, a dependency manager for PHP.

Run the following command in your project directory:

composer require sodecl/scheduler

Usage

Basic Setup

First, ensure you import the necessary classes from the library:

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

Schedule Configuration

Create a ScheduleConfig object to define your schedule parameters:

$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());

Creating a Schedule

Instantiate the Schedule class with your configuration:

$schedule = new Schedule($scheduleConfig);

Generating Time Slots

Generate time slots for a specific day:

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

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

Examples

Example 1: 1 Hour Time Blocks

This example demonstrates setting up a schedule with 1-hour blocks, excluding lunch hours:

$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());

Example 2: 15 Minute Time Blocks

In this example, the schedule is set for 15-minute time slots without a lunch break:

$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());

Contributing

Contributions to the Sodecl Scheduler are welcome. Please ensure to follow the project's code standards and submit your pull requests for review.

License

MIT