sfneal / time-helpers
PHP 时间实用工具,用于转换时间值和创建时间周期
1.2.3
2021-07-30 17:50 UTC
Requires
- php: >=7.3
- spatie/laravel-analytics: ^3.10
Requires (Dev)
- illuminate/database: >=8.2
- orchestra/testbench: >=6.7
- scrutinizer/ocular: ^1.8
- sfneal/laravel-helpers: ^2.4
README
PHP 时间实用工具,用于转换时间值和创建时间周期
安装
您可以通过 composer 安装此包
composer require sfneal/time-helpers
使用方法
Carbonate
Carbonate 可以用来获取从今天的日期时间转换而来的 Carbon 对象。这有助于获取表示过去或未来日期时间的 Carbon 对象。
use Sfneal\Helpers\Time\Carbonate; // Retrieve a Carbon\Carbon object representing '3' days ago $threeDaysAgo = Carbonate::daysAgo(3); $threeDaysAgo = Carbonate::days(-3); // Retrieve a Carbon\Carbon object representing '5' years ago $fiveYearsAgo = Carbonate::yearsAgo(3); $fiveYearsAgo = Carbonate::years(-3); // Retrieve a Carbon\Carbon object representing '6' months ago $sixMonthsAgo = Carbonate::monthsAgo(3); $sixMonthsAgo = Carbonate::months(-3);
TimeConverter
TimeConverter 用于在不同时间单位(小时、分钟和秒)之间进行转换。
use Sfneal\Helpers\Time\TimeConverter; // Convert Hours to Minutes $hours = 5.5; $minutes = (new TimeConverter())->setHours($hours)->minutes(); >>> 19800 // Convert Seconds to Hours $seconds = 37800; $hours = (new TimeConverter())->setSeconds($hours)->hours(); >>> 10.5
TimePeriod
TimePeriod 用于获取时间段(如今天、上个月等)的开始和结束日期时间。这在创建时间范围的查询时很有用,例如收集上个月的订单。
use Sfneal\Helpers\Time\TimePeriod; // Retrieve a TimePeriod representing today (02/16/2021) [$start, $end] = TimePeriods::today(); // $start >>> 2021-02-16 00:00:00 // $end >>> 2021-02-16 23:59:59
测试
composer test
更新日志
请参阅 更新日志 了解最近更改的更多信息。
贡献
请参阅 贡献指南 了解详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 stephen.neal14@gmail.com 联系,而不是使用问题跟踪器。
致谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。
PHP 包模板
此包是使用 PHP 包模板 生成的。