# Time 1.0.3+

# TC\ComponentLibrary\Util\Time

# Flags

Flag Value Description
ALL 0x3F Display all time units in results.
SECONDS 0x1 Display seconds in results.
MINUTES 0x2 Display minutes in results.
HOURS 0x4 Displauy hours in results.
DAYS 0x8 Display days in results.
MONTHS 0x10 Display months in results.
YEARS 0x20 Display years in results.
NO_ZEROS 0x800 Removing zeros from results.
NO_FIRST_ZEROS 0x1000 Removing insignificant zeros from results.

# Constants

Constants Value
FORMAT_STR {years_phrased} {months_phrased} {days_phrased} {hours_phrased} {minutes_phrased} {seconds_phrased}

# timeToArray

Converts time in seconds to years, months, days, hours, minutes and seconds.

public static function timeToArray(int $time, int $flags = self::ALL): array

# Arguments

Argument Type Default value Description
time int Time to convert (in seconds).
flags int self::ALL | self::NO_FIRST_ZEROS See Flags.

# Examples

# Simple conversion
print_r(
    \TC\ComponentLibrary\Util\Time::timeToArray(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000
    )
);

/*
Array
(
    [years] => 3
    [months] => 1
    [days] => 0
    [hours] => 14
    [minutes] => 37
    [seconds] => 13
    [invert] => false
)
*/
# Retrieving only certain values
$time = \TC\ComponentLibrary\Util\Time::class;
print_r(
    $time::timeToArray(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
        $time::DAYS | $time::HOURS | $time::MINUTES
    )
);

/*
Array
(
    [years] => 0
    [months] => 0
    [days] => 1125
    [hours] => 14
    [minutes] => 37
    [seconds] => 0
    [invert] => false
)
*/

# timeToString

Converts a time to a string.

public static function timeToString(int $time, string $format = self::FORMAT_STR, int $flags = self::ALL | self::NO_FIRST_ZEROS): string

# Arguments

Argument Type Default value Description
time int Time to convert (in seconds).
format string self::FORMAT_STR Output format.
The following placeholders are available:
⋅ {seconds}, {minutes}, {hours}, {days}, {months}, {years} — values returned by the timeToArray method.
⋅ {seconds_phrased}, {minutes_phrased}, {hours_phrased}, {days_phrased}, {months_phrased}, {years_phrased} — phrases for these values.
flags int self::ALL | self::NO_FIRST_ZEROS See Flags.

# Examples

# Simple conversion
print_r(
    \TC\ComponentLibrary\Util\Time::timeToString(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000
    )
);

// 3 years 1 month 0 days 14 hours 37 minutes 13 seconds
# Removing all zeros from results
$time = \TC\ComponentLibrary\Util\Time::class;
print_r(
    $time::timeToString(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400,
        $time::FORMAT_STR,
        $time::ALL | $time::NO_ZEROS
    )
);

// 1 month 14 hours 37 minutes 13 seconds
# Retrieving only certain values
$time = \TC\ComponentLibrary\Util\Time::class;
print_r(
    $time::timeToString(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
        $time::FORMAT_STR,
        $time::DAYS | $time::HOURS | $time::MINUTES
    )
);

// 1125 days 14 hours 37 minutes
# Custom format
$time = \TC\ComponentLibrary\Util\Time::class;
print_r(
    $time::timeToString(
        13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
        '{hours}:{minutes}:{seconds}',
        $time::HOURS | $time::MINUTES | $time::SECONDS
    )
);

// 27014:37:13

# Templater functions

# tc_time_to_string

Converts a time to a string.

# Arguments

Argument Type Default value Description
time int Time to convert (in seconds).
format string $xf.tcTime.FORMAT_STR Output format.
The following placeholders are available:
⋅ {seconds}, {minutes}, {hours}, {days}, {months}, {years} — values returned by the timeToArray method.
⋅ {seconds_phrased}, {minutes_phrased}, {hours_phrased}, {days_phrased}, {months_phrased}, {years_phrased} — phrases for these values.
flags int $xf.tcTime.ALL + $xf.tcTime.NO_FIRST_ZEROS See Flags.

# Example

# Simple conversion
{{ tc_time_to_string(13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000) }}

<!-- 3 years 1 month 0 days 14 hours 37 minutes 13 seconds -->
# Removing all zeros from results
{{ tc_time_to_string(
    13 + 37 * 60 + 14 * 3600 + 30 * 86400,
    $xf.tcTime.FORMAT_STR,
    $xf.tcTime.ALL + $xf.tcTime.NO_ZEROS
) }}

<!-- 1 month 14 hours 37 minutes 13 seconds -->
# Retrieving only certain values
{{ tc_time_to_string(
    13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
    $xf.tcTime.FORMAT_STR,
    $xf.tcTime.DAYS + $xf.tcTime.HOURS + $xf.tcTime.MINUTES
) }}

<!-- 1125 days 14 hours 37 minutes -->
# Custom format
{{ tc_time_to_string(
    13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
    '{hours}:{minutes}:{seconds}',
    $xf.tcTime.HOURS + $xf.tcTime.MINUTES + $xf.tcTime.SECONDS
) }}

<!-- 27014:37:13 -->