Page MenuHomePhabricator

$wgLocaltimezone half ignored in signatures
Closed, ResolvedPublic

Description

Author: achuggard

Description:
At the beginning of function pstPass2 in Parser.php we have the following code. Effective as of around revision 30106:

if ( isset( $wgLocaltimezone ) ) {
        $oldtz = getenv( 'TZ' ); 
        putenv( 'TZ='.$wgLocaltimezone );
}       
$d = $wgContLang->timeanddate( $this->mOptions->getTimestamp(), false, false) . ' (' . date( 'T' ) . ')';
if ( isset( $wgLocaltimezone ) ) {
        putenv( 'TZ='.$oldtz );
}

The issue with this is that if $wgLocaltimezone is set, $this->mOptions->getTimestamp() seems to return a cached UTC timestamp, while date( 'T' ) returns a the TimeZone abbreviation coordinated with $wgLocaltimezone.

Example, my $wgLocaltimezone is set to "America/Chicago" if I used ~~~~~ in a page at 23:19 Central today (27 January), my timestamp is reported as "05:19, 28 January 2008 (CST)"

An off the cuff suggestion for solving this is the following:

if ( isset( $wgLocaltimezone ) ) {
        $oldtz = getenv( 'TZ' ); 
        putenv( 'TZ='.$wgLocaltimezone );
        $dtz = date( 'YmdHis' );
} else {
        $dtz = $this->mOptions->getTimestamp();
}
$d = $wgContLang->timeanddate( $dtz , false, false) . ' (' . date( 'T' ) . ')';
if ( isset( $wgLocaltimezone ) ) {
        putenv( 'TZ='.$oldtz );
}

Version: 1.12.x
Severity: normal

Details

Reference
bz12815

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:06 PM
bzimport set Reference to bz12815.
bzimport added a subscriber: Unknown Object (MLST).

achuggard wrote:

Thinking about this more, could it be a better option to create and store a $mLocalTimestamp on the ParserOptions which is set at the same time as the standard timestamp (perhaps add a $local parameter on the getTimestamp() call also)? But I don't know (offhand) where else a LocalTimestamp would be used so it may not be justified to calculate and store both.

achuggard wrote:

Looking into it one step further, the timeanddate function in Language.php called here seems to make the appropriate adjustment if if passed with the 2nd parameter being true: (so long as $wgLocalTZoffset is set properly) As $d is only used in putting together signatures, so I would bet that the following would be the best option:

$d = $wgContLang->timeanddate( $this->mOptions->getTimestamp(), isset( $wgLocaltimezone ) , false) . ' (' . date( 'T' ) . ')';

Should be fixed in r30766, based on the earlier suggestion above. (Passing true as the 2nd parameter to timeanddate() doesn't work right if the user has set a different timezone offset in their preferences.)