* Bug 9123 : safer way when applying $wgLocalTZoffset.
authorAntoine Musso <hashar@users.mediawiki.org>
Sun, 13 May 2007 11:53:07 +0000 (11:53 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sun, 13 May 2007 11:53:07 +0000 (11:53 +0000)
* Add a test for Language::userAdjust()

RELEASE-NOTES
languages/Language.php
t/inc/Language.t [new file with mode: 0644]

index 13f1eb0..d6f987f 100644 (file)
@@ -51,6 +51,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 5375) profiling does not respect read-only mode.
 * (bug 7070) monobook/user.gif has antialias artifacts
 * (bug 9877) Fix Catalan translation of rev-deleted-text-view
+* (bug 9123) Safer way when applying $wgLocalTZoffset
+
 
 == Maintenance script changes since 1.10 ==
 
index 1eb09b6..d36b549 100644 (file)
@@ -420,8 +420,12 @@ class Language {
                if ( $tz === '' ) {
                        # Global offset in minutes.
                        if( isset($wgLocalTZoffset) ) {
-                               $hrDiff = $wgLocalTZoffset % 60;
-                               $minDiff = $wgLocalTZoffset - ($hrDiff * 60);
+                               if( $wgLocalTZoffset >= 0 ) {
+                                       $hrDiff = floor($wgLocalTZoffset / 60);
+                               } else {
+                                       $hrDiff = ceil($wgLocalTZoffset / 60);
+                               }
+                               $minDiff = $wgLocalTZoffset % 60;
                        }
                } elseif ( strpos( $tz, ':' ) !== false ) {
                        $tzArray = explode( ':', $tz );
diff --git a/t/inc/Language.t b/t/inc/Language.t
new file mode 100644 (file)
index 0000000..df5e491
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/env php
+<?php
+
+require 'Test.php';
+
+# Test offset usage for a given language::userAdjust
+function test_userAdjust( $langObj, $date, $offset, $expected ) {
+       global $wgLocalTZoffset;
+       $wgLocalTZoffset = $offset;
+
+       cmp_ok(
+               $langObj->userAdjust( $date, '' ),
+               '==',
+               $expected,
+               "User adjust $date by $offset minutes should give $expected"
+       );
+}
+
+# Collection of parameters for Language_t_Offset.
+# Format: date to be formatted, localTZoffset value, expected date
+$userAdjust_tests = array(
+       array( 20061231235959,   0, 20061231235959 ),
+       array( 20061231235959,   5, 20070101000459 ),
+       array( 20061231235959,  15, 20070101001459 ),
+       array( 20061231235959,  60, 20070101005959 ),
+       array( 20061231235959,  90, 20070101012959 ),
+       array( 20061231235959, 120, 20070101015959 ),
+       array( 20061231235959, 540, 20070101085959 ),
+       array( 20061231235959,  -5, 20061231235459 ),
+       array( 20061231235959, -30, 20061231232959 ),
+       array( 20061231235959, -60, 20061231225959 ),
+);
+
+plan( 7 + count($userAdjust_tests) );
+
+require_ok( 'includes/Defines.php' );
+
+# require_ok() doesn't work for these, find out why
+define( 'MEDIAWIKI', 1 );
+require 'LocalSettings.php';
+require 'includes/DefaultSettings.php';
+
+# Create a language object
+require_ok( 'languages/Language.php' );
+require_ok( 'includes/Title.php' );
+$wgContLang = $en = Language::factory( 'en' );
+
+# We need an user to test the lang
+require_ok( 'includes/GlobalFunctions.php' );
+require_ok( 'includes/ProfilerStub.php' );
+require_ok( 'includes/Exception.php' );
+require_ok( 'includes/User.php' );
+global $wgUser;
+$wgUser = new User();
+
+# Launch tests for language::userAdjust
+foreach( $userAdjust_tests as $data ) {
+       test_userAdjust( $en, $data[0], $data[1], $data[2] ); 
+}
+
+/* vim: set filetype=php: */
+?>