# Copyright (C) 2004, 2009 Alex Schroeder <alex@gnu.org> # Copyright (C) 2004 Zuytdorp Survivor # # 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. # # 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. # # You should have received a copy of the GNU General Public License along with # this program. If not, see <http://www.gnu.org/licenses/>. use strict; use v5.10; AddModuleDescription('atlantic-timezone.pl', 'Custom Timezone Extension', undef, '2.3.15-26-gc2cf3e7b'); use DateTime; use DateTime::TimeZone; our ($q); our ($defaultTZ); $defaultTZ = 'America/Halifax'; sub TZget { my $ts = shift; $ts = 0 if not defined($ts); my $dt = DateTime->from_epoch(epoch=>$ts); 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; } *OldTZCalcDay = \&CalcDay; *CalcDay = \&NewTZCalcDay; sub NewTZCalcDay { return TZget(shift)->ymd; } *OldTZCalcTime = \&CalcTime; *CalcTime = \&NewTZCalcTime; sub NewTZCalcTime { return substr(TZget(shift)->hms, 0, 5) # strip seconds . (GetParam('time', '') ? '' : ' '); }