# How long ago adds $howlongago to entries, containing a string that reads: # # Posted config['date_format'] if you're viewing an entry's permalink. # Posted N minutes ago if the entry was posted less than 1 hour ago. # Posted H hours M minutes ago if the entry was posted less than 24 hours ago. # Posted n days ago if the post was not posted today and it was posted more than 24 hours ago. def cb_story( app ) entry = app['entry'] return if app.getValue( 'notime',entry ) posttime = entry.getPostTime currtime = Time::now howlongago = "Posted " ispermalink = app.isPermalink?( app['PATH_INFO'] ) if not ispermalink seconds = currtime.utc - posttime.utc if ( seconds >= 86400 ) days = Integer( seconds / 86400 ) now = Time::now daytime = seconds - ( days * 86400 ) if ( now - daytime ).localtime.day != now.localtime.day $stderr.write( "Adding a day.\n" ) days = days + 1 end howlongago += days.to_s + " day" howlongago += "s" if days > 1 else hours = Integer( seconds / 3600 ) minutes = Integer( ( seconds % 3600 ) / 60 ) howlongago += hours.to_s + " hour" if hours > 0 howlongago += "s" if hours > 1 howlongago += " " + minutes.to_s + " minute" howlongago += "s" if minutes != 1 end howlongago += " ago" else howlongago += posttime.localtime.strftime( app['date_format'] ) # + " at " + posttime.localtime.strftime( "%I:%M %p" ) end entry['howlongago'] = howlongago return end