News:

Wondering if this will always be free?  See why free is better.

Main Menu

Forum time off - server time right - no offset

Started by straxus, April 03, 2008, 05:23:42 PM

Previous topic - Next topic

straxus

My server time right now: Thu Apr  3 16:20:46 CDT 2008
My forum time: April 03, 2008, 03:20:46 pm
My Profile Time Offset: 0
Forum Overall time offset: 0

How do I account for this one hour discrepancy?

greyknight17

Change it in the forum overall offset...by 1.

straxus

That's what I've done.  But it doesn't explain what has happened.

From what I understand, SMF pulls it's time directly from the server time.  They should match up if there is 0 offset, and they did until just recently.  I don't know exactly when or why it happened, unfortunately.

If I learn anything more or if something else develops, I'll post an update.

greyknight17

You can try asking your host to see if it's something they are aware of. If you didn't touch any of the settings, it should be pulling directly from their server.

straxus

Actually, it's my own server.  I haven't noticed anything else out of the ordinary yet.

Tony Reid

Your server probably has system time and hardware time offset - try synchronising them.
Tony Reid

straxus

# hwclock
Wed 09 Apr 2008 03:20:40 PM CDT  -0.875729 seconds
# date
Wed Apr  9 15:20:40 CDT 2008


They appear to be in sync.

Rumbaar

You sure there isn't some type of Daylight Savings setting elsewhere on your server adjusting the time output to SMF?  We did recently have the period of the year where that is adjusted.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

straxus

Quote from: Rumbaar on April 14, 2008, 05:55:31 AM
You sure there isn't some type of Daylight Savings setting elsewhere on your server adjusting the time output to SMF?  We did recently have the period of the year where that is adjusted.

I'm not sure.  I've got a basic Debian install running LAMP, Bind, Postfix, Courier, and little else.  If there is something adjusting the time shown to SMF, it would almost have to be something installed by default in Debian.  I'm at a loss as to what that could be. 

metallica48423

were you ever able to figure this out?

I seem to recall a bug with time under certain circumstances but i have not been able to find the post nor the bugtracker entry regarding it.  (so in that light, take it for what it is worth).

It may be possible that php is sticking on one time and not following the server... its a longshot...

if you do this


<?php

$time 
time();
$time strftime('%B %d, %Y, %I:%M %p'$time);

echo 
$time;

?>



what do you get?
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Gorm

I have a similar problem (forum shows 1 hour less than the server time even though time offset is set to 0 both in forum and profile setting). I tried the php string above and got the correct server time. Help!  ::)

/Johan

TaskyZZ

I also have this problem.  Th eonly reason I even noticed it is because I am making a MOD and it is spitting out the wrong time.  When writing a MOD, what do I need to add to the time output to account for that global timne offset setting?  Is there a global variable I need to add?

metallica48423

you should be able to pass it through the timeformat() function -- it will take into account offset and their personal time format settings. -- but you have to pass it a timestamp.
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

TaskyZZ

I have figured out what was causing my time being off by 1 hour issue.  It turns out that there is a setting for default_Timezone in the database, and if it has been set, then the php scripting is set to that timezone.  Once I deleted that entry from the database, my time issues went away.

What sets this timezone entry?  Can any mod or theme set this entry?  I think this setting needs to be available on the standard Features and Options page in the Admin area so it can be found easily if it gets set for some reason.

TaskyZZ

Oh yes, thanks for letting me know about the timeformat() function.  I will look into using it for my time display needs on my MODs.

volswagn

I just had to post here and say THANK YOU TASKYZZ for figuring this out. It's been annoying me for over a year now. The offset seemed like such a "hack," I knew something was wrong. Server time was right, php.ini and my.cnf both set to the same (EST5EDT), the php code above from metallica was showing the right time...

One quick search of the smf database and sure enough, default time zone was set! As soon as I deleted it, PRESTO... My forum time was the same as my server time, php time and mysql time, as it should be!

This should DEFINITELY be available via the GUI. Otherwise, how would anyone know about it other than from your post? It certainly seems to be a question that's asked a lot on this board, but rarely answered.

Thanks again!

Rumbaar

This is the only occurrence of that setting in SMF:
Load.php
// Setting the timezone is a requirement for some functions in PHP >= 5.1.
if (isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
date_default_timezone_set($modSettings['default_timezone']);

And appears to be automatically set based on the version of php bring run at the time.  Now if the version of php is updated, and the setting as been set I'm sure this where the conflict might arise.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

Jade E.

Sorry to resurrect an older thread, but I just installed SMF for the first time and this problem was bugging me as well.  I've traced down the root cause, for my case at least.  At line 783 in the install.php file, it attempts to detect and save the current time zone thus:

        // As of PHP 5.1, setting a timezone is required.
        if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
        {
                $server_offset = mktime(0, 0, 0, 1, 1, 1970);
                $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
                if (date_default_timezone_set($timezone_id))
                        mysql_query("
                                REPLACE INTO {$db_prefix}settings
                                        (variable, value)
                                VALUES
                                        ('default_timezone', '$timezone_id')");
        }


I'm not sure what the deal is with that mktime function, but it doesn't return anything even vaguely resembling the proper offset on my servers.  (I'm at -7, whereas that's returning +8).  My hardware and software clocks are set correctly.  I believe that the proper way to do it would be to ask PHP what the default timezone is, by dropping the $server_offset line and changing the $timezone_id line to:

                $timezone_id = date_default_timezone_get();

By replacing the database value with the return from that function, my forum now displays the correct time without needing an offset.

Rumbaar

So did it return Etc/GMT+8 or Etc/GMT-8 for you?  And you're at GMT -7 (mid USA)?
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

Jade E.

The code in install.php was returning Etc/GMT+8, whereas I am in the US pacific timezone, which is GMT-8 standard, and GMT-7 DST.  DST is currently in effect.

After I posted that last night, it was bugging me that my time was only off by 1 hour, instead of the 15 it should have been if it was off from -7 to +8. So I did some more digging after posting last night and I have more information.

It turns out that the Etc/* timezones (excepting Etc/UTC) are hxxp:us.php.net/manual/en/timezones.others.php [nonactive] for a couple reasons.  The important ones being, the GMT+/- timezones are reversed (The Etc/GMT+8 tz actually refers to GMT-8). And those timezones don't contain any DST settings, so they're going to be wrong for at least part of the year in the half of the world that uses a form of DST.

I still don't know why mktime is returning +8 (28800).

I think that changing the install to ask PHP what timezone we're in would be the proper way to fix it, since that's the only easy way to get the TZ name that includes the proper DST information, and avoids the whole mess.  date_default_timezone_get() returns "US/Pacific" on my server.  After inserting that as the new database default_timezone value, I tested it forward and back through a couple of DST changes, and the forum time automatically changed as well.  I did the same using Etc/GMT+8 and Etc/GMT+7, and they didn't auto change, and each was wrong for one of the DST period (+7 is right now, wrong in the winter, +8 is wrong now, right in the winter.)

Hope this helps  :)

Advertisement: