r79253 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79252‎ | r79253 | r79254 >
Date:16:10, 30 December 2010
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Fix r71751 problems with textual parameters.
Add a test for checking the problems which appeared in r71751
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/GlobalTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/GlobalTest.php
@@ -348,6 +348,27 @@
349349
350350 }
351351
 352+ function testTimestampParameter() {
 353+ // There are a number of assumptions in our codebase where wfTimestamp() should give
 354+ // the current date but it is not given a 0 there. See r71751 CR
 355+
 356+ $now = wfTimestamp( TS_UNIX );
 357+ // We check that wfTimestamp doesn't return false (error) and use a LessThan assert
 358+ // for the cases where the test is run in a second boundary.
 359+
 360+ $zero = wfTimestamp( TS_UNIX, 0 );
 361+ $this->assertNotEquals( false, $zero );
 362+ $this->assertLessThan( 5, $zero - $now );
 363+
 364+ $empty = wfTimestamp( TS_UNIX, '' );
 365+ $this->assertNotEquals( false, $empty );
 366+ $this->assertLessThan( 5, $empty - $now );
 367+
 368+ $null = wfTimestamp( TS_UNIX, null );
 369+ $this->assertNotEquals( false, $null );
 370+ $this->assertLessThan( 5, $null - $now );
 371+ }
 372+
352373 function testBasename() {
353374 $sets = array(
354375 '' => '',
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1948,7 +1948,7 @@
19491949 $da = array();
19501950 $strtime = '';
19511951
1952 - if ( $ts == 0 ) { // This intentionally catches $ts === '' and $ts === null too, so DON'T change this to ===
 1952+ if ( !$ts ) { // We want to catch 0, '', null... but not date strings starting with a letter.
19531953 $uts = time();
19541954 $strtime = "@$uts";
19551955 } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
@@ -1988,7 +1988,7 @@
19891989 # asctime
19901990 $strtime = $ts;
19911991 } else {
1992 - # Bogus value; fall back to the epoch...
 1992+ # Bogus value...
19931993 wfDebug("wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts\n");
19941994
19951995 return false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r793731.17: MFT r78308, r78622, r79089, r79185, r79199, r79213, r79214, r79253catrope21:09, 31 December 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r71751Merge r71750 to trunk: let wfTimestamp() accept TS_RFC2822 as an input format...catrope21:02, 26 August 2010

Comments

#Comment by Platonides (talk | contribs)   16:11, 30 December 2010

This should read Fix r79213 problems...

Status & tagging log