create new tag
, view all tags


Hello everyone! Let me first say what a wonderful idea this is. I am 99% done with my company's intranet site (using TWiki of course). The only problem that's preventing me from reaching the 100% goal is the time. I try changing the time variable in TWikiVariables from GMTIME (General Mountain Time)to ESTIME (Eastern Standard Time) by typing this:

    • Set %ESTIME{"$day $month, $year - $hour:$min:$sec"}%

I also typed the line above in TWikiPreferences. However none of this works. At the bottom of the page I still see GMTime. Is there anyone who has done this already? I have not seen any documentation on how to do this and I'm stumped so I figured that someone out there had done this and succeeded. Please help me. smile

  • TWiki version: Dec 2000 with Spring 2001 Beta Update(3/15/01)
  • Web server: Apache 1.3.12
  • Server OS: Linux (Debian)

-- TWikiGuest - 03 Aug 2001


Well, first of all GMTIME stands for Greenwich Mean Time, and it is the international standard for global time. Twiki was designed for international collaboration, so it measures time in a format that everybody can agree on, and no, simple changing the name of a variable will not do it.

If you really want to make this change, unless somebody has done it and can just tell you which lines to patch, you will have to go messing with the twiki code yourself.

This question was previously addressed as TimeZone.

-- EdgarBrown - 03 Aug 2001

Thank You very much Edgar for your response and thank for the correction on GMT wink A question for Peter (or any of the other developers including you Edgar) My company just has one office (at the present at least) so this is the reason I asked this question and the reason for the need for a specifi time zone. I see that there will be a future version that will come out with support for different time zones - when is this scheduled to happen? If its a while from now what would I need to adjust in the actual code to accomplish this?

-- TWikiGuest - 06 Aug 2001

No schedule has been set for supporting different time zones and this has not the highest priority for us because the major users of TWiki are larger organizations with multiple offices.

However you could hack the TWiki source as follows. Warning: I did not test this code, there is a possibility that it might break something. Changes in wiki.pm are indicated in red

# =========================
sub formatGmTime
    my( $time ) = @_;

    my( $sec, $min, $hour, $mday, $mon, $year) = localtime( $time );
    my( $tmon) = $isoMonth[$mon];
    $year = sprintf( "%.4u", $year + 1900 );  # Y2K fix
    $time = sprintf( "%.2u ${tmon} %.2u - %.2u:%.2u", $mday, $year, $hour, $min );
    return $time;

-- PeterThoeny - 06 Aug 2001

Peter, I've tried this hack; it doesn't seem to do anything for me. -- JonReid - 16 Aug 2001

Jon, I've also tried this which is why I asked the question below. Have you been able to accomplish this since then? I'm not having any luck with it. -- JessicaOrtiz - 23 Aug 2001

Could this be accomplished using the local time plugin? -- JessicaOrtiz - 13 Aug 2001

No, the LocalCityTimePlugin allows you to display the local time of a city in a TWiki topic, but it does not change the time stamp display of topics. -- PeterThoeny - 28 Aug 2001

Thank You Peter, but my original question of changing the time stamp display (I posted as TWikiGuest in the original message) has not yet been addressed. I tried changing the code as you have typed it up above, but it was not working. I understand it has not been tested but did anyone accomplished this?

-- JessicaOrtiz - 29 Aug 2001

Sorry, can't help you out with this one.

-- PeterThoeny - 31 Aug 2001

The code above is not used in displaying revision dates and times (i.e. the date/time at the bottom of the page). You can modify TWiki/Store.pm to display localtime for the revision date - however a quick hack that I tried did not work completely, and broke some other usage (e.g. WebChanges), so it's not that easy. I can mail you the patch, but it's not working at the moment so you'd need Perl skills to finish it off and fix it.

The simplest solution is to update Store.pm's getRevisionInfoNew routine, so that it doesn't mention the date/time - WebChanges should still work, but should be tested.

-- RichardDonkin - 01 Sep 2001

can you mail me the patch when you get it to work?

-- JessicaOrtiz - 05 Sep 2001

I won't be doing any more work on this, as I don't really need it and I'm a bit busy... Let me know if you want to start working on it, but finishing it is more like 80% of the work than 20%.

-- RichardDonkin - 06 Sep 2001

Here's a simple hack that will probably do the trick for most people... It relies on your server time being set to the local timezone. You can change the sprintf statement in Store.pm if you prefer another date format (eg, yyyy mm dd @ hh:mm).

Note: Attachments will still be timestamped in GMT.

Related Link: TopicCreateDateInFormattedSearch

You could change this to read Web or Site preferences to determine if TWiki should use GMTIME or SERVERTIME. =================================================================

Step 1: Change the code in lib/TWiki/Store.pm

================================================================= Store.pm

sub getRevisionInfoFromMeta
  ... ...

