unit/microtime

Package for calculating and formatting information units like second, millisecond, microsecond, nanosecond, picosecond, etc.

v1.0.1 2018-12-23 12:16 UTC

This package is auto-updated.

Last update: 2020-02-23 18:35:54 UTC


README

Package for calculating and formatting information units like second, millisecond, microsecond, nanosecond, picosecond, etc.

Installation

composer require unit/microtime

Usage

Instantiate microtime:

use Unit\Microtime\Microtime;

$microtime = new Microtime(1); // arguments which are no strings are treated as microsecond values
$twoMilliseconds = new Microtime('2ms');

Get microtime information:

$microtime->format();                               // '1µs'
$microtime->format('s');                            // '1.0E-6s'
$microtime->format('s', 6);                         // '0.000001s'
$microtime->format('ms');                           // '0.001ms'
$microtime->format('ms', 1);                        // '0.0ms'
$microtime->format('ms', 2);                        // '0.00ms'
$microtime->format('µs');                           // '1µs'
$microtime->format('ns');                           // '1000ns'
$microtime->format('ps');                           // '1000000ps'
$microtime->format('fs');                           // '1000000000fs"'

$microtime->get('s');                               // (double) 1.0E-6)
$microtime->get('ms');                              // (double) 0.001
$microtime->get('µs');                              // (double) 1
$microtime->get('ns');                              // (double) 1000
$microtime->get('ps');                              // (double) 1000000
$microtime->get('fs');                              // (double) 1000000000

$microtime->add($twoMilliseconds)->format();        // '2.001ms'
$microtime->add($twoMilliseconds)->format();        // '4.001ms'
$microtime->add($twoMilliseconds)->format(null, 1); // '6.0ms'
$microtime->subtract($twoMilliseconds)->format();   // '4.001ms'
$microtime->multiply($twoMilliseconds)->format();   // '8.002s'
$microtime->divide($twoMilliseconds)->format();     // '4.001ms'

Testing

$ ./vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.