MyBB Community Forums

Full Version: $timenow Calculation/Timezones
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The calculation for the "Current Time" language variable in global.php does not appear to be respecting timezones.

// Set the current date and time now
$datenow = my_date($mybb->settings['dateformat'], TIME_NOW, 0, false);
$timenow = my_date($mybb->settings['timeformat'], TIME_NOW);
$lang->welcome_current_time = $lang->sprintf($lang->welcome_current_time, $datenow . $lang->comma . $timenow);

I believe it should be
$timenow = my_date($mybb->settings['timeformat'], TIME_NOW, null);

based on the way the function is defined in functions.php, the if will only evaluate true if the $offset is null. When the parameter is not specified, as in global.php, it defaults to 0 and skips the timezone calculation.
if(!$offset && $offset != '0')

I did a quick search on the forums and github and do not see this logged as an issue anywhere. I installed a clean copy of MyBB 1.8.6 to ensure it was not an existing plugin/modification causing the problem.

Edit: On second thought, perhaps the 0 should be null as well in the date calculation so the day flips at the right time.
The code appears to be correct in 1.8.6:
$datenow = my_date($mybb->settings['dateformat'], TIME_NOW, '', false);
It's the $timenow that's incorrect
$timenow = my_date($mybb->settings['timeformat'], TIME_NOW);
There is nothing wrong with that. my_date uses the timezone by default.
(2016-02-24, 07:20 PM)StefanT Wrote: [ -> ]There is nothing wrong with that. my_date uses the timezone by default.

It does not. The parameter is omitted so it's using the default offset of 0
function my_date($format, $stamp=0, $offset=0, $ty=1, $adodb=false)

With a default of zero, it skips the block where it calculates the offset based on the timezone. 0 != 0 is a false statement.
if(!$offset && $offset != '0') { 
I don't know what you're testing, but definitely not MyBB 1.8.6... https://github.com/mybb/mybb/blob/featur...s.php#L332 I can't also reproduce it neither on my testing forum, nor here. So marking as rejected, unless you have more info (such as detailed reproduction steps on a clean forum) to share.
Apparently I have an old version of the files somehow. The definitions in the github link you provided doesn't match mine. Thanks for clearing that up.
This bug has been in a development version but never made it into a release: https://github.com/mybb/mybb/commit/f0e9...435b25fc6d
Edit: Figured it out, thanks.