1
iHackCode
How does displaying user time work?

I'm a bit lost on this. The function is below (I got it from XOOPS 2.6)

$time is the time (Unix timestamp).
* The timezone can be set by the locale.php based on the general settings (default locale) for the website.

$timeoffset is the 'user' timezone
* if user. its whats they set in their profile
* if anon. its the 'Default_TZ', from the general settings.

Now there is one more offset, the 'Server_TZ'. That is confusing me.

Looking at the logic that assigns $usertimestamp it looks like it assumes the 'Server_TZ' and $time are using the same timezone. The two time stamps might not always be the same Timezone though. So if they are not the same then the displayed timezone will be off.

When will the $time timezone change timezone:
* using a different locale (because of language)

/**
     * @param mixed  $time
     * @param string $timeoffset
     *
     * @return int
     */
    
public function getUserTimestamp($time$timeoffset '')
    {
        if (
$timeoffset == '') {
            if (
$this->isUser()) {
                
$timeoffset $this->user->getVar('timezone_offset');
            } else {
                
$timeoffset $this->getConfig('default_TZ');
            }
        }
        
$usertimestamp intval($time) + (floatval($timeoffset) - $this->getConfig('server_TZ')) * 3600;
        return (int)
$usertimestamp;
    }

2
geekwright
Re: How does displaying user time work?

In most circumstances, server_TZ should be 0 (UTC/GMT.) There are "servers" configured incorrectly, where the system time (and therefor PHP's time() function) is not actually UTC. This was common in personal machines using Windows, but showed up occasionally in a variety of systems. Most modern systems use ntp synced clocks set to UTC, so this issue is much less common. In a perfect world, server_TZ would not be needed.

That is the theory. If it is all implemented correctly across the system, I'm not certain. But in the case of the getUserTimestamp() method, it looks correct. It really only should come into play if the server is mis-configured, and then only fix it when displaying the time.

3
iHackCode
Re: How does displaying user time work?

Oh I see. I was incorrect on the $time, $time is from time(). Which should be from the same TZ as the Server_TZ as you said.

So now I'm looking at formatTimestamp() function that calls the getUserTimestamp() function.

It returns:
return ucfirst(date($datestring$usertimestamp));


But if the timezone for date() is not UTC/GMT (set with the date_default_timezone_set()), it would change the calculated $usertimestamp.

So I guess the question is about locales, why is it used to set the timezone? Instead of date() should gmdate() be used?

4
geekwright
Re: How does displaying user time work?

Quote:

iHackCode wrote:
...
So I guess the question is about locales, why is it used to set the timezone?
...


When the system stores a time value, it should be a system (preferably UTC) timestamp, so that data from all layers (web server, database, application, etc.) correlate. When it displays that timestamp, it needs to be expressed in a way useful to the user. That may include adjusting it to the timezone, and respecting whatever conventions are in place due to culture and/or language. That means that conversion for display in current timezone and adjusting user input of time data to UTC/sytem are completely locale dependent issues.

This is especially true of the user friendly relative times. Even a concept as seemingly simple as expressing "x days ago" can change drastically, not just by a direct translation of the phrase "days ago," but the value of x can change the entire expression. 1, 2 and 3 days cases could each be different.

http://www.unicode.org/repos/cldr-aux/charts/26/by_type/date_&_time.fields.html#Relative_Day

I agree it looks like formatTimestamp is mixing UTC and system timezone shifted elements.
For any follow up on this aspect, see https://github.com/XOOPS/XoopsCore/pull/240

Thanks!

5
iHackCode
Re: How does displaying user time work?

Thanks, that was really helpful

Login

Who's Online

396 user(s) are online (280 user(s) are browsing Support Forums)


Members: 0


Guests: 396


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits