From: Tim Starling Date: Mon, 26 Jan 2004 02:55:07 +0000 (+0000) Subject: Half hour time zones X-Git-Tag: 1.3.0beta1~1093 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=c56c69e986692a126e964c3147e55b20f319ab24;p=lhc%2Fweb%2Fwiklou.git Half hour time zones --- diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index cbfb1b6ec5..902b9191c7 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -56,7 +56,28 @@ function wfSpecialPreferences() } } - +/* private */ function validateTimeZone( $s ) +{ + + if ( $s !== "" ) { + if ( strpos( $s, ":" ) ) { + # HH:MM + $array = explode( ":" , $s ); + $hour = intval( $array[0] ); + $minute = intval( $array[1] ); + } else { + $minute = intval( $s * 60 ); + $hour = intval( $minute / 60 ); + $minute = abs( $minute ) % 60; + } + $hour = min( $hour, 15 ); + $hour = max( $hour, -15 ); + $minute = min( $minute, 59 ); + $minute = max( $minute, 0 ); + $s = sprintf( "%02d:%02d", $hour, $minute ); + } + return $s; +} /* private */ function savePreferences() { @@ -93,7 +114,7 @@ function wfSpecialPreferences() $wgUser->setOption( "rows", validateInt( $wpRows, 4, 1000 ) ); $wgUser->setOption( "cols", validateInt( $wpCols, 4, 1000 ) ); $wgUser->setOption( "stubthreshold", validateIntOrNull( $wpStubs ) ); - $wgUser->setOption( "timecorrection", validateIntOrNull( $wpHourDiff, -12, 14 ) ); + $wgUser->setOption( "timecorrection", validateTimeZone( $wpHourDiff, -12, 14 ) ); $namespaces = $wgLang->getNamespaces(); # Set search namespace options diff --git a/languages/Language.php b/languages/Language.php index 9b54441e2c..8fa96b14cf 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1436,16 +1436,26 @@ class Language { { global $wgUser, $wgLocalTZoffset; - $diff = $wgUser->getOption( "timecorrection" ); - if ( ! is_numeric( $diff ) ) { - $diff = isset( $wgLocalTZoffset ) ? $wgLocalTZoffset : 0; + $tz = $wgUser->getOption( "timecorrection" ); + if ( $tz === "" ) { + $hrDiff = isset( $wgLocalTZoffset ) ? $wgLocalTZoffset : 0; + $minDiff = 0; + } elseif ( strpos( $tz, ":" ) !== false ) { + $tzArray = explode( ":", $tz ); + $hrDiff = intval($tzArray[0]); + $minDiff = intval($hrDiff < 0 ? -$tzArray[1] : $tzArray[1]); + } else { + $hrDiff = intval( $tz ); } - if ( 0 == $diff ) { return $ts; } - - $t = mktime( ( (int)substr( $ts, 8, 2) ) + $diff, - (int)substr( $ts, 10, 2 ), (int)substr( $ts, 12, 2 ), - (int)substr( $ts, 4, 2 ), (int)substr( $ts, 6, 2 ), - (int)substr( $ts, 0, 4 ) ); + if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; } + + $t = mktime( ( + (int)substr( $ts, 8, 2) ) + $hrDiff, # Hours + (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes + (int)substr( $ts, 12, 2 ), # Seconds + (int)substr( $ts, 4, 2 ), # Month + (int)substr( $ts, 6, 2 ), # Day + (int)substr( $ts, 0, 4 ) ); #Year return date( "YmdHis", $t ); } diff --git a/stylesheets/wikibits.js b/stylesheets/wikibits.js index bcd9ade930..a76aeb2515 100644 --- a/stylesheets/wikibits.js +++ b/stylesheets/wikibits.js @@ -31,7 +31,7 @@ function checkTimezone( tz, msg ) { } } -// in [-][H]H format... +// in [-]HH:MM format... // won't yet work with non-even tzs function fetchTimezone() { // FIXME: work around Safari bug @@ -39,7 +39,9 @@ function fetchTimezone() { // returns negative offset from GMT in minutes var tzRaw = localclock.getTimezoneOffset(); var tzHour = Math.floor( Math.abs(tzRaw) / 60); - var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "" : "0") + tzHour; + var tzMin = Math.abs(tzRaw) % 60; + var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour + + ":" + ((tzMin < 10) ? "0" : "") + tzMin; return tzString; }