本文整理汇总了PHP中TimeHelper::secondsToGeneralTime方法的典型用法代码示例。如果您正苦于以下问题:PHP TimeHelper::secondsToGeneralTime方法的具体用法?PHP TimeHelper::secondsToGeneralTime怎么用?PHP TimeHelper::secondsToGeneralTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeHelper
的用法示例。
在下文中一共展示了TimeHelper::secondsToGeneralTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$joined_ts = strtotime($user->joined, TimeHelper::getTime());
$viable = $joined_ts > strtotime('2000-01-1');
$joined_day = date('m-d', $joined_ts);
$is_twitter = $instance->network == 'twitter';
if ($viable && $is_twitter && date('m-d', TimeHelper::getTime()) == $joined_day) {
$insight = new Insight();
$insight->slug = "twitterbirthday";
$insight->instance_id = $instance->id;
$insight->date = $this->insight_date;
$insight->emphasis = Insight::EMPHASIS_HIGH;
$insight->filename = basename(__FILE__, ".php");
$follow_dao = DAOFactory::getDAO('FollowDAO');
$all_friends = $follow_dao->countTotalFriends($instance->network_user_id, $instance->network);
$late_friends = $follow_dao->countTotalFriendsJoinedAfterDate($instance->network_user_id, $instance->network, $user->joined);
$years = date('Y', TimeHelper::getTime()) - date('Y', $joined_ts);
$ordinal_age = $this->terms->getOrdinalAdverb($years);
$insight->headline = "A Very Happy {$ordinal_age} Twitter Birthday!";
$insight->text = $this->username . " joined Twitter {$years} year" . ($years == 1 ? '' : 's') . " ago today";
if ($all_friends > 0 && $late_friends > 0) {
$percent_before = floor($late_friends / $all_friends * 100);
$insight->text .= ", " . "before " . $percent_before . "% of the people " . $this->username . " follows did.";
} else {
$insight->text .= ".";
}
$week_seconds = 60 * 60 * 24 * 7;
$followers = $follow_dao->getFriendsJoinedInTimeFrame($user->user_id, $instance->network, date('Y-m-d', $joined_ts - $week_seconds), date('Y-m-d', $joined_ts + $week_seconds));
$just_before = null;
$just_after = null;
$last_user = null;
foreach ($followers as $follower) {
if (strtotime($follower->joined, TimeHelper::getTime()) > $joined_ts) {
$just_after = $follower;
$just_before = $last_user;
break;
}
$last_user = $follower;
}
if (!$just_after && $last_user) {
$just_before = $last_user;
}
$bonus_text = array();
$people = array();
if ($just_before) {
$time = TimeHelper::secondsToGeneralTime(abs($joined_ts - strtotime($just_before->joined, TimeHelper::getTime())));
$bonus_text[] = "@" . $just_before->username . " just beat " . $this->username . ", joining {$time} earlier";
$people[] = $just_before;
}
if ($just_after) {
$time = TimeHelper::secondsToGeneralTime(abs($joined_ts - strtotime($just_after->joined, TimeHelper::getTime())));
$bonus_text[] = "@" . $just_after->username . " was a little slower, getting on Twitter {$time} later";
$people[] = $just_after;
}
if (count($bonus_text)) {
$insight->text .= " " . join(', and ', $bonus_text) . ".";
$insight->setPeople($people);
}
$res = $this->insight_dao->insertInsight($insight);
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例2: testSecondsToGeneralTime
public function testSecondsToGeneralTime()
{
$minute = 60;
$hour = 60 * $minute;
$day = $hour * 24;
$week = $day * 7;
$this->assertEqual('1 second', TimeHelper::secondsToGeneralTime(1));
$this->assertEqual('0 seconds', TimeHelper::secondsToGeneralTime(0));
$this->assertEqual('11 seconds', TimeHelper::secondsToGeneralTime(11));
$this->assertEqual('1 minute', TimeHelper::secondsToGeneralTime($minute));
$this->assertEqual('6 minutes', TimeHelper::secondsToGeneralTime($minute * 6));
$this->assertEqual('1 hour', TimeHelper::secondsToGeneralTime($hour));
$this->assertEqual('23 hours', TimeHelper::secondsToGeneralTime($hour * 23));
$this->assertEqual('1 day', TimeHelper::secondsToGeneralTime($hour * 26));
$this->assertEqual('3 days', TimeHelper::secondsToGeneralTime($day * 3));
$this->assertEqual('1 week', TimeHelper::secondsToGeneralTime($week));
$this->assertEqual('1 week', TimeHelper::secondsToGeneralTime($day * 8));
$this->assertEqual('3 weeks', TimeHelper::secondsToGeneralTime($day * 23));
$this->assertEqual('2 weeks', TimeHelper::secondsToGeneralTime($week * 2));
}
示例3: calculateTime
private function calculateTime($total)
{
// 45 minutes per posting, a rough estimate
return TimeHelper::secondsToGeneralTime($total * 45 * 60);
}