root/misc/timezonecvt

Revision 1959 (checked in by miyagawa, 14 years ago)

use Pod::Usage

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use DateTime;
5 use DateTime::TimeZone;
6 use Date::Manip;
7 use Getopt::Long;
8 use Pod::Usage;
9
10 my $from = "America/Los_Angeles";
11 my $to   = "Asia/Tokyo";
12
13 GetOptions('--from=s', \$from, '--to=s' => \$to);
14 Getopt::Long::Configure("bundling");
15
16 my $date = join ' ', @ARGV or pod2usage(1);
17 my @date = localtime(UnixDate(ParseDateString($date), "%s"));
18
19 my $dt = DateTime->new(
20     second => $date[0],
21     minute => $date[1],
22     hour   => $date[2],
23     day    => $date[3],
24     month  => $date[4] + 1,
25     year   => $date[5] + 1900,
26     time_zone => $from,
27 );
28
29 my $from_date = $dt->ymd('/') . ' ' . $dt->hms(':');
30 $dt->set_time_zone($to);
31 my $to_date   = $dt->ymd('/') . ' ' . $dt->hms(':');
32
33 print <<EOF;
34 $from_date ($from)
35 $to_date ($to)
36 EOF
37
38 __END__
39
40 =head1 NAME
41
42 timezonecvt - Convert timezone for given datetime
43
44 =head1 SYNOPSIS
45
46   timezonecvt 9/12 13:45
47   timezonecvt -f Asia/Tokyo -t America/New_York tomorrow 3pm
48
49 =cut
Note: See TracBrowser for help on using the browser.