2009-10-13 22:27:54 +00:00
|
|
|
# Copyright (C) 2004, 2009 Alex Schroeder <alex@gnu.org>
|
2004-07-07 11:52:52 +00:00
|
|
|
# Copyright (C) 2004 Zuytdorp Survivor
|
|
|
|
|
#
|
2009-10-13 22:27:54 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
|
# version.
|
2004-07-07 11:52:52 +00:00
|
|
|
#
|
2009-10-13 22:27:54 +00:00
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
2004-07-07 11:52:52 +00:00
|
|
|
#
|
2009-10-13 22:27:54 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-07-07 11:52:52 +00:00
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('timezone.pl', 'Timezone Extension');
|
2009-10-13 22:27:54 +00:00
|
|
|
|
|
|
|
|
use DateTime;
|
|
|
|
|
use DateTime::TimeZone;
|
2004-07-07 11:52:52 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, %Action, %CookieParameters);
|
|
|
|
|
our ($defaultTZ);
|
2004-07-07 11:52:52 +00:00
|
|
|
|
2009-10-13 22:27:54 +00:00
|
|
|
$defaultTZ = 'UTC';
|
2004-07-07 11:52:52 +00:00
|
|
|
|
2009-10-13 22:27:54 +00:00
|
|
|
$CookieParameters{time} = '';
|
2004-07-07 11:52:52 +00:00
|
|
|
|
2009-10-13 22:27:54 +00:00
|
|
|
sub TZget {
|
2013-01-30 16:03:40 +01:00
|
|
|
my $ts = shift;
|
|
|
|
|
$ts = 0 if not defined($ts);
|
|
|
|
|
my $dt = DateTime->from_epoch(epoch=>$ts);
|
2009-10-13 22:27:54 +00:00
|
|
|
my $tz = GetParam('time', '');
|
|
|
|
|
# setting time= will use the (defined) empty string, so avoid that
|
|
|
|
|
$tz = $defaultTZ unless $tz;
|
|
|
|
|
# converting floating point hours used by a previous version of the
|
|
|
|
|
# code
|
|
|
|
|
$tz = sprintf("%d:%02d", int($tz), int(60*($tz-int($tz))))
|
|
|
|
|
if $tz =~ /^[+-]?\d+\.?\d*$/;
|
|
|
|
|
$dt->set_time_zone($tz);
|
|
|
|
|
return $dt;
|
2004-07-07 11:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldTZCalcDay = \&CalcDay;
|
|
|
|
|
*CalcDay = \&NewTZCalcDay;
|
2009-10-13 22:27:54 +00:00
|
|
|
|
|
|
|
|
sub NewTZCalcDay {
|
|
|
|
|
return TZget(shift)->ymd;
|
2004-07-07 11:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldTZCalcTime = \&CalcTime;
|
|
|
|
|
*CalcTime = \&NewTZCalcTime;
|
2009-10-13 22:27:54 +00:00
|
|
|
|
|
|
|
|
sub NewTZCalcTime {
|
|
|
|
|
return substr(TZget(shift)->hms, 0, 5) # strip seconds
|
|
|
|
|
. (GetParam('time', '') ? '' : ' UTC');
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldTZGetFooterTimestamp = \&GetFooterTimestamp;
|
|
|
|
|
*GetFooterTimestamp = \&NewTZGetFooterTimestamp;
|
2009-10-13 22:27:54 +00:00
|
|
|
|
|
|
|
|
sub NewTZGetFooterTimestamp {
|
|
|
|
|
my $html = OldTZGetFooterTimestamp(@_);
|
|
|
|
|
$html =~ s/(\d\d:\d\d( UTC)?)/ScriptLink('action=tz', $1, 'tz')/e;
|
|
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$Action{tz} = \&DoTZ;
|
|
|
|
|
|
|
|
|
|
sub DoTZ {
|
|
|
|
|
print GetHeader(undef, T('Timezone'));
|
|
|
|
|
print $q->start_div({-class=>'tz content'});
|
|
|
|
|
print GetFormStart();
|
|
|
|
|
my @names = DateTime::TimeZone->all_names;
|
|
|
|
|
print $q->p(T('Pick your timezone:'),
|
|
|
|
|
$q->popup_menu(-name=>'time',
|
|
|
|
|
-values=>\@names,
|
|
|
|
|
-default=>GetParam('time', $defaultTZ)),
|
|
|
|
|
$q->submit('dotz', T('Set')));
|
2014-10-10 16:43:01 +02:00
|
|
|
print $q->end_form . $q->end_div();
|
2009-10-13 22:27:54 +00:00
|
|
|
PrintFooter();
|
|
|
|
|
}
|