CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Time Conversion Issue: Edit Log



TheBigAmbulance
Novice

Jul 13, 2012, 9:22 AM


Views: 5633
Time Conversion Issue

Greetings all,

I have a bit of a problem. I work for an ISP and have had to develop an 'newbie' perl script to parse copyright infringement letters sent to me in xml and msg. I have a good script, and it works well with the exception of time zones. In my larger script (attached to this post - too large to paste it all), I have the time stamp parsed out of either xml or mime into a variable called '$rawtime' that comes from $array[$i][1]. $rawtime data looks like this:


Code
2012-07-06T03:23:56.000Z 
2012-07-06T03:33:53.000Z
2012-07-06T03:36:48.000Z
2012-07-06T03:36:08.000Z
2012-07-06T03:35:25.000Z
2012-06-29T12:50:12-04:00
2012-06-29T11:20:53-04:00
2012-07-01T00:59:48-04:00
2012-07-01T00:59:44-04:00
2012-07-01T07:51:14-04:00
2012-07-01T10:00:31-04:00
2012-07-01T17:20:13-04:00
2012-07-01T21:19:26-04:00
2012-07-01T22:01:10-04:00
2012-07-02T13:21:11-04:00
2012-07-02T11:15:02-04:00
2012-07-02T18:10:37-04:00
2012-07-04T23:55:51-04:00
2012-07-04T22:19:59-04:00
2012-07-05T17:47:26-04:00
2012-07-06T08:35:53-04:00
2012-07-06T13:04:17-04:00
2012-07-06T17:56:16-04:00
2012-07-07T17:52:40-04:00
2012-07-09T07:46:29-04:00
2012-07-01T18:14:39Z
2012-07-09T11:06:50Z
2012-06-29T16:44:37Z
2012-07-02T19:20:29Z


As you can see, I am dealing with all sorts of variable times. Most are in Zulu time, but some of these 'yahoos' send their local time zone.

Here is the piece of my perl script that deals with the time:


Code
for (my $i = 0; $i < $arrayc; $i++) { 
my $rawtime = $array[$i][1];
print "Time - " . $rawtime . "\n";
my $dt = Date_ConvTZ($rawtime,'GMT','America/North_Dakota/Center');
my $year = substr($dt , 0 , 4);
my $month = substr($dt , 4 , 2);
my $date = substr($dt , 6 , 2);
my $hour = substr($dt , 8 , 2);
my $minute = substr($dt , 11 , 2);
my $sec = substr($dt , 14 , 2);
my $AMorPM;

if ($hour > 12) {
$hour = $hour - 12;
$AMorPM = "PM";
} elsif ($hour < 12) {
$AMorPM = "AM";
}

my $time = $year."-".$month."-".$date." ".$hour.":".$minute.":".$sec." ".$AMorPM;
$array[$i][1] = $time
}


So what I think I am going to have to do is have the script figure out which time zone the letter references, and then convert it to CST so it will match my logs.

Anyone have an opinion on what to do? Me not being a 100% perl programmer, I'm sure someone will be able to redo the portion above in like 4 lines! hehe

TIA!


(This post was edited by TheBigAmbulance on Jul 13, 2012, 9:50 AM)
Attachments: script.pl (5.99 KB)


Edit Log:
Post edited by TheBigAmbulance (Novice) on Jul 13, 2012, 9:23 AM
Post edited by TheBigAmbulance (Novice) on Jul 13, 2012, 9:50 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives