Download the PHP package korshunov/timeinterval without Composer

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

timeinterval

Class to work with amount of time(hours, minutes, seconds). Absolute time interval not related to calendar (year, month). Features:

Instance:

1) TimeInterval instance, can create by seconds, example:

or other time units, example:

2) TimeInterval instance, can create by H:M:S string, example:

3) TimeInterval instance, can create by datestring, example:

4) TimeInterval instance, can create by interval spec string, example:

Can work with positive and negative intervals.

Add and sub intervals

1) Add:

2) Sub:

3) Modify:

Formatting

Format compatible with \DateInterval::format(), but only time units placeholder. Available placeholders: %r, %R, %h, %H, %m, %M, %s, %S Additional placeholders: %x, %X - amount of minutes in the interval(round to interger)

Example


use Korshunov\TimeInterval\TimeInterval;
use Korshunov\TimeInterval\TimeIntervalImmutable;
use Korshunov\TimeInterval\TimeIntervalInterface;

$days = 5;
$hours = 8;
$minutes = 15;
$seconds = 15;

// BASE
$convertToSeconds = $days * 86400 + $hours * 3600 + $minutes * 60 + $seconds;

$time = new TimeInterval($convertToSeconds);

echo $time->convertToHours(); // 128
// with precision
echo $time->convertToHours(2); //128.25
echo $time->convertToHours(3); //128.254

echo $time->convertToMinutes(); // 7695
// with precision
echo $time->convertToMinutes(2); // 7695.25
echo $time->convertToMinutes(3); // 7695.25

echo $time->convertToSeconds(); // 461715

// MODIFY
$time = new TimeInterval($days, TimeIntervalInterface::DAY);
$time->modify($hours, TimeIntervalInterface::HOUR);
$time->modify($minutes, TimeIntervalInterface::MINUTE);
$time->modify($seconds, TimeIntervalInterface::SECOND); // or $time->modify($seconds);

echo $time->convertToHours();   // 128
// with precision
echo $time->convertToHours(2); //128.25
echo $time->convertToHours(3); //128.254

echo $time->convertToMinutes(); // 7695
// with precision
echo $time->convertToMinutes(2); // 7695.25
echo $time->convertToMinutes(3); // 7695.25

echo $time->convertToSeconds(); // 461715

// ADD
$time = new TimeInterval();
$time1 = new TimeInterval($days, TimeIntervalInterface::DAY);
$time2 = new TimeInterval($hours, TimeIntervalInterface::HOUR);
$time3 = new TimeInterval($minutes, TimeIntervalInterface::MINUTE);
$time4 = new TimeInterval($seconds, TimeIntervalInterface::SECOND);

// adding
$time->add($time1)->add($time2);
$time->add($time3);
$time->add($time4);

echo $time->convertToHours(); // 128
// with precision
echo $time->convertToHours(2); //128.25
echo $time->convertToHours(3); //128.254

echo $time->convertToMinutes(); // 7695
// with precision
echo $time->convertToMinutes(2); // 7695.25
echo $time->convertToMinutes(3); // 7695.25

echo $time->convertToSeconds(); // 461715

// SUB
$time = new TimeInterval($convertToSeconds);
$time1 = new TimeInterval($days, TimeIntervalInterface::DAY);
$time2 = new TimeInterval($hours, TimeIntervalInterface::HOUR);
$time3 = new TimeInterval($minutes, TimeIntervalInterface::MINUTE);
$time4 = new TimeInterval($seconds, TimeIntervalInterface::SECOND);

// adding
$time->sub($time1)->sub($time2);
$time->sub($time3);
$time->sub($time4);

echo $time->convertToSeconds(); // 0

// Immutable
$timeImmutable = new TimeIntervalImmutable($convertToSeconds);
$time1 = new TimeInterval($days, TimeIntervalInterface::DAY);
$time2 = new TimeInterval($hours, TimeIntervalInterface::HOUR);
$time3 = new TimeInterval($minutes, TimeIntervalInterface::MINUTE);
$time4 = new TimeInterval($seconds, TimeIntervalInterface::SECOND);

$timeNew = $timeImmutable->sub($time1)->sub($time2)->sub($time3)->sub($time4);

echo $timeImmutable->convertToSeconds(); // 461715
echo $timeNew->convertToSeconds(); // 0

// Create from HMS
$time = TimeInterval::createFromHMS('24:05:15');
echo $time->convertToSeconds(); // 86715

$time = TimeInterval::createFromHMS('-24:05:15');
echo $time->convertToSeconds(); // -86715

// Create from date string
$time = TimeInterval::createFromDateString('24 hours + 5 minutes + 15 seconds');
echo $time->convertToSeconds(); // 86715

// Create from interval spec
$time = TimeInterval::createFromIntervalSpec('P1DT0H5M15S');
echo $time->convertToSeconds(); // 86715

// Format
$time = new TimeInterval($days, TimeIntervalInterface::DAY);
$time->modify($hours, TimeIntervalInterface::HOUR);
$time->modify($minutes, TimeIntervalInterface::MINUTE);
$time->modify($seconds, TimeIntervalInterface::SECOND);

echo $time->getHours(); // 128
echo $time->getMinutes(); // 15
echo $time->getSeconds(); // 15

echo $time->format('%H:%I:%S'); // 128:15:15
echo $time->format('%x min. %s sec.'); // 7695 min. 15 sec.

$timeNegative = new TimeInterval();
$timeNegative->sub($time);

echo $timeNegative->format('%r%H:%I:%S'); // -128:15:15
echo $timeNegative->format('%r%x min. %s sec.'); // -7695 min. 15 sec.

// convert TimeInterval to DateInterval
$time = new TimeInterval($convertToSeconds);

/** @var DateInterval $dateInterval */
$dateInterval = $time->createDateInterval();

All versions of timeinterval with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1|^8.0
ext-json Version *
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 korshunov/timeinterval contains the following files

Loading the files please wait ....