if( %topicinfo ) {
       # Stored as meta data in topic for faster access
       $date = TWiki::formatGmTime( $topicinfo{"date"} ); # FIXME deal with changeToIsoDate

       # hack for local time - Corey Fruitman 22 Feb 2002
       if ( $changeToIsoDate eq "isoLocalTimeFormat") {
          my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime ( $topicinfo{"date"} );
          my @monthTranslation= ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
          $year+= 1900;
          $mon = $monthTranslation[$mon];
          $date = sprintf ("%02d %s %04d - %02d:%02d", $mday, $mon, $year, $hour , $min);
       # end hack

       $author = $topicinfo{"author"};
       my $tmp = $topicinfo{"version"}; 

... ...


Step 2: Change code in /bin/view

================================================================= view

sub main
... ...
 if( $viewRaw ) {
            $text = &TWiki::Store::readTopicRaw( $webName, $topic );
        } else {
            ( $meta, $text ) = &TWiki::Store::readTopic( $webName, topic );

        # hack for local time - last arg was "isoFormat" - Corey Fruitman 22 Feb 2002
        ( $revdate, $revuser, $maxrev ) = &TWiki::Store::getRevisionInfoFromMeta( $webName, $topic, $meta, "isoLocalTimeFormat" );

        writeDebug( "maxrev = $maxrev" );
        if( $rev ) 

... ...

Step 3: Change the templates

================================================================= In your templates directory,

grep " GMT" *

Edit each instance of GMT to represent the desired time zone. (Note the space between the first quote and the 'G' in the grep statement. You don't want to change % GMTIME%!)

Better yet, create a variable for your time zone and use that.


Step 4: Change the executables

================================================================== In your bin directory,

grep " GMT" *

Same thing. Edit each instance to represent the desired time zone.

Hope this helps!

-- CoreyFruitman - 22 Feb 2002

Corey in the name of everyone who's been trying to do this, thank you for the hack above ... it worked! smile I set the time to SERVERTIME
and its working just fine.

-- JessicaOrtiz - 25 Feb 2002

Is this working fairly well for people who've applied it? If so, it might be useful to put this into the TWiki code in a more robust form. TWiki is often used by international companies who are OK with GMT, but it seems like a good idea to support a different 'server timezone' than GMT, at least.

Ideally we could do something like SlashDot, which has a per-user timezone setting allowing display of the local time for each user in whatever timezone - but this would require cookie-based authentication as in UserCookiePlugin. (Something to think about for the future though.)

-- RichardDonkin - 22 Mar 2002

It has been working perfectly for me since I applied it. The only problem is that TWiki still shows attachments in GMT. Probably a pretty simple fix.

What you're proposing has been touched on in Codev.TimeFormat. I'll continue this thread there.

-- CoreyFruitman - 22 Mar 2002

I've applied the set of changes outlined by CoreyFruitman above, in order to have one time zone, our intranet's local time. I'm very pleased with the results, but there's still one problem. In the output of any simple search, with the default format as shown in WebChanges, the date field is still GMT times.

Now that I've got my hands dirty and it didn't hurt, could someone point me to the place I'd need to hack to get this column in searches to display in server time too?

-- SueBlake - 07 Aug 2002

I haven't tested this, but you can try adding the following to lib/TWiki.pm:

sub formatLocalTime
    my( $theTime ) = @_;
    my( $sec, $min, $hour, $mday, $mon, $year ) = localtime( $theTime );
    my( $tmon ) = $isoMonth[$mon];
    $year = sprintf( "%.4u", $year + 1900 );  # Y2K fix
    return sprintf( "%.2u ${tmon} %.2u - %.2u:%.2u", $mday, $year, $hour, $min );

... and then change line 77 in the the file bin/changes

from: $time = &TWiki::formatGmTime( $bar[2] );

to: $time = &TWiki::formatLocalTime( $bar[2] );

-- CoreyFruitman - 12 Aug 2002

Changing status to Answered. If someone tries this, could you please post your results here?

-- CoreyFruitman - 15 Aug 2002

I suspect part of the problem with whether solutions work or not depends on how your server is set-up timewise and on the OS. Our pilot TWiki server (Athens Dec 2001 release) is running under Linux on UK local time but with the hardware clock set to GMT.

I've made the following changes to TWiki:


(Actually the first item of the changes - the "localtime" change described by Peter Thoeny earlier - didn't work correctly and had to be replaced. See the revised solution described below).

-- RichardLewis - 08 Oct 2002

Yes, everything is fine except one: on WebChanges page I see GMT time for each pages links. But in notification e-mail I receive correct time values for each pages links. What have I missed? Can you advise me?

-- EugeneKuzmitsky - 09 Oct 2002

There was a problem with my earlier proposed patches: Repeated edit/saves in a single edit session added an hour (+ 2 minutes, I believe) each time round. Here's a working solution - at least as of a couple of hours of testing! I've deleted my earlier post and replaced it by this one.

The procedure I described earlier still applies except for the first item (the "localtime" change to the formatGmTime sub). This, unfortunately, has far too wide an impact. In its place I've done the following:

  • Created a new sub, formatLocTime, in TWiki.pm identical to formatGmTime except for the one-line change of:
    • my( $sec, $min, $hour, $mday, $mon, $year) = gmtime( $time );     to
    • my( $sec, $min, $hour, $mday, $mon, $year) = localtime( $time );
    • The reason for doing this is to apply Peter Thoeny's original change only where needed rather than everywhere formatGmTime is called.

  • Changed formatGmTime to formatLocTime only in the following Perl scripts/lines:
    • bin/changes: $time = &TWiki::formatGmTime( $bar[2] );
    • bin/mailnotify: $time = &TWiki::formatGmTime( $prevLastmodify );
    • bin/mailnotify: $time = &TWiki::formatGmTime( $bar[2] );
    • bin/mailnotify: $text =~ s/%LASTDATE%/&TWiki::formatGmTime($prevLastmodify)/geo;
    • lib/TWiki/Attach.pm: $attrDate = &TWiki::formatGmTime( $attrDate );
    • lib/TWiki/Store.pm: $date = TWiki::formatGmTime( $topicinfo{"date"} ); # FIXME deal with changeToIsoDate

  • Don't change the following line:
    • lib/TWiki/Store.pm: $date = &TWiki::formatGmTime( $epochSec, "rcs" );

Now the changes I discussed earlier:

  • In the following files/lines I've removed "GMT" from:
     bin/view:    my $temp = &TWiki::getRenderedVersion( "r1.$rev - $revdate GMT - $revuser" );
     templates/searchbookview.tmpl:    <b>Changed:</b> GMT
     templates/mailnotify.tmpl: (all lines containing GMT)
  • In the following files/lines I've changed "GMTIME" to "SERVERTIME" and removed "GMT":
     templates/changes.tmpl:   <b>Changed:</b> now %GMTIME{"$hour:$min"}% GMT
     templates/search.tmpl:   <b>Changed:</b> now %GMTIME{"$hour:$min"}% GMT
     templates/searchrenameview.tmpl:   <b>Changed:</b> now %GMTIME{"$hour:$min"}% GMT

If you want to show a local time suffix, simply define a variable eg %LOCALTIME%, set it to your local three-letter time zone acronym (eg BST) and insert instead of GMT in the strings above where I've actually removed it. If you have daylight saving time and the acronym changes, as it does here in the UK (ie GMT to/from BST), you'll probably have to use a bit of Perl to check which time acronym to use depending on the difference between SERVERTIME and GMTIME.

-- RichardLewis - 09 Oct 2002

Right. I can now confirm that the above changes work perfectly. Dates are stored as GMT and only converted to local time for display. This avoids any compatibility problems. As far as I can see, everything is being displayed in local time, inc attachments. What I can't promise is that this'll work for every platform. This is on a SuSE Linux/386/Apache implementation, running GMT hardware clock and GMT0BST1 local time. Windows may react differently.

-- RichardLewis - 11 Oct 2002

Would be nice to get a combination of the Richard Lewis' Date::Calc and Richard Donkin's UserCookiePlugin solution into CairoRelease. I'm in a situation where I have two TWiki hosted on the same shared linux hosting server in America. One serves the UK and the other Australia. My localtime is set to US East coast!

-- MartinCleaver - 06 Apr 2003

This sucks. TWiki has options for almost anything but not for this frown

-- FrankGerhardt - 15 Jul 2003

I agree this issue does need fixing as it's a frequent issue. Authentication of page views is really important for many sites using TWiki, not just for timezone settings.

-- RichardDonkin - 16 Jul 2003

OK guys, how much are you prepared to risk to get this? smile

There might be an answer if what you want is a single LOCAL time throughout. I've applied Richard Lewis's instructions above to the Feb 2003 release, produced a single patch to do the whole TWiki tree, and I'm currently testing it. So far my FreeBSD computer hasn't exploded, but YMMV.

Not knowing what to do with an untested patch, I've temporarily attached it to my SueBlake page. Would one of you other needy people care to try it out and compare notes? Patch now moved to AlwaysServerTimeZone

Basically you just cd to the directory that contains the main twiki distribution directory (likely /home/httpd or /usr/local/www) and type 'patch < pachfilename' as root. Backup well beforehand, of course.

Maybe it's time to split the several (sometimes conflicting) questions here into separate topics, e.g. my twiki doesn't care about any user's time, nor GMT, just wants the real server time, one timezone only, always, forever, etc, and my users would freak horrendously if they ever glimpsed any other kind of time. Some other twikis need individual users or user groups to be given their own time zones, which is probably more tricky to set up and quite a different question.

-- SueBlake - 16 Jul 2003

Moved patch to AlwaysServerTimeZone with a plea for testing. Please go there for followup discussion.

-- SueBlake - 27 Jul 2003

removed math in variables question to the same place since it really is a code suggestion.

-- MattWilkie - 29 Jul 2003

Edit | Attach | Watch | Print version | History: r51 < r50 < r49 < r48 < r47 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r51 - 2007-05-28 - GrazianoMisuraca
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.