TimeSpan
extends DateInterval
in package
implements
JsonSerializable, Stringable, IComparable, IEquatable
Represents a duration of time.
Table of Contents
Interfaces
- JsonSerializable
- Stringable
- IComparable
- Provides an interface for comparison between objects. Allows for order/sorting instances.
- IEquatable
- Provides an interface for determining the value-equality of two objects.
Methods
- __construct() : TimeSpan
- Creates a new instance of TimeSpan.
- __toString() : string
- Creates a string representation of this object.
- add() : TimeSpan
- Returns a new TimeSpan whose value is the sum of this instance and the provided instance.
- cast() : TimeSpan
- Makes sure a DateInterval inheriting object is a TimeSpan instance.
- compare() : int
- Compares the current instance with another and returns an integer that indicates whether the current object comes before or after or the same position and the other object.
- create() : TimeSpan
- Creates a new TimeSpan using the given parameters.
- createFromDateString() : TimeSpan
- Creates a TimeSpan from the relative parts of a string.
- divideFloat() : TimeSpan
- Returns the result of a division of this instance and the provided divisor.
- divideTimeSpan() : float
- Returns the result of a division of this instance and the provided instance.
- equals() : bool
- Checks whether the current object is equal to another.
- fromDays() : TimeSpan
- Creates a new TimeSpan instance that represents the specified number of days.
- fromHours() : TimeSpan
- Creates a new TimeSpan instance that represents the specified number of hours.
- fromMicroseconds() : TimeSpan
- Creates a new TimeSpan instance that represents the specified number of microseconds.
- fromMilliseconds() : TimeSpan
- Creates a new TimeSpan instance that represents the specified number of milliseconds.
- fromMinutes() : TimeSpan
- Creates a new TimeSpan instance that represents the specified number of minutes.
- fromSeconds() : TimeSpan
- Creates a new TimeSpan instance that represents the specified number of seconds.
- getDays() : int
- Gets the amount of days this TimeSpan represents.
- getHours() : int
- Gets the amount of hours this TimeSpan represents.
- getMicroseconds() : int
- Gets the amount of microseconds this TimeSpan represents.
- getMilliseconds() : int
- Gets the amount of milliseconds this TimeSpan represents.
- getMinutes() : int
- Gets the amount of minutes this TimeSpan represents.
- getSeconds() : int
- Gets the amount of seconds this TimeSpan represents.
- isNegative() : bool
- Gets whether this TimeSpan represents a negative amount of time.
- jsonSerialize() : mixed
- Returns the data which should be serialized as json.
- multiply() : TimeSpan
- Returns a new TimeSpan whose alue is the result of a multiplication of this oinstance and the provided factor.
- negate() : TimeSpan
- Return a new TimeSpan whose value is the negated value of this instance.
- subtract() : TimeSpan
- Returns a new TimeSpan whose value is the difference of this instance and the provided instance.
- totalDays() : float
- Counts the total amount of days this TimeSpan contains.
- totalHours() : float
- Counts the total amount of hours this TimeSpan contains.
- totalMicroseconds() : float
- Counts the total amount of microseconds this TimeSpan contains.
- totalMilliseconds() : float
- Counts the total amount of milliseconds this TimeSpan contains.
- totalMinutes() : float
- Counts the total amount of minutes this TimeSpan contains.
- totalSeconds() : float
- Counts the total amount of seconds this TimeSpan contains.
Methods
__construct()
Creates a new instance of TimeSpan.
public
__construct([string $duration = 'PT0S' ]) : TimeSpan
Parameters
- $duration : string = 'PT0S'
-
An ISO8601 duration string.
Return values
TimeSpan —A TimeSpan instance representing the given duration.
__toString()
Creates a string representation of this object.
public
__toString() : string
Return values
string —Representation of this object.
add()
Returns a new TimeSpan whose value is the sum of this instance and the provided instance.
public
add(DateInterval $timeSpan) : TimeSpan
Parameters
- $timeSpan : DateInterval
-
Interval to add.
Return values
TimeSpan —Instance that represents this instance plus the value of $timeSpan.
cast()
Makes sure a DateInterval inheriting object is a TimeSpan instance.
public
static cast(DateInterval $dateInterval) : TimeSpan
Parameters
- $dateInterval : DateInterval
-
Input object.
Return values
TimeSpan —If the input was a TimeSpan, the same instance will be returned. If the input was something else, a new TimeSpan instance will be returned based on the input.
compare()
Compares the current instance with another and returns an integer that indicates whether the current object comes before or after or the same position and the other object.
public
compare(mixed $other) : int
Parameters
- $other : mixed
Return values
int —A value that indicates the relative order of the objects being compared. Less than zero for before, zero for same position, greater than zero for after.
create()
Creates a new TimeSpan using the given parameters.
public
static create(int $days, int $hours, int $minutes, int $seconds[, int $micros = 0 ][, bool $negative = false ]) : TimeSpan
Parameters
- $days : int
-
Number of days.
- $hours : int
-
Number of hours.
- $minutes : int
-
Number of minutes.
- $seconds : int
-
Number of seconds.
- $micros : int = 0
-
Number of microseconds.
- $negative : bool = false
-
true for a negative TimeSpan, false for positive.
Return values
TimeSpan —A new TimeSpan from the provided parameters.
createFromDateString()
Creates a TimeSpan from the relative parts of a string.
public
static createFromDateString(string $dateTime) : TimeSpan
Uses the same parser as strtotime and the DateTime constructor internally.
Parameters
- $dateTime : string
-
A date with relative parts.
Return values
TimeSpan —A TimeSpan representing the given
divideFloat()
Returns the result of a division of this instance and the provided divisor.
public
divideFloat(float $divisor) : TimeSpan
Parameters
- $divisor : float
-
Value to divide by.
Return values
TimeSpan —Instance that represents this instance divided by the value of $divisor.
divideTimeSpan()
Returns the result of a division of this instance and the provided instance.
public
divideTimeSpan(DateInterval $timeSpan) : float
Parameters
- $timeSpan : DateInterval
-
Interval to be divided by.
Return values
float —$timeSpan Number that represents this instance divided by the value of $timeSpan.
equals()
Checks whether the current object is equal to another.
public
equals(mixed $other) : bool
Parameters
- $other : mixed
Return values
bool —true if the objects are equals, false if not.
fromDays()
Creates a new TimeSpan instance that represents the specified number of days.
public
static fromDays(float $days) : TimeSpan
Parameters
- $days : float
-
Number of days.
Return values
TimeSpan —Instance representing the provided number of days.
fromHours()
Creates a new TimeSpan instance that represents the specified number of hours.
public
static fromHours(float $hours) : TimeSpan
Parameters
- $hours : float
-
Number of hours.
Return values
TimeSpan —Instance representing the provided number of hours.
fromMicroseconds()
Creates a new TimeSpan instance that represents the specified number of microseconds.
public
static fromMicroseconds(float $micros) : TimeSpan
Parameters
- $micros : float
-
Number of microseconds.
Return values
TimeSpan —Instance representing the provided number of microseconds.
fromMilliseconds()
Creates a new TimeSpan instance that represents the specified number of milliseconds.
public
static fromMilliseconds(float $millis) : TimeSpan
Parameters
- $millis : float
-
Number of milliseconds.
Return values
TimeSpan —Instance representing the provided number of milliseconds.
fromMinutes()
Creates a new TimeSpan instance that represents the specified number of minutes.
public
static fromMinutes(float $minutes) : TimeSpan
Parameters
- $minutes : float
-
Number of minutes.
Return values
TimeSpan —Instance representing the provided number of minutes.
fromSeconds()
Creates a new TimeSpan instance that represents the specified number of seconds.
public
static fromSeconds(float $seconds) : TimeSpan
Parameters
- $seconds : float
-
Number of seconds.
Return values
TimeSpan —Instance representing the provided number of seconds.
getDays()
Gets the amount of days this TimeSpan represents.
public
getDays() : int
Return values
int —Amount of days.
getHours()
Gets the amount of hours this TimeSpan represents.
public
getHours() : int
Tags
Return values
intgetMicroseconds()
Gets the amount of microseconds this TimeSpan represents.
public
getMicroseconds() : int
Return values
int —Amount of microseconds.
getMilliseconds()
Gets the amount of milliseconds this TimeSpan represents.
public
getMilliseconds() : int
Return values
int —Amount of milliseconds.
getMinutes()
Gets the amount of minutes this TimeSpan represents.
public
getMinutes() : int
Return values
int —Amount of minutes.
getSeconds()
Gets the amount of seconds this TimeSpan represents.
public
getSeconds() : int
Return values
int —Amount of seconds.
isNegative()
Gets whether this TimeSpan represents a negative amount of time.
public
isNegative() : bool
Return values
bool —true if negative, false if positive.
jsonSerialize()
Returns the data which should be serialized as json.
public
jsonSerialize() : mixed
Tags
Return values
mixed —Data to be passed to json_encode.
multiply()
Returns a new TimeSpan whose alue is the result of a multiplication of this oinstance and the provided factor.
public
multiply(float $factor) : TimeSpan
Parameters
- $factor : float
-
Value to multiply with.
Return values
TimeSpan —Instance that represents this instance multiplied by the value of $factor.
negate()
Return a new TimeSpan whose value is the negated value of this instance.
public
negate() : TimeSpan
Return values
TimeSpan —Negated copy of this instance.
subtract()
Returns a new TimeSpan whose value is the difference of this instance and the provided instance.
public
subtract(DateInterval $timeSpan) : TimeSpan
Parameters
- $timeSpan : DateInterval
-
Interval to subtract.
Return values
TimeSpan —Instance that represents this instance minus the value of $timeSpan.
totalDays()
Counts the total amount of days this TimeSpan contains.
public
totalDays() : float
Return values
float —Total amount of days.
totalHours()
Counts the total amount of hours this TimeSpan contains.
public
totalHours() : float
Return values
float —Total amount of hours.
totalMicroseconds()
Counts the total amount of microseconds this TimeSpan contains.
public
totalMicroseconds() : float
Return values
float —Total amount of microseconds.
totalMilliseconds()
Counts the total amount of milliseconds this TimeSpan contains.
public
totalMilliseconds() : float
Return values
float —Total amount of milliseconds.
totalMinutes()
Counts the total amount of minutes this TimeSpan contains.
public
totalMinutes() : float
Return values
float —Total amount of minutes.
totalSeconds()
Counts the total amount of seconds this TimeSpan contains.
public
totalSeconds() : float
Return values
float —Total amount of seconds.