Item10039: add possibility to redefine timezone in user settings
Priority: Enhancement
Current State: Proposal Required
Released In: n/a
Target Release: n/a
This patch will allow user to set TZ varible to redefine server timezone, because we have many users in different timezones and they would like to see modification time in their time
--- lib/Foswiki/Render.pm.orig 2010-11-16 09:32:32.000000000 +0000
+++ lib/Foswiki/Render.pm 2010-11-15 17:02:41.000000000 +0000
@@ -1865,18 +1865,20 @@
$un ||= $user;
}
+ my $userTZ = $this->{session}->{prefs}->getPreferencesValue('TZ');
+
my $value = $format || 'r$rev - $date - $time - $wikiusername';
$value =~ s/\$web/$web/gi;
$value =~ s/\$topic/$topic/gi;
$value =~ s/\$rev/$rev/gi;
- $value =~ s/\$time/Foswiki::Time::formatTime( $date, '$hour:$min:$sec')/gei;
+ $value =~ s/\$time/Foswiki::Time::formatTime( $date, '$hour:$min:$sec', $userTZ)/gei;
$value =~
-s/\$date/Foswiki::Time::formatTime( $date, $Foswiki::cfg{DefaultDateFormat} )/gei;
+s/\$date/Foswiki::Time::formatTime( $date, $Foswiki::cfg{DefaultDateFormat}, $userTZ )/gei;
$value =~
s/(\$(rcs|http|email|iso))/Foswiki::Time::formatTime($date, $1 )/gei;
if ( $value =~ /\$(sec|min|hou|day|wday|dow|week|mo|ye|epoch|tz)/ ) {
- $value = Foswiki::Time::formatTime( $date, $value );
+ $value = Foswiki::Time::formatTime( $date, $value, $userTZ );
}
$value =~ s/\$comment/$comment/gi;
$value =~ s/\$username/$un/gi;
--- lib/Foswiki/Time.pm.orig 2010-11-15 15:51:52.000000000 +0000
+++ lib/Foswiki/Time.pm 2010-11-15 16:29:05.000000000 +0000
@@ -223,7 +223,7 @@
* =$epochSeconds= epochSecs GMT
* =$formatString= twiki time date format, default =$day $month $year - $hour:$min=
- * =$outputTimeZone= timezone to display, =gmtime= or =servertime=, default is whatever is set in $Foswiki::cfg{DisplayTimeValues}
+ * =$outputTimeZone= timezone to display, =gmtime=, =servertime= or actual timezone, default is whatever is set in $Foswiki::cfg{DisplayTimeValues}
=$formatString= supports:
| $seconds | secs |
@@ -265,10 +265,15 @@
( $sec, $min, $hour, $day, $mon, $year, $wday, $yday ) =
localtime($epochSeconds);
}
- else {
+ elsif ( $outputTimeZone eq 'gmtime' ) {
( $sec, $min, $hour, $day, $mon, $year, $wday, $yday ) =
gmtime($epochSeconds);
}
+ else {
+ local $ENV{TZ} = $outputTimeZone;
+ ( $sec, $min, $hour, $day, $mon, $year, $wday, $yday ) =
+ localtime($epochSeconds);
+ }
#standard twiki date time formats
if ( $formatString =~ /rcs/i ) {
@@ -312,16 +317,19 @@
# we add usertime, then what?)
$tz_str = 'Local';
}
- else {
+ elsif ( $outputTimeZone eq 'gmtime' ) {
( $sec, $min, $hour, $day, $mon, $year, $wday ) =
gmtime($epochSeconds);
$tz_str = 'GMT';
}
+ else {
+ $tz_str = $outputTimeZone;
+ }
$value =~ s/\$tz/$tz_str/gei;
}
if ($value =~ /\$isotz/) {
- my $tz_str = 'Z';
- if ( $outputTimeZone ne 'gmtime' ) {
+ my $tz_str;
+ if ( $outputTimeZone eq 'servertime' ) {
# servertime
# time zone designator (+hh:mm or -hh:mm)
# cached.
@@ -339,6 +347,18 @@
}
$tz_str = $TZSTRING;
}
+ elsif ( $outputTimeZone eq 'gmtime' ) {
+ $tz_str = 'Z';
+ }
+ else {
+ local $ENV{TZ} = $outputTimeZone;
+ my $offset = _tzOffset();
+ my $sign = ($offset < 0) ? '-' : '+';
+ $offset = abs($offset);
+ my $hours = int($offset / 3600);
+ my $mins = int(($offset - $hours * 3600) / 60);
+ $tz_str = sprintf("$sign%02d:%02d", $hours, $mins);
+ }
$value =~ s/\$isotz/$tz_str/gei;
}
--
AlexanderKriventsov - 17 Nov 2010
This is an enhancement request that requires feature proposal.
And if implemented the patch above lacks...
Documentation. The patch is code only
User interface of some sort. The patch assumes preference setting in users topic and the users will write anything. There is no check to see if TZ is valid. What happens when you write garbage?
What about DST?
Timezones in this world are not always full hours. Some are half hours offset. Patch assumes only full hours.
So a lot of work and discussion. The idea is not bad that a user once logged in get times displayed in his own time zones but after having dealt with conversion problems in a plugin we have to watch out that times are not shifted in unpredictable ways.
Changed to Enhancement and awaiting feature proposal from committed developer.
--
KennethLavrsen - 19 Nov 2010