12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- use strict;
- use v5.10;
- AddModuleDescription('timezone.pl', 'Timezone Extension');
- use DateTime;
- use DateTime::TimeZone;
- our ($q, %Action, %CookieParameters);
- our ($defaultTZ);
- $defaultTZ = 'UTC';
- $CookieParameters{time} = '';
- sub TZget {
- my $ts = shift;
- $ts = 0 if not defined($ts);
- my $dt = DateTime->from_epoch(epoch=>$ts);
- my $tz = GetParam('time', '');
-
- $tz = $defaultTZ unless $tz;
-
-
- $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)
- . (GetParam('time', '') ? '' : ' UTC');
- }
- *OldTZGetFooterTimestamp = \&GetFooterTimestamp;
- *GetFooterTimestamp = \&NewTZGetFooterTimestamp;
- 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')));
- print $q->end_form . $q->end_div();
- PrintFooter();
- }
|