Cut-off point for Time Since plugin

Written . Tagged PHP, WordPress.

I’m helping my girlfriend set up an 18th century blog. I’m currently playing around with how to present dates and times for posts and comments. It’s an interesting usability question, what with different time zones.

The Time Since plugin displays relative times like “1 hour, 23 minutes ago”. I like this, but I want a cut-off point. Times older than some number of days (or hours, seconds, whatever) should be displayed absolute.

The plugin doesn’t support this out of the box, but it’s a very easy fix.

Simply change the code for displaying the time into something like this:

<?php if (function_exists('time_since') && (time() - get_the_time('U') < 60*60*24*7)) { // If < 7 days ago ?>
  <?php echo time_since(abs(strtotime($post->post_date_gmt . " GMT")), time()) ?> ago
<?php } else { ?>
  <?php the_time('M jS, Y') ?> at <?php the_time('H:i') ?>
<?php } ?>

The 60*60*24*7 bit is the cut-off age – 7 days, in seconds.

Incidentally, that blog displays the absolute time in user local time per Johan’s insights. I’ll likely blog that later.