root/misc/timezonecvt

Revision 1937 (checked in by miyagawa, 13 years ago)

add timezonecvt

  • 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::Parse;
7 use Getopt::Long;
8
9 my $from = "America/Los_Angeles";
10 my $to   = "Asia/Tokyo";
11
12 GetOptions('--from=s', \$from, '--to=s' => \$to);
13 Getopt::Long::Configure("bundling");
14
15 my $date = join ' ', @ARGV or die "Usage: timezonecvt [-f From] [-t To] date\n";
16 my @date = strptime($date);
17
18 my $dt = DateTime->new(
19     second => $date[0],
20     minute => $date[1],
21     hour   => $date[2],
22     day    => $date[3],
23     month  => $date[4] + 1,
24     year   => ($date[5] || (localtime)[5]) + 1900,
25     time_zone => $from,
26 );
27
28 my $from_date = $dt->ymd('/') . ' ' . $dt->hms(':');
29 $dt->set_time_zone($to);
30 my $to_date   = $dt->ymd('/') . ' ' . $dt->hms(':');
31
32 print <<EOF;
33 $from_date ($from)
34 $to_date ($to)
35 EOF
Note: See TracBrowser for help on using the browser.