Download the PHP package rasuvaeff/duration without Composer

On this page you can find all versions of the php package rasuvaeff/duration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package duration

rasuvaeff/duration

Latest Stable Version Total Downloads Build Static analysis Psalm level PHP Русская версия

Type-safe, immutable, non-negative duration value object for PHP. Replaces bare int parameters (seconds? milliseconds?) with an explicit unit, removing a whole class of "seconds vs milliseconds" bugs. Designed as the foundation for timeout, wait and lease parameters across the resilience packages.

Using an AI coding assistant? llms.txt contains a compact API reference you can share with the model.

Requirements

Installation

Usage

Factories

Method Description
Duration::zero() Zero-length duration
Duration::micros(int $micros) From microseconds
Duration::millis(int $millis) From milliseconds
Duration::seconds(int\|float $seconds) From seconds (fractional allowed)
Duration::minutes(int\|float $minutes) From minutes (fractional allowed)
Duration::hours(int\|float $hours) From hours (fractional allowed)
Duration::days(int\|float $days) From days (fractional allowed)

Conversions

Method Returns Notes
toMicros() int Exact — microseconds is the storage unit
toMillis() int Rounded up (ceil)
toSeconds() float
toMinutes() float

toMillis() rounds up on purpose: a non-zero sub-millisecond duration must never collapse to 0, because 0ms means "no timeout / infinite" to cURL and most HTTP clients — the exact failure a timeout value is meant to prevent.

Arithmetic & comparison

Method Returns Description
plus(Duration $other) Duration Sum of two durations
minus(Duration $other) Duration Saturating difference — never negative (a passed deadline is 0)
Duration::min($a, $b) Duration Static — the smaller of two durations
Duration::max($a, $b) Duration Static — the larger of two durations
isZero() bool True when zero-length
isPositive() bool True when non-zero
equals(Duration $other) bool Equal length
compareTo(Duration $other) int -1 / 0 / 1
isGreaterThan(Duration $other) bool Strictly longer
isLessThan(Duration $other) bool Strictly shorter

String representation

Duration implements Stringable. Casting to string yields a human-readable form, choosing the largest unit with a value of at least 1:

The unit set, rounding and suffix spelling are an observable contract: changing them is a major version bump. For machine-readable values use toMicros() / toMillis() / toSeconds() / toMinutes() directly.

Security

Not security-sensitive: a pure, side-effect-free value object. It performs no I/O and holds no secrets. The only enforced contract is the input domain:

Examples

See examples/ for runnable scripts. Examples are expected to execute without fatal errors and stay aligned with the documented public API.

Script Shows Needs server?
basic.php Factories, conversions, arithmetic, comparison no

Development

No PHP/Composer on the host — run in Docker via the composer:2 image:

Or with Make:

make test-coverage and make mutation bootstrap pcov inside the composer:2 container because the base image has no coverage driver.

License

BSD-3-Clause


All versions of duration with dependencies

PHP Build Version
Package Version
Requires php Version 8.3 - 8.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rasuvaeff/duration contains the following files

Loading the files please wait ...