Display of times in TWiki metacode
Should these matters be platform related, my platform is
'CentOS Linux release 7.3.1611 (Core)'
Problem description
- Tested using the following TWiki metacode with
$TWiki::cfg{DisplayTimeValues} = 'localtime';
in LocalSite.cfg.
DISPLAYTIME is %DISPLAYTIME%. SERVERTIME is %SERVERTIME%. DATE is %DATE%. GMTIME is %GMTIME%
- Result: I get times rendered in GMT for the 3 above times. This is correct for GMTIME but not for DISPLAYTIME and maybe not for SERVERTIME?
Problem analysis
The following code in
sub formatTime {}
in lib/TWiki/Time.pm is relevant.
210 } else {
211 my $tzSave;
212 if ( $outputTimeZone ) {
213 $tzSave = $ENV{TZ};
214 $ENV{TZ} = $outputTimeZone;
215 tzset();
216 }
Commenting out line 214 & 215 as a hack fixes the problem.
- Result: I get times rendered in BST for DISPLAYTIME and SERVERTIME and in GMT for GMTIME which is correct.
If not set explicitly in the code
$outputTimeZone
is set to
$TWiki::cfg{DisplayTimeValues}
from LocalSite.cfg. Looking at the man page for tzset on my system suggests
localtime
(or
gmtime
as suggested in lib/TWiki.spec) is not a valid value for this environment variable, which is intended to code an explicit/geographical timezone spec, eg.
Europe/London
.
- Uncommented/restored the code in lib/TWiki/Time.pm and changed LocalSite.cfg item to read
$TWiki::cfg{DisplayTimeValues} = ':/etc/localtime';
where /etc/localtime -> /usr/share/zoneinfo/Europe/London
on my system.
- Result: I get times rendered in BST for DISPLAYTIME and in GMT for SERVERTIME and GMTIME which is better.
- Conclusion: This is acceptable but is this the intended behaviour? Maybe the entry in lib/TWiki.spec needs amending?
Display of times in TWiki logs (eg. data/log201705.txt and data/debug.txt)
Problem description
The logs are always timestamped in GMT. Looking at the code (see below) this seems to be intended. At least on the Unix systems I have administered most things (syslog,Apache etc.) always log in local time, which to my mind makes the TWiki logs slightly confusing.
Problem analysis
The following code in
sub _writeReport{}
in lib/TWiki.pm is relevant.
2354 sub _writeReport {
2355 my ( $this, $log, $message ) = @_;
2356
2357 if ( $log ) {
2358 require TWiki::Time;
2359 my $time =
2360 TWiki::Time::formatTime( time(), '$year$mo', 'gmtime');
2361 $log =~ s/%DATE%/$time/go;
2362 $time = TWiki::Time::formatTime( time(), '$year-$mo-$day - $hour:$min:$sec', 'gmtime' );
Replacing both instances of
'gmtime'
with
undef
makes the
formatTime()
call use the timezone value
$TWiki::cfg{DisplayTimeValues}
specified in LocalSite.cfg, which as changed above makes the logs timestamps render in BST. Could this (being able to set the timezone for logs) be considered as a feature request for future TWiki releases? I notice there are many other calls to
formatTime()
and other functions within the TWiki code which specify
gmtime
as an argument and I can see that for certain internal uses this makes sense. Maybe a more holistic approach to timezone handling rather than the two issues I've brought up is needed...
--
TWiki:Main/TomCrane
- 2017-05-16
Thanks for the thorough description of the symptoms and analysis. It seems that this item is closely related to
Item7752 (same root cause, different observations). I fully agree with
Maybe a more holistic approach to timezone handling [...] is needed.
--
TWiki:Main.HaraldJoerg
- 2017-05-18
TWiki::_writeReport() now omits the third argument of TWiki::TIme::formatTime().
TWikibug:Item7752
is already taken care of. So you can have time stamps in log files in local time if you set $TWiki::cfg{DisplayTimeValues} "servertime".
--
TWiki:Main.HideyoImazu
- 2017-06-01