label84/

laravel-hours-helper

创建具有给定间隔的时间集合。

v1.3.0 2024-02-24 20:10 UTC

This package is auto-updated.

Last update: 2024-09-25 20:31:22 UTC


README

Latest Stable Version MIT Licensed Total Downloads GitHub Workflow Status

使用 laravel-hours-helper,您可以创建一个特定时间段内具有特定间隔的日期和/或时间的 Illuminate\Support\Collection。此辅助工具在生成日历会议邀请的下拉选择或安排事件持续时间时可能很有用。此辅助工具还允许您为每个间隔定义日期格式,并排除特定时间段内的间隔。

Laravel 支持

安装

使用 composer 安装此包

composer require label84/laravel-hours-helper

用法

use Label84\HoursHelper\Facades\HoursHelper;

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

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

示例 1:时间格式

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('11:00', '13:00', 60, 'g:i A');

// Illuminate\Support\Collection
0 => '11:00 AM',
1 => '12:00 PM',
2 => '1:00 PM',

示例 2:排除时间

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('08:00', '11:00', 60, 'H:i', [
    ['09:00', '09:59'],
    // more..
]);

// Illuminate\Support\Collection
0 => '08:00',
1 => '10:00',
2 => '11:00',

示例 3:午夜之后

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('23:00', '01:00', 60);

// Illuminate\Support\Collection
0 => '23:00',
1 => '00:00',
2 => '01:00',

示例 4:多日

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('2022-01-01 08:00', '2022-01-01 08:30', 15, 'Y-m-d H:i');

// Illuminate\Support\Collection
0 => '2022-01-01 08:00',
1 => '2022-01-01 08:15',
2 => '2022-01-01 08:30',

您可以在测试目录中找到更多示例: tests/HoursHelperTest.php

测试

./vendor/bin/phpstan analyze
./vendor/bin/phpunit

许可证

MIT