/** * Return the post date and time of a topic * * @since bbPress (r4155) * * @param int $topic_id Optional. Topic id. * @param bool $humanize Optional. Humanize output using time_since * @param bool $gmt Optional. Use GMT * @uses bbp_get_topic_id() To get the topic id * @uses get_post_time() to get the topic post time * @uses bbp_time_since() to maybe humanize the topic post time * @return string */ function bbp_get_topic_post_date($topic_id = 0, $humanize = false, $gmt = false) { $topic_id = bbp_get_topic_id($topic_id); // 4 days, 4 hours ago if (!empty($humanize)) { $gmt = !empty($gmt) ? 'G' : 'U'; $date = get_post_time($gmt, $topic_id); $time = false; // For filter below $result = bbp_time_since($date); // August 4, 2012 at 2:37 pm } else { $date = get_post_time(get_option('date_format'), $gmt, $topic_id); $time = get_post_time(get_option('time_format'), $gmt, $topic_id); $result = sprintf(_x('%1$s at %2$s', 'date at time', 'bbpress'), $date, $time); } return apply_filters('bbp_get_topic_post_date', $result, $topic_id, $humanize, $gmt, $date, $time); }
/** * @covers ::bbp_time_since * @covers ::bbp_get_time_since */ public function test_bbp_time_since_timezone() { $now = time(); $then = $now - 1 * HOUR_IN_SECONDS; $since = '1 hour ago'; // Backup timezone. $tz_backup = date_default_timezone_get(); // Set timezone to something other than UTC. date_default_timezone_set('Europe/Paris'); // Output. $this->expectOutputString($since); bbp_time_since($then, $now); // Formatted. $this->assertSame($since, bbp_get_time_since($then, $now, true)); // Revert timezone back to normal. if ($tz_backup) { date_default_timezone_set($tz_backup); } }
/** * Output for Akismet History metabox * * @since bbPress (r5049) * * @uses get_post_history() To get the Akismet history for the post * @uses get_the_ID() To get the post ID * @uses bbp_time_since() To get the human readable time */ public function history_metabox() { // Post ID $history = $this->get_post_history(get_the_ID()); ?> <div class="akismet-history" style="margin: 13px 0;"> <?php if (!empty($history)) { ?> <table> <tbody> <?php foreach ($history as $row) { ?> <tr> <td style="color: #999; text-align: right; white-space: nowrap;"> <span title="<?php echo esc_attr(date('D d M Y @ h:i:m a', $row['time']) . ' GMT'); ?> "> <?php bbp_time_since($row['time'], false, true); ?> </span> </td> <td style="padding-left: 5px;"> <?php echo esc_html($row['message']); ?> </td> </tr> <?php } ?> </tbody> </table> <?php } else { ?> <p><?php esc_html_e('No recorded history. Akismet has not checked this post.', 'bbpress'); ?> </p> <?php } ?> </div> <?php }