root/misc/timezonecvt

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

added DoW

  • 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 $to_date = $dt->clone;
30 $to_date->set_time_zone($to);
31
32 for my $date ($dt, $to_date) {
33     print $date->strftime("%Y/%m/%d (%a) %H:%M:%S "), $date->time_zone->name, ($date->is_dst ? '*' : ''), "\n";
34 }
35
36 __END__
37
38 =head1 NAME
39
40 timezonecvt - Convert timezone for given datetime
41
42 =head1 SYNOPSIS
43
44   timezonecvt 9/12 13:45
45   timezonecvt -f Asia/Tokyo -t America/New_York tomorrow 3pm
46
47 =cut
Note: See TracBrowser for help on using the browser.