Exemplo n.º 1
0
 /**
  * For a given number of posts, generate insight text
  *
  * @param int $number_of_posts How many posts
  * @return str The insight text
  */
 private function postsToInsightText($number_of_posts)
 {
     $posting_seconds = $number_of_posts * 15;
     $insight_text = 'That\'s over<strong>';
     $posting_time = TimeHelper::secondsToExactTime($posting_seconds);
     if ($posting_time["d"]) {
         $insight_text .= ' ' . $posting_time["d"] . ' day' . ($posting_time["d"] > 1 ? 's' : '');
     }
     if ($posting_time["h"]) {
         $insight_text .= ' ' . $posting_time["h"] . ' hour' . ($posting_time["h"] > 1 ? 's' : '');
     }
     if ($posting_time["m"]) {
         $insight_text .= ' ' . $posting_time["m"] . ' minute' . ($posting_time["m"] > 1 ? 's' : '');
     }
     $insight_text .= '</strong> of ' . $this->username . '\'s life.';
     return $insight_text;
 }
Exemplo n.º 2
0
 public function testSecondsToExactTime()
 {
     $minute = 60;
     $hour = 60 * $minute;
     $day = $hour * 24;
     $week = $day * 7;
     $result = array('d' => 0, 'h' => 0, 'm' => 0, 's' => 1);
     $this->assertEqual($result, TimeHelper::secondsToExactTime(1));
     $result = array('d' => 0, 'h' => 0, 'm' => 0, 's' => 0);
     $this->assertEqual($result, TimeHelper::secondsToExactTime(0));
     $result = array('d' => 0, 'h' => 0, 'm' => 0, 's' => 11);
     $this->assertEqual($result, TimeHelper::secondsToExactTime(11));
     $result = array('d' => 0, 'h' => 0, 'm' => 1, 's' => 11);
     $this->assertEqual($result, TimeHelper::secondsToExactTime(60 + 11));
     $result = array('d' => 0, 'h' => 0, 'm' => 6, 's' => 11);
     $this->assertEqual($result, TimeHelper::secondsToExactTime(60 * 6 + 11));
     $result = array('d' => 0, 'h' => 1, 'm' => 6, 's' => 11);
     $this->assertEqual($result, TimeHelper::secondsToExactTime(60 * 60 + 60 * 6 + 11));
     $result = array('d' => 0, 'h' => 23, 'm' => 6, 's' => 11);
     $this->assertEqual($result, TimeHelper::secondsToExactTime(23 * (60 * 60) + 60 * 6 + 11));
     $result = array('d' => 2, 'h' => 0, 'm' => 6, 's' => 11);
     $this->assertEqual($result, TimeHelper::secondsToExactTime(48 * (60 * 60) + 60 * 6 + 11));
 }
Exemplo n.º 3
0
 public function getPostingTime($total_posts)
 {
     $posting_seconds = $total_posts * 15;
     $time_array = array();
     $posting_time = TimeHelper::secondsToExactTime($posting_seconds);
     if ($posting_time["d"]) {
         $time_array[] = $posting_time["d"] . ' day' . ($posting_time["d"] > 1 ? 's' : '');
     }
     if ($posting_time["h"]) {
         $time_array[] = $posting_time["h"] . ' hour' . ($posting_time["h"] > 1 ? 's' : '');
     }
     if ($posting_time["m"]) {
         $time_array[] = $posting_time["m"] . ' minute' . ($posting_time["m"] > 1 ? 's' : '');
     }
     return $this->makeList($time_array);
 }