Dear PerlMonks, Please help me. This is my first post on SOPM so beg you forgive any indiscretions.
The perl code I have managed to "put together" is not giving me the right answers. Here is a data sample that I want it to process:
20050526~18:15:06 GMT 20040401~01:12:02 GMT 20060201~00:59:01 GMT 20060401~01:01:01 EST 20040201~10:10:01 -0600 20010901~04:23:05 -0400 20050526~18:15:06 GMT 20040401~01:12:02 GMT 20000101~00:59:01 -0200 19841223~04:22:06 MST
And here is the perl code cleaned up a bit with PerlTidy
#!/usr/bin/perl -w use strict; use Date::Manip; Date_Init("TZ=EST"); #set TimeZone to Eastern Daylight Savings Time { my $input = $ARGV[0]; #returns filename from command line my $thetmz; #time zone for that line my ( $date, $time); #from file chomp $input; #strip the carriage return sub convertthetmz { $datetime = ( "$date" . "$time" ) ; #$date and #time from subroutine call and concats them $converteddate = ParseDate("$datetime"); #date-time strng $converteddate =Date_ConvTZ("$converteddate", $thetmz, "EST" ) ; #converts from any tmz to EST print("$converteddate~$from~$to\n"); } open( DATAFILE, "$input" ) || die("Can not open $input:!\n"); #access the file while (<DATAFILE>) { chomp $_; ( $date, $time) = split( "~", $_ ); #split date/time my $testfortmz = substr $time, -3; #last 4 chars of str if ( "$testfortmz" == "-0400" ) { $thetmz = "AST"; convertthetmz( $thetmz, $date, $time, $from, $to ); } elsif ( "$testfortmz" == "-0600" ) { $thetmz = "CST"; convertthetmz( $thetmz, $date, $time, $from, $to ); } elsif ( "$testfortmz" =~ " GMT" ) { $thetmz = "GMT"; convertthetmz( $thetmz, $date, $time, $from, $to ); } else #this is need to work for some reason { my $nochangedate; $nochangedate = ( ParseDate("$date.$time") ); print("$nochangedate~$from~$to\n"); } } close(DATAFILE); }
The result that I get with the above data sample is the following:
2005052613:15:06 2004033120:12:02 2006013119:59:01 2006040101:01:01 2004020112:10:01 2001090102:23:05 2005052613:15:06 2004033120:12:02 1999123121:59:01 1984122306:22:06
Some of these are correct but others are I believe wrong.
Shouldn't 20040201~10:10:01 -0600 be 2004020111:10:01 EST since there is only 1 hour difference between -600 and -0500?
Obviously I did something wrong. I would greatly appreciate your assistance! Thank you kindly!

In reply to TimeZone Assistance Requested by Knoperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.