Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Hours Helper

Laravel Hours Helper Laravel Package

label84/laravel-hours-helper

Generate Laravel Collections of time/date intervals between start and end with a given step. Customize output formatting, handle ranges crossing midnight or spanning days, and exclude specific intervals—ideal for meeting schedulers, calendars, and dropdown time selectors.

View on GitHub
Deep Wiki
Context7

Creates a Collection of times with a given interval.

Frequently asked questions about Laravel Hours Helper
How do I generate time slots for a booking system UI in Laravel?
Use `HoursHelper::create('start_time', 'end_time', interval_minutes, 'format')` to generate a Collection of time strings. For example, `HoursHelper::create('09:00', '17:00', 30, 'H:i')` creates 30-minute slots from 9 AM to 5 PM. The output is ready for Blade templates or API responses.
Does this package support multi-day time ranges (e.g., overnight shifts)?
Yes, it handles ranges crossing midnight automatically. For example, `HoursHelper::create('23:00', '01:00', 60)` generates slots from 11 PM to 1 AM, including midnight. Works for any datetime format, including full dates like '2024-01-01 23:00' to '2024-01-02 01:00'.
Can I exclude specific time ranges (e.g., lunch breaks) from the generated slots?
Absolutely. Pass an array of exclusion ranges as the fifth parameter. For example, `HoursHelper::create('08:00', '18:00', 60, 'H:i', [['12:00', '13:00']])` skips all slots between 12 PM and 1 PM. You can add multiple exclusion ranges to block multiple intervals.
What Laravel versions does this package support, and will it break in future updates?
The package supports Laravel 11, 12, and 13 with version `^1.4`. It follows semantic versioning, so minor updates (e.g., 1.4.x) will maintain backward compatibility. Major updates (e.g., 2.0) may introduce breaking changes, but the release history suggests stability for now.
How do I customize the output format of the time slots (e.g., '12-hour clock' or localized formats)?
Use Carbon-compatible format strings as the fourth parameter. For example, `'g:i A'` produces '11:00 AM', while `'H:i'` gives '13:00'. For localized formats, parse the output Collection with Carbon’s `setLocale()` or use Laravel’s localization helpers. The package relies on Carbon’s formatting, so all standard Carbon formats are supported.
Will this package work with timezones other than UTC? If not, how can I handle timezone-specific scheduling?
The package defaults to UTC for consistency. To use a specific timezone, wrap your inputs with Carbon’s timezone parsing. For example, `Carbon::parse('09:00', $appTimezone)->format('H:i')` before passing to `HoursHelper`. Alternatively, extend the package via a service provider to inject timezone logic into the facade.
Is there a performance risk if I generate thousands of time slots (e.g., for a yearly calendar)?
The package is optimized for typical use cases (e.g., daily scheduling with <100 slots), but generating >10k intervals may impact memory or response time. Mitigate this by caching static ranges (e.g., `Cache::remember`) or implementing lazy loading (e.g., chunked processing or generators) in your application layer.
How do overlapping exclusion ranges work? For example, if I exclude [['09:00', '10:00']] and [['09:30', '10:30']], which takes precedence?
The package processes exclusions in the order they’re provided, with the first matching exclusion taking precedence. For your example, slots between 09:00–09:30 and 10:00–10:30 would be included, while 09:30–10:00 would be excluded. Document this behavior in your app or pre-validate exclusions to avoid ambiguity.
Can I integrate this with Livewire or Inertia for real-time scheduling UIs?
Yes, the package returns a Laravel Collection, which integrates seamlessly with Livewire or Inertia. Pass the Collection directly to your frontend (e.g., via JSON response or Blade) and bind it to dropdowns or time pickers. No additional processing is needed—just ensure your frontend handles the formatted strings correctly.
Are there alternatives to this package for generating time intervals in Laravel?
For simple time intervals, you could manually loop with Carbon or use Laravel’s `Str::of()` for formatting. For more advanced scheduling, consider `spatie/laravel-calendar` (for recurring events) or `nwidart/laravel-modules` (for modular scheduling logic). However, this package is specialized for lightweight, dynamic interval generation without calendar overhead.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport