Download the PHP package iarcadia/time without Composer
On this page you can find all versions of the php package iarcadia/time. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download iarcadia/time
More information about iarcadia/time
Files in iarcadia/time
Informations about the package time
Time
Introduction
Time is A PHP time/duration library... again.
Currently, the library supports:
- Hours
- Minutes
- Seconds
- Milliseconds (+ Hundredth/Tenth of second)
The objective of this library is first to have something not related to dates at all, then to be light and simple.
Usage
Instantiation
With the new
keyword:
With the static method create
:
The given arguments are the same for both methods:
The static method will be used for the rest of the readme.
Time::create($h, $i, $s, $v)
Examples
Creating a Time of 17 hours and 19 minutes:
Creating a Time of 45 minutes, 12 seconds and 476 ms:
Time::create($int_or_float)
Examples
Creating a Time of 45 minutes, 12 seconds and 476 ms:
Formating
The format()
method is available to format and write your Time instance:
Also, here's the characters or groups of characters which are going to be formated:
-
will appear if the time is negativeh
into hoursii
into minutes with leading zeroi
into minutesss
into seconds with leading zeros
into secondsd
into tenth of secondscc
into hundredth of seconds with leading zeroc
into hundredth of secondsvvv
into milliseconds with leading zero(s)v
into milliseconds
Avoid a character to be translated by making it preceded by an antislash.
Examples
Getters & Setters
The library proposes to you two different kinds of getters, the classic ones and the total.
The classics will give you the capped int values, but the hours. Minutes won't be over 59 and milliseconds over 999.
The total getters will give you a float value.
The getters also can all be used with magic attributes.
The setters will override the current timestamp of the Time instance.
They are also available as magic attributes.
Negative times
Time instances can be negative at creation, just instantiate it with a negative timestamp.
Be aware that using Time::create()
with 4 arguments will not work as intented for a negative time.
Operations
Additions and substractions are possible with this library by using Time#addX()
and Time#subX()
methods.
You can also do these operations with other Time instances thanks to Time#addFromTime()
and Time#subFromTime()
.
Finally, shortcut methods exist : Time#add()
and Time#sub()
. These two methods accept many arguments at once, and accept integer/float values and Time object.
If 4 arguments are given, it will add/substract the same way as the instantiation with 4 arguments.
The library proposes the Time#diff()
and Time::diffBetween()
methods to calculate difference between to times.
This feature is quite the same as Time#sub()
, the only difference is that they return a new Time instance.
Comparisons
You can compare two times by using comparison methods.