monadial/php-duration
Composer 安装命令:
composer require monadial/php-duration
包简介
PHP Duration Type
README 文档
README
Missing PHP TimeUnit and Duration library
Installation
composer require monadial/php-duration
Finite Duration
The FiniteDuration class is a representation of a finite duration of time. It provides functionality to perform operations and conversions on durations, such as addition, subtraction, multiplication, division, and conversion to different units of time.
Factory Methods
-
fromTimeUnit(int $length, TimeUnit $unit): FiniteDuration: Creates a new instance of theFiniteDurationclass from the specified length and time unit.\Monadial\Duration\FiniteDuration::fromTimeUnit(1, TimeUnit::SECONDS); // create 1 second duration
-
fromNanos(int $nanos): FiniteDuration: Creates a new instance of theFiniteDurationclass from the specified duration in nanoseconds.\Monadial\Duration\FiniteDuration::fromNanos(1000); // create 1000 nanoseconds duration
-
fromString(string $duration): FiniteDuration: Creates a new instance of theFiniteDurationclass from a string representation of the duration.\Monadial\Duration\FiniteDuration::fromTimeUnit('1 minutes'); // create 1 minute duration
Duration Conversion Methods
toNanos(): int: Converts the duration to nanoseconds.toMicros(): int: Converts the duration to microseconds.toMillis(): int: Converts the duration to milliseconds.toSeconds(): int: Converts the duration to seconds.toMinutes(): int: Converts the duration to minutes.toHours(): int: Converts the duration to hours.toDays(): int: Converts the duration to days.toUnit(TimeUnit $unit): float: Converts the duration to the specified time unit.
Arithmetic Operations
add(Duration $other): FiniteDuration: Adds another duration to the current duration.subtract(Duration $other): FiniteDuration: Subtracts another duration from the current duration.multiply(int $factor): FiniteDuration: Multiplies the duration by a factor.division(int $divisor): FiniteDuration: Divides the duration by a divisor.
Other Methods
isFinite(): bool: Checks if the duration is finite.equals(Duration $other): bool: Checks if the current duration is equal to another duration.toCoarsest(): Duration: Converts the duration to the coarsest possible unit.asDateTime(): DateTimeImmutable: Converts the duration to aDateTimeImmutableobject.
Exceptions
The FiniteDuration class may throw the following exceptions:
FiniteDurationBoundary: Thrown when the duration exceeds the maximum or minimum value allowed by the time unit.NanosecondsAreNotConvertibleToDateTime: Thrown when attempting to convert a duration in nanoseconds to aDateTimeImmutableobject (nanoseconds cannot be represented as a valid date and time).UnableToConvertToDateTime: Thrown when the duration cannot be converted to aDateTimeImmutableobject due to limitations or errors.
Please note that this is just an overview of the FiniteDuration class and its available methods. For detailed information on each method and its usage, refer to the class implementation and documentation.
monadial/php-duration 适用场景与选型建议
monadial/php-duration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.03k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 monadial/php-duration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 monadial/php-duration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 27.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-only
- 更新时间: 2022-12-09