Download the PHP package thesis/time-span without Composer

On this page you can find all versions of the php package thesis/time-span. 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 time-span

Thesis TimeSpan

PHP Version Requirement GitHub Release Code Coverage Mutation testing badge

An immutable, nanosecond-precise time duration type for PHP 8.3+.

Installation

Why not DateInterval?

PHP's built-in DateInterval covers calendar durations — periods like "3 months" or "1 year" that only make sense relative to a specific date. TimeSpan covers the complementary case: a fixed amount of elapsed time that exists independently of any calendar.

DateInterval TimeSpan
Represents calendar period fixed duration
Supports months/years yes no
Immutable no yes
Arithmetic no add sub mul div
Comparison no compareTo isLessThan
Negative values awkward invert flag signed int
Precision microseconds nanoseconds

DateInterval is the right tool when you need "30 days from now" or "next month". TimeSpan is the right tool when you need "wait 30 seconds" or "this request took 42 ms".

Use cases

Creating a TimeSpan

From multiple units

From a single unit

All constructors accept int|float. Floats are rounded to the nearest nanosecond.

From a DateInterval

Note: Intervals with years or months cannot be converted to a fixed duration and will throw an InvalidArgumentException. Intervals produced by DateTimeInterface::diff() are also rejected due to DST ambiguity — use TimeSpan::between() instead.

Between two datetimes

The result is signed: between($a, $b) returns a negative span if $b is in the past relative to $a.

From the high-resolution timer

Directly from nanoseconds

Converting to other units

Every to*() method returns int by default. Pass a $precision argument to get a float with that many decimal places.

The optional second argument controls rounding mode (defaults to PHP_ROUND_HALF_UP):

Arithmetic

All arithmetic methods return a new TimeSpan instance and throw \OverflowException if the result exceeds the int range (~292 years in nanoseconds on 64-bit platform).

div() throws \DivisionByZeroError when the factor is 0.

Comparison

Sign checks

Formatting

format()

format() renders a span as a human-readable string. The default pattern is %-%h:%i:%s.

Placeholder Unit Width
%- sign 0–1
%d days >=1 (unpadded)
%h hours >=2 (zero-padded)
%i minutes >=2 (zero-padded)
%s seconds >=2 (zero-padded)
%ms milliseconds >=3 (zero-padded)
%us microseconds >=3 (zero-padded)
%ns nanoseconds >=3 (zero-padded)

The largest unit present in the format receives the total cumulative value; each smaller unit shows only the remainder after the larger ones are subtracted:

The sign is only included when %- is explicitly present in the format:

__toString()

__toString() is equivalent to format() with the default pattern:

License

MIT


All versions of time-span with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
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 thesis/time-span contains the following files

Loading the files please wait ...