dcaswel/time-converter
Composer 安装命令:
composer require dcaswel/time-converter
包简介
A PHP package for converting a unit of time into another unit of time.
README 文档
README
A fluent PHP package for converting one unit of time into another unit of time.
Have you ever wanted an elegant way to get a certain amount of time worth of seconds? Let's say you're using a caching system where you need to set the ttl in a number of seconds. Does this look familiar?
//One day's worth of seconds $ttl = 24 * 60 * 60;
Have you ever wanted to have something that was easier to read that is self documenting. That's where this package comes in. Here's the equivalent line of code using Time Converter:
use Dcaswel\TimeConverter\TimeConverter; $ttl = TimeConverter::convert()->oneDay()->toSeconds();
Now, let's take a deeper look...
Installation
composer require dcaswel/time-converter
Usage
This package can be used for converting almost any length of time into any other length of time.
Examples
TimeConverter::convert()->days(5)->toSeconds(); //432000 TimeConverter::convert()->years(2)->toMonths(); //24 TimeConverter::convert()->weeks(20)->toDays(); //140 ...
Note: In order to keep the numbers whole, a month is considered 28 days.
You can also combine methods to get a more precise time:
TimeConverter::convert()->weeks(2)->days(5)->toDays(); //19
For any method in the class, you can also call a singular version of it by prepending one to the beginning and removing
the s.
For example:
weeks()can beoneWeek()days()can beoneDay()- etc.
API
/** * Methods to set the time being converted */ public function minutes(int $number) public function hours(int $number) public function days(int $number) public function weeks(int $number) public function months(int $number) public function years(int $number) /** * Methods to get the number you want to convert to */ public function toSeconds(): int|float public function toMinutes(): int|float public function toHours(): int|float public function toDays(): int|float public function toWeeks(): int|float public function toMonths(): int|float public function toYears(): int|float
dcaswel/time-converter 适用场景与选型建议
dcaswel/time-converter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dcaswel/time-converter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dcaswel/time-converter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-11