{"id":1362,"date":"2009-11-17T14:03:47","date_gmt":"2009-11-17T05:03:47","guid":{"rendered":"https:\/\/regex.info\/blog\/other-writings\/timesince"},"modified":"2009-11-17T14:05:30","modified_gmt":"2009-11-17T05:05:30","slug":"timesince","status":"publish","type":"page","link":"https:\/\/regex.info\/blog\/other-writings\/timesince","title":{"rendered":"A Non-Stupid &#8220;Time Since&#8221; Plugin for WordPress"},"content":{"rendered":"\n\n<p>On my blog, I like post and comment dates to include an &#8220;....ago&#8221;\ndescription. I've not cared for any of the simpleton solutions I've seen so\nfar, so I wrote my own plugin for WordPress to provide this.<\/p>\n\n<p>The problem with most time-span computations I've seen is that they\nsimply subtract one time from another to get a total number of elapsed\nseconds, then start dividing to get the time-unit components (e.g. divide\nby 60 to get the elapsed number of minutes). This is fine for durations up\nto 28 days, but past that the definition of &#8220;one month&#8221; is dependent on the\nspecific dates involved.<\/p>\n\n<p>My plugin handles this computation properly, and also brings some common\nsense into how time spans are reported. For example, if something happened\n&#8220;1 hour, 17 minutes ago&#8221;, the extra 17 minutes is a lot more relevant than\nin &#8220;22 hours, 17 minutes&#8221;. My plugin reports the latter simply as &#8220;22\nhours&#8221;.<\/p>\n\n<p>Of course, when something happend a few weeks or months or years ago,\nhours and minutes are not relevent at all, so they're not even shown.<\/p>\n\n<p>Here it is: &nbsp;&nbsp;<a style='border:solid 1px #833; padding: 2px 1em 4px 1em' href='\/code\/jeffreys-timesince-v1.1.php'>jeffreys-timesince.php v1.1<\/a><\/p>\n\n\n<p>My plugin is a drop-in replacement for what I used to use, <a\nhref='http:\/\/binarybonsai.com\/wordpress\/time-since\/'>Dunstan Orchard's\n&#8220;Time Since&#8221; plugin<\/a>, which is no longer supported.<\/p>\n\n<p>Here's how I use it, from my <b>post.php<\/b> theme file:<\/p>\n\n<div style='border:solid 1px #444; margin:0px 1em'>\n<pre style='color:#999;font-size:85%'>\n &lt;div class=\"post_timestamp\"&gt;\n   &lt;span class=\"post_date\"&gt;&lt;?php the_time('F jS, Y') ?&gt;&lt;\/span&gt;\n   &lt;span class=\"post_time\"&gt;&lt;?php the_time('g:ia') ?&gt;&lt;\/span&gt;\n   &lt;span class=\"post_tz\"&gt;JST&lt;\/span&gt;\n   &lt;span class=\"post_ago\"&gt;(<span style='color:white'>&lt;?php echo time_since(abs(strtotime($post-&gt;post_date_gmt . \" GMT\")), time()); ?&gt; ago)<\/span>&lt;\/span&gt;\n &lt;\/div&gt;\n<\/pre>\n<\/div>\n\n<p>Your timestamp section likely looks different (WordPress didn't handle\ntimezones well when I set up my blog, so I had to force some things;\nhopefully it's better now), but the highlighted section can be dropped in\nwherever you like within <i>the loop<\/i>.<\/p>\n\n<p>It's used in a similar way in other files that display timestamps, such\nas index, archive, and comment pages.<\/p>\n\n<p>I've published one other WordPress plugin: &#8220;<a href='\/blog\/other-writings\/wordpress-file-based-posts-plugin'>File-based Posts<\/a>&#8221;<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>On my blog, I like post and comment dates to include an \"....ago\" description. I've not cared for any of the simpleton solutions I've seen so far, so I wrote my own plugin for WordPress to provide this.<\/p> <p>The problem with most time-span computations I've seen is that they simply subtract one time from another to get a total number of elapsed seconds, then start dividing to get the time-unit components (e.g. divide by 60 to get the elapsed number of minutes). This is fine for durations up to 28 days, but past that the definition of \"one month\" is [...]","protected":false},"author":1,"featured_media":0,"parent":51,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/pages\/1362"}],"collection":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/comments?post=1362"}],"version-history":[{"count":0,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/pages\/1362\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/pages\/51"}],"wp:attachment":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/media?parent=1362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}