Interval
Interval
Interval utility class.
This class provides a number of helper functions for working with time intervals.
Methods
seconds
Convert a string interval to seconds.
public seconds(string $interval): intThis function can be used to convert a string interval such as '1 week' into seconds. Currently supported intervals are seconds, minutes, hours, days and weeks. Months are not supported because some crazy crackpot decided to make them all different lengths, so without knowing which month we're talking about, converting them to seconds is impossible.
Multiple interval support is also possible. Intervals can be separated with a comma (,) or the word 'and', for example:
$foo = seconds('1 week, 2 days');
$bar = seconds('1 week and 2 days');Both of these function calls will yeild the same result.
Parameters
| Parameter | Type | Description |
|---|---|---|
$interval | string | The string interval to convert to seconds |
minutes
Convert interval to minutes.
public minutes(int $interval): floatSame as the seconds function except returns the number of minutes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$interval | int |
hours
Convert interval to hours.
public hours(int $interval): floatSame as the seconds function except returns the number of hours.
Parameters
| Parameter | Type | Description |
|---|---|---|
$interval | int |
days
Convert interval to days.
public days(int $interval): floatSame as the seconds function except returns the number of days.
Parameters
| Parameter | Type | Description |
|---|---|---|
$interval | int |
weeks
Convert interval to weeks.
public weeks(int $interval): floatSame as the seconds function except returns the number of weeks.
Parameters
| Parameter | Type | Description |
|---|---|---|
$interval | int |
years
Convert interval to years.
public years(int $interval): floatSame as the seconds function except returns the number of years.
Parameters
| Parameter | Type | Description |
|---|---|---|
$interval | int |
age
Get the age of a date.
public age(string $date): intThis helper function will return the number of years between a specified date and now. Useful for getting an age.
Parameters
| Parameter | Type | Description |
|---|---|---|
$date | string |
toString
Return a string interval in a nice readable format.
public toString(mixed $seconds): stringSimilar to uptime() this extends the format into a complete string in a nice, friendly readable format.
Parameters
| Parameter | Type | Description |
|---|---|---|
$seconds | mixed | the interval to convert in seconds |
uptime
Convert interval to uptime string.
public uptime(int $interval): stringThis function will convert an integer of seconds into an uptime string similar to what is returned by the unix uptime command. ie: '9 days 3:32:02'
Parameters
| Parameter | Type | Description |
|---|---|---|
$interval | int |
Generated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000