Skip to content

Laravel Hours Helper – easy to generate time intervals

Laravel Hours Helper package, makes it easier to generate a collection of dates and times with a specific interval for a particular period which could be super useful on.

What Is Laravel Hours Helper

This is a very useful package to generate a Collection of date and/or time intervals which can be used in drop-downs for a calendar meeting invite or scheduling the duration of an event, or any time/date sensitive situation you may need in your project. Laravel Hours Helper also allows you to define the date formatting for each interval and a way to exclude intervals within the specific time period.

Requirements of Laravel Hours Helper

Laravel Hours Helper
Laravel Hours Helper in action

To use this package you will need Laravel 8.x and that is it.

Examples of Laravel Hours Helper

First, we need to install the package via composer command below:

composer require label84/laravel-hours-helper

Then import the Facade and you are ready to go:

use Facades\Label84\HoursHelper\HoursHelper;

$hours = HoursHelper::create('08:00', '09:00', 15);

// Illuminate\Support\Collection
0 => '08:00',
1 => '08:15',
2 => '08:30',
3 => '08:45'

This helper can be very useful in multiple situations and is actually pretty powerful.

In this example, we are showing that you can use it in any situation, this example is excluding some dates and formatting the output:

$result = HoursHelper::create('2021-01-01 23:30', '2021-01-03 00:30', 15, 'Y-m-d H:i', [
            ['2021-01-02 00:00', '2021-01-02 23:59'],

        // Illuminate\Support\Collection
            0 => '2021-01-01 23:30',
            1 => '2021-01-01 23:45',
            2 => '2021-01-03 00:00',
            3 => '2021-01-03 00:15',
            4 => '2021-01-03 00:30',

Pretty cool, huh? Please elaborate in comments below if this helper is useful to you and how you will use it in your projects?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.