You are here

public function ForcePasswordChangeService::getTextDate in Force Password Change 8

Same name and namespace in other branches
  1. 2.0.x src/Service/ForcePasswordChangeService.php \Drupal\force_password_change\Service\ForcePasswordChangeService::getTextDate()

*

Overrides ForcePasswordChangeServiceInterface::getTextDate

File

src/Service/ForcePasswordChangeService.php, line 251

Class

ForcePasswordChangeService

Namespace

Drupal\force_password_change\Service

Code

public function getTextDate($seconds) {
  $year = 60 * 60 * 24 * 365;
  if ($timestamp % $year === 0) {
    $time_period = $timestamp / $year;
    $time_period = $time_period > 1 ? $time_period . ' ' . t('years') : t('year');
  }
  else {
    $week = 60 * 60 * 24 * 7;
    if ($timestamp % $week === 0) {
      $time_period = $timestamp / $week;
      $time_period = $time_period > 1 ? $time_period . ' ' . t('weeks') : t('week');
    }
    else {
      $day = 60 * 60 * 24;
      if ($timestamp % $day === 0) {
        $time_period = $timestamp / $day;
        $time_period = $time_period > 1 ? $time_period . ' ' . t('days') : t('day');
      }
      else {
        $hour = 60 * 60;
        if ($timestamp % $hour === 0) {
          $time_period = $timestamp / $hour;
          $time_period = $time_period > 1 ? $time_period . ' ' . t('hours') : t('hour');
        }
      }
    }
  }
  return $time_period;
}