#
Time
1.0.3+
#
TC\ComponentLibrary\Util\Time
#
Flags
#
Constants
Flags and $xf.tcTime
variables.
#
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
#
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
#
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
#
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 -->