1 # Copyright (C) 2004, 2009 Alex Schroeder <alex@gnu.org>
2 # Copyright (C) 2004 Zuytdorp Survivor
4 # This program is free software: you can redistribute it and/or modify it under
5 # the terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program. If not, see <http://www.gnu.org/licenses/>.
16 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/timezone.pl">timezone.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Timezone_Extension">Timezone Extension</a></p>';
19 use DateTime
::TimeZone
;
21 use vars
qw($defaultTZ);
25 $CookieParameters{time} = '';
29 $ts = 0 if not defined($ts);
30 my $dt = DateTime->from_epoch(epoch=>$ts);
31 my $tz = GetParam('time', '');
32 # setting time= will use the (defined) empty string, so avoid that
33 $tz = $defaultTZ unless $tz;
34 # converting floating point hours used by a previous version of the
36 $tz = sprintf("%d:%02d", int($tz), int(60*($tz-int($tz))))
37 if $tz =~ /^[+-]?\d+\.?\d*$/;
38 $dt->set_time_zone($tz);
42 *OldTZCalcDay = *CalcDay;
43 *CalcDay = *NewTZCalcDay;
46 return TZget(shift)->ymd;
49 *OldTZCalcTime = *CalcTime;
50 *CalcTime = *NewTZCalcTime;
53 return substr(TZget(shift)->hms, 0, 5) # strip seconds
54 . (GetParam('time', '') ? '' : ' UTC');
57 *OldTZGetFooterTimestamp = *GetFooterTimestamp;
58 *GetFooterTimestamp = *NewTZGetFooterTimestamp;
60 sub NewTZGetFooterTimestamp {
61 my $html = OldTZGetFooterTimestamp(@_);
62 $html =~ s/(\d\d:\d\d( UTC)?)/ScriptLink('action=tz', $1, 'tz')/e;
69 print GetHeader(undef, T('Timezone'));
70 print $q->start_div({-class=>'tz content'});
72 my @names = DateTime::TimeZone->all_names;
73 print $q->p(T('Pick your timezone:'),
74 $q->popup_menu(-name=>'time',
76 -default=>GetParam('time', $defaultTZ)),
77 $q->submit('dotz', T('Set')));
78 print $q->endform . $q->end_div();