Download the PHP package vdhicts/time without Composer

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

Time

This package aims to make working with times (as in date, ranges and/or duration) easier. It contains a time value-object, parser, ranges, duration, rounding, etc.

Requirements

This package requires PHP 8.1 or higher.

Installation

You can install the package via composer:

composer require vdhicts/time

Usage

This package aims to provide an easy usage, with some similarities with PHP's DateTime and Carbon. An example of that are the interfaces.

Time

The Time object can be initiated with:

Building from input

To build the Time object from several different inputs, you can use the following methods:

Comparison

The Time object makes it easy to compare to other Time objects. It offers the following methods:

Difference

The time object can also be used to calculate the difference between time objects:

The difference can be calculated in hours (diffInHours), minutes (diffInMinutes) and seconds (diffInSeconds).

Duration

A time can be part of a date, i.e. 2022-03-01 10:00:00 but can also be used for a duration, i.e. "It took me 1 hour and 46 minutes to get there.".

Results in:

Rounding

Working with very specific times might not always be the result you want, for example for time tracking. This package allows you to round the time to your likings. By default, it rounds to 5 minutes:

It's also possible to round the seconds and/or change the precision. For example, round to 15 seconds:

Presentation

The Time object can be presented as a string with the toString method or just casting the object to a string (string)$time. This will output: 14:30:15.

There are also two other presentations available, the toNumericalTime and toReadableTime:

Time collection

Time objects can be collected in a TimeCollection. The TimeCollection ca be initiated with:

It's possible to provide an array of Time objects or to use the add and set methods on the collection. The contains method provides the ability to check if the collection contains a Time object.

Time range

A TimeRange object contains two Time objects, a start and end time. The TimeRange object can be initiated with:

To get the duration of the range, you can get the Time object as duration with:

Comparison

The TimeRange object makes it easy to compare to a single Time or another TimeRange.

To determine if a Time is in a range:

To determine if another range overlaps the range:

Tests

Unit tests are available in the tests folder. Run with:

composer test

When you want a code coverage report which will be generated in the build/report folder. Run with:

composer test-coverage

Contribution

Any contribution is welcome, but it should meet the PER 2.0 code style and please create one pull request per feature/bug. In exchange, you will be credited as contributor.

Security

If you discover any security related issues in this or other packages of Vdhicts, please email [email protected] instead of using the issue tracker.

License

This package is open-sourced software licensed under the MIT license


All versions of time with dependencies

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

Loading the files please wait ....