/** * Time difference of one week */ public function testTimeDiffWeek() { $lastWeek = strtotime('-1 week'); $now = strtotime('now'); $result = questions_time_diff($lastWeek, $now); $this->assertEqual($result, 3600 * 8 * 5); }
/** * Calculate the time that was needed to answer this question * * @return float $answerTime */ public function calculateAnswerTime() { $question = $this->getQuestion(); if ($previousAnswers = $question->getIntAnswers()) { $latestAnswer = $previousAnswers[0]; if ($question->workflowStart > $latestAnswer->time_created) { $startTime = $question->workflowStart; } else { $startTime = $latestAnswer->time_created; } } else { $startTime = $question->workflowStart; } return questions_time_diff($startTime, time()); }
/** * Get the total number of hours a question is open * * @return int hours */ public function getWorkflowLatestTotalTime() { if ($this->isWorkflowOpen()) { return questions_time_diff($this->workflowStart, time()); } else { if ($this->totalAnswerTimes) { $totalAnswerTimes = unserialize($this->totalAnswerTimes); return end($totalAnswerTimes); } else { return 0; } } }