{"id":631,"date":"2008-04-23T14:17:49","date_gmt":"2008-04-23T13:17:49","guid":{"rendered":"http:\/\/pete.nu\/blog\/?p=631"},"modified":"2008-04-23T17:37:04","modified_gmt":"2008-04-23T16:37:04","slug":"possible-wordpress-date-formatting-bug","status":"publish","type":"post","link":"https:\/\/pete.nu\/blog\/2008\/04\/23\/possible-wordpress-date-formatting-bug\/","title":{"rendered":"Possible WordPress date formatting bug"},"content":{"rendered":"<p>As you have noticed, I do not display the time on my posts &#8211; just the date. However, anything published between midnight and 5am gets the words &#8220;in the small hours&#8221; appended to the datestamp, to indicate that even though it was technically posted on date D according to some atomic clock in a large city in Europe, it was posted on D-1 according to my internal daily rhythms.<\/p>\n<p>To implement this, I use the function `get_the_time(&#8216;G&#8217;)`. This should return a number between 0 and 23 which indicates the hour of the post&#8217;s timestamp. However, this stopped working, and it would actually return a very large number (of the order of about 1.1 billion) so the test failed. I don&#8217;t know whether this was caused by the upgrade to WordPress 2.5, or my recent move to a different server.<\/p>\n<p>I managed to &#8220;fix&#8221; the problem by commenting out the following few lines near the top of `mysql2date` (defined in `wp-includes\/functions.php`)<\/p>\n<p>    if( &#8216;G&#8217; == $dateformatstring ) {<br \/>\n        return gmmktime(<br \/>\n            (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),<br \/>\n            (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )<br \/>\n        );<br \/>\n    }<\/p>\n<p>However, this is not the ideal solution. Firstly, it&#8217;s hard to know if this change is causing a breakage elsewhere in the system (where the code relies upon this apparent bug). Secondly, when I upgrade to a new version of WordPress, I have to remember to fix the new `functions.php`<\/p>\n<p>I discovered a better solution to the problem. I put `functions.php` back to its original state, and then replaced my calls to `get_the_time(&#8216;G&#8217;)` with `get_the_time(&#8216;G &#8216;)` &#8211; note the added space. `$dateformatstring != &#8216;G&#8217;` but the function returns the desired result. Get in.<\/p>\n<p>I would report this on the <a href=\"http:\/\/wordpress.org\/support\/\">WordPress support forums<\/a> but I can&#8217;t be bothered to create an account.<\/p>\n<p>*Update: I&#8217;ve discovered that the offending block of code was added for WordPress 2.5 to address <a href=\"http:\/\/trac.wordpress.org\/ticket\/5970\">this issue<\/a>.*<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As you have noticed, I do not display the time on my posts &#8211; just the date. However, anything published between midnight and 5am gets the words &#8220;in the small hours&#8221; appended to the datestamp, to indicate that even though it was technically posted on date D according to some atomic clock in a large [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,27,2],"tags":[340],"class_list":["post-631","post","type-post","status-publish","format-standard","hentry","category-blogging","category-guidance","category-titgig","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/posts\/631","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/comments?post=631"}],"version-history":[{"count":0,"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/posts\/631\/revisions"}],"wp:attachment":[{"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/media?parent=631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/categories?post=631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pete.nu\/blog\/wp-json\/wp\/v2\/tags?post=631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}