承接 monadial/php-duration 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 the FiniteDuration class 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 the FiniteDuration class from the specified duration in nanoseconds.

    \Monadial\Duration\FiniteDuration::fromNanos(1000); // create 1000 nanoseconds duration
  • fromString(string $duration): FiniteDuration: Creates a new instance of the FiniteDuration class 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 a DateTimeImmutable object.

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 a DateTimeImmutable object (nanoseconds cannot be represented as a valid date and time).
  • UnableToConvertToDateTime: Thrown when the duration cannot be converted to a DateTimeImmutable object 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 monadial/php-duration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 27.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: AGPL-3.0-only
  • 更新时间: 2022-12-09