| 1 |
#!/usr/bin/perl -w |
| 2 |
# Copyright (c) 2009-2026 Sullivan Beck. All rights reserved. |
| 3 |
# This program is free software; you can redistribute it and/or modify it |
| 4 |
# under the same terms as Perl itself. |
| 5 |
|
| 6 |
############################################################################### |
| 7 |
############################################################################### |
| 8 |
|
| 9 |
require 5.010000; |
| 10 |
use Date::Manip::Date; |
| 11 |
use IO::File; |
| 12 |
use strict; |
| 13 |
use warnings; |
| 14 |
|
| 15 |
############################################################################### |
| 16 |
# HELP |
| 17 |
############################################################################### |
| 18 |
|
| 19 |
our($usage); |
| 20 |
my $COM = $0; |
| 21 |
$COM =~ s/^.*\///; |
| 22 |
|
| 23 |
$usage= |
| 24 |
"usage: $COM OPTIONS [ZONE ZONE ...] |
| 25 |
-h/--help : Print help. |
| 26 |
|
| 27 |
-v/--vebose : Prints a full description of each |
| 28 |
timezone. |
| 29 |
|
| 30 |
-c/--cutoff YEAR : Cut off verbose output near the |
| 31 |
start of YEAR. |
| 32 |
|
| 33 |
"; |
| 34 |
|
| 35 |
=pod |
| 36 |
|
| 37 |
=head1 NAME |
| 38 |
|
| 39 |
dm_zdump - timezone dumper |
| 40 |
|
| 41 |
=head1 SYNOPSIS |
| 42 |
|
| 43 |
This performs the same operation as the unix 'zdump' command, but using |
| 44 |
the Date::Manip module. |
| 45 |
|
| 46 |
dm_zdump [-v] [-c YEAR] [ZONE ZONE ...] |
| 47 |
|
| 48 |
=head1 DESCRIPTION |
| 49 |
|
| 50 |
This displays the current time in each ZONE named on the command line |
| 51 |
unless the -v option is given. |
| 52 |
|
| 53 |
=over 4 |
| 54 |
|
| 55 |
=item -h, --help |
| 56 |
|
| 57 |
Print online help. |
| 58 |
|
| 59 |
=item -v, --verbose |
| 60 |
|
| 61 |
This displays all critical dates (i.e. the times when a time change |
| 62 |
occurs due to the timezone description) for each of the timezones |
| 63 |
listed (or the local timezone if none are listed). |
| 64 |
|
| 65 |
Each critical date is printed as two lines of output: the last second |
| 66 |
before the change occurs, and the first second of the new time. |
| 67 |
|
| 68 |
By default, all critical dates from Jan 1, 0001 until the year 20 years |
| 69 |
in the future are printed, but this can be changed with the -c option. |
| 70 |
|
| 71 |
=item -c, --cutoff YEAR |
| 72 |
|
| 73 |
This specifies the cutoff year. All critical dates up to the start of |
| 74 |
YEAR are given. The GMT time Jan 01, YEAR at 00:00:00 is the cutoff |
| 75 |
time. |
| 76 |
|
| 77 |
=back |
| 78 |
|
| 79 |
=head1 KNOWN BUGS |
| 80 |
|
| 81 |
None known. |
| 82 |
|
| 83 |
=head1 BUGS AND QUESTIONS |
| 84 |
|
| 85 |
Please refer to the Date::Manip::Problems documentation for |
| 86 |
information on submitting bug reports or questions to the author. |
| 87 |
|
| 88 |
=head1 SEE ALSO |
| 89 |
|
| 90 |
Date::Manip::Date |
| 91 |
|
| 92 |
=head1 LICENSE |
| 93 |
|
| 94 |
This script is free software; you can redistribute it and/or |
| 95 |
modify it under the same terms as Perl itself. |
| 96 |
|
| 97 |
=head1 AUTHOR |
| 98 |
|
| 99 |
Sullivan Beck ([email protected]) |
| 100 |
|
| 101 |
=cut |
| 102 |
|
| 103 |
############################################################################### |
| 104 |
# PARSE ARGUMENTS |
| 105 |
############################################################################### |
| 106 |
|
| 107 |
our($date,$dmt,$dmb,$verbose,$cutoff,@zone); |
| 108 |
|
| 109 |
$date = new Date::Manip::Date "now"; |
| 110 |
$dmt = $date->tz(); |
| 111 |
$dmb = $date->base(); |
| 112 |
$cutoff = $date->printf('%Y') + 21; |
| 113 |
$verbose = 0; |
| 114 |
|
| 115 |
while ($_ = shift) { |
| 116 |
|
| 117 |
(print $usage), exit if ($_ eq "-h" || $_ eq "--help"); |
| 118 |
|
| 119 |
$verbose = 1, next if ($_ eq "-v" || $_ eq "--verbose"); |
| 120 |
$cutoff = shift, next if ($_ eq "-c" || $_ eq "--cutoff"); |
| 121 |
|
| 122 |
@zone = ($_,@ARGV); |
| 123 |
last; |
| 124 |
} |
| 125 |
|
| 126 |
if (@zone) { |
| 127 |
foreach my $z (@zone) { |
| 128 |
my $tmp = $dmt->zone($z); |
| 129 |
if (! $tmp) { |
| 130 |
die "ERROR: invalid timezone: $z\n"; |
| 131 |
} |
| 132 |
$z = $tmp; |
| 133 |
} |
| 134 |
|
| 135 |
} else { |
| 136 |
@zone = $dmt->curr_zone(); |
| 137 |
} |
| 138 |
|
| 139 |
############################################################################ |
| 140 |
# MAIN PROGRAM |
| 141 |
############################################################################ |
| 142 |
|
| 143 |
if ($verbose) { |
| 144 |
foreach my $z (@zone) { |
| 145 |
my @per = $dmt->periods($z,undef,$cutoff); |
| 146 |
foreach my $per (@per) { |
| 147 |
my($startUT,$startLT,$offsetstr,$offset,$abbrev,$isdst,$endUT,$endLT) |
| 148 |
= @$per; |
| 149 |
|
| 150 |
$startUT = datestr($startUT); |
| 151 |
$startLT = datestr($startLT); |
| 152 |
$endUT = datestr($endUT); |
| 153 |
$endLT = datestr($endLT); |
| 154 |
my $gmtoff = $$offset[0]*3600 + $$offset[1]*60 + $$offset[2]; |
| 155 |
|
| 156 |
print "$z $startUT UT = $startLT $abbrev isdst=$isdst gmtoff=$gmtoff\n"; |
| 157 |
print "$z $endUT UT = $endLT $abbrev isdst=$isdst gmtoff=$gmtoff\n"; |
| 158 |
} |
| 159 |
print "\n" if ($#zone != 0); |
| 160 |
} |
| 161 |
|
| 162 |
} else { |
| 163 |
my $wid = 0; |
| 164 |
foreach my $z (@zone) { |
| 165 |
$wid = length($z) if (length($z) > $wid); |
| 166 |
} |
| 167 |
|
| 168 |
foreach my $z (@zone) { |
| 169 |
$date->convert($z); |
| 170 |
print $z," "x($wid-length($z))," ",$date->printf('%a %b %e %H:%M:%S %Y %Z'),"\n"; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
sub datestr { |
| 175 |
my($date) = @_; |
| 176 |
|
| 177 |
my %mon = qw(1 Jan 2 Feb 3 Mar 4 Apr 5 May 6 Jun |
| 178 |
7 Jul 8 Aug 9 Sep 10 Oct 11 Nov 12 Dec); |
| 179 |
my %dow = qw(1 Mon 2 Tue 3 Wed 4 Thu 5 Fri 6 Sat 7 Sun); |
| 180 |
|
| 181 |
my($y,$m,$d,$h,$mn,$s) = @$date; |
| 182 |
my $dow = $dmb->day_of_week($date); |
| 183 |
$dow = $dow{$dow}; |
| 184 |
my $mon = $mon{$m+0}; |
| 185 |
$y="0$y" while (length($y) < 4); |
| 186 |
$d=" $d" if (length($d) < 2); |
| 187 |
$h="0$h" if (length($h) < 2); |
| 188 |
$mn="0$mn" if (length($mn) < 2); |
| 189 |
$s="0$s" if (length($s) < 2); |
| 190 |
|
| 191 |
return "$dow $mon $d $h:$mn:$s $y"; |
| 192 |
} |
| 193 |
|
| 194 |
# Local Variables: |
| 195 |
# mode: cperl |
| 196 |
# indent-tabs-mode: nil |
| 197 |
# cperl-indent-level: 3 |
| 198 |
# cperl-continued-statement-offset: 2 |
| 199 |
# cperl-continued-brace-offset: 0 |
| 200 |
# cperl-brace-offset: 0 |
| 201 |
# cperl-brace-imaginary-offset: 0 |
| 202 |
# cperl-label-offset: 0 |
| 203 |
# End: |