protected function SamlauthConfigureForm::makeReadableDuration in SAML Authentication 8.3
Same name and namespace in other branches
- 4.x src/Form/SamlauthConfigureForm.php \Drupal\samlauth\Form\SamlauthConfigureForm::makeReadableDuration()
Converts number of seconds into a human readable 'duration' string.
Parameters
int $seconds: Number of seconds.
Return value
string The human readable duration description (e.g. "5 hours 3 minutes").
1 call to SamlauthConfigureForm::makeReadableDuration()
- SamlauthConfigureForm::buildForm in src/
Form/ SamlauthConfigureForm.php - Form constructor.
File
- src/
Form/ SamlauthConfigureForm.php, line 1639
Class
- SamlauthConfigureForm
- Provides a configuration form for samlauth module settings and IdP/SP info.
Namespace
Drupal\samlauth\FormCode
protected function makeReadableDuration($seconds) {
$calculation = [
'week' => 3600 * 24 * 7,
'day' => 3600 * 24,
'hour' => 3600,
'minute' => 60,
'second' => 1,
];
$duration = '';
foreach ($calculation as $unit => $unit_amount) {
$amount = (int) ($seconds / $unit_amount);
if ($amount) {
if ($duration) {
$duration .= ', ';
}
$duration .= "{$amount} {$unit}" . ($amount > 1 ? 's' : '');
}
$seconds -= $amount * $unit_amount;
}
return $duration;
}