Note that there are some explanatory texts on larger screens.

plurals
  1. POdate issue with PHP 4.4.8
    text
    copied!<p>Last week a released a 2.0 beta version of my Events Manager plugin, which produces a list of events. Among the many bugs floating around, there is one I cannot fix. The bug seems to manifest itself only on a tester's server with PHP 4.4.8; works allright on PHP 5. When I try to use the <code>H:i</code> php time format, I always get midnight (00:00). The issue is with the wordpress function mysql2date. This function is a wrapper around the date function.<br> I isolated the problem and inserted this in the website template:</p> <pre><code>echo (mysql2date("H:i", "0000-00-00 13:24:00")); </code></pre> <p>The result was </p> <pre><code>00:00 </code></pre> <p>At first I thought it was a wordpress bug, but then I rewrote my function to employ <code>date()</code> straightaway. The result was even stranger, instead of midnight I got <code>11:59</code>. Quite strangerly, both mysql2date and date seem to work allright on every other part of the plugin. Also, as I said, I cannot reproduce the bug on my server, only 2 users signalled it.</p> <p>Since I was asked, here's the mysql2date code; it's part of Wordpress:</p> <pre><code>/** * Converts MySQL DATETIME field to user specified date format. * * If $dateformatstring has 'G' value, then gmmktime() function will be used to * make the time. If $dateformatstring is set to 'U', then mktime() function * will be used to make the time. * * The $translate will only be used, if it is set to true and it is by default * and if the $wp_locale object has the month and weekday set. * * @since 0.71 * * @param string $dateformatstring Either 'G', 'U', or php date format. * @param string $mysqlstring Time from mysql DATETIME field. * @param bool $translate Optional. Default is true. Will switch format to locale. * @return string Date formated by $dateformatstring or locale (if available). */ function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { global $wp_locale; $m = $mysqlstring; if ( empty( $m ) ) return false; if( 'G' == $dateformatstring ) { return gmmktime( (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ), (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 ) ); } $i = mktime( (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ), (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 ) ); if( 'U' == $dateformatstring ) return $i; if ( -1 == $i || false == $i ) $i = 0; if ( !empty( $wp_locale-&gt;month ) &amp;&amp; !empty( $wp_locale-&gt;weekday ) &amp;&amp; $translate ) { $datemonth = $wp_locale-&gt;get_month( date( 'm', $i ) ); $datemonth_abbrev = $wp_locale-&gt;get_month_abbrev( $datemonth ); $dateweekday = $wp_locale-&gt;get_weekday( date( 'w', $i ) ); $dateweekday_abbrev = $wp_locale-&gt;get_weekday_abbrev( $dateweekday ); $datemeridiem = $wp_locale-&gt;get_meridiem( date( 'a', $i ) ); $datemeridiem_capital = $wp_locale-&gt;get_meridiem( date( 'A', $i ) ); $dateformatstring = ' ' . $dateformatstring; $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring ); $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); } $j = @date( $dateformatstring, $i ); /* if ( !$j ) // for debug purposes echo $i." ".$mysqlstring; */ return $j; } </code></pre> <p>If you're interested, you can download the code of my plugin <a href="http://downloads.wordpress.org/plugin/events-manager.zip" rel="nofollow noreferrer">here</a>, the problem is on line 613 of events-manager.php.</p> <p>Can this have something to do with PHP or apache settings?</p> <p>Thanks in advance for any suggestion.</p> <p>Davide</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload