Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Month '-1' out of range 0..11

by kennethk (Monsignor)
on Mar 18, 2014 at 15:57 UTC ( #1078801=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Month '-1' out of range 0..11
in thread Month '-1' out of range 0..11

Did you try printing the value in $date on line 29? The answer is that some of the values are not what you think, because the following code works fine:

#! /usr/bin/perl use strict; use warnings; use Time::Local; my $iso_time = '2014-03-18T15:41:14Z'; my $expected_epoch = 1 * 60 * 60 + 1 * 60 + 1; my ($date, $time) = split /T/ => $iso_time; my ($year, $mon, $mday) = split /-/ => $date; my $currenttime = time; # get current time from system (epoch time) my $threshold = 900; $year -= 1900; $mon -= 1; my ($hour, $min, $sec) = split /:/ => $time; my $nsec = chop($sec); my $mtime = timegm($sec, $min, $hour, $mday, $mon, $year);
However, without your actual input file, I'm just guessing. Adding warnings and following the advice in Basic debugging checklist will help you track down the issue. Alternatively, I could help you debug if you posted your input file, wrapped in <code> tags.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re^3: Month '-1' out of range 0..11
Select or Download Code
Re^4: Month '-1' out of range 0..11
by swissknife (Novice) on Mar 18, 2014 at 16:14 UTC
    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ScheduleMessage SYSTEM "../schedulev2r3/dtd/schedule-xml.dtd +"> <ScheduleMessage DtdVersion="2" DtdRelease="3"> <MessageIdentification v="8787897987897897" /> <MessageVersion v="097" /> <MessageType v="A01" /> <ProcessType v="A02" /> <ScheduleClassificationType v="A01" /> <SenderIdentification v="9090900" codingScheme="A01" /> <SenderRole v="A01" /> <ReceiverIdentification v="453543453453" codingScheme="A01" /> <ReceiverRole v="A04" /> <MessageDateTime v="2014-03-18T15:41:14Z" /> <ScheduleTimeInterval v="2014-03-13T23:00Z/2014-03-14T23:00Z" /> <ScheduleTimeSeries> <SendersTimeSeriesIdentification v="65765675765" /> <SendersTimeSeriesVersion v="001" /> <BusinessType v="A06" /> <Product v="8716867000016" /> <ObjectAggregation v="A01" /> <InArea v="10YFRkjkjkl" codingScheme="A01" /> <OutArea v="10YCHiuiuoiu" codingScheme="A01" /> <InParty v="jkkljkljlkj" codingScheme="A01" /> <OutParty v="uiouiouoiuo" codingScheme="A01" /> <MeasurementUnit v="MAW" /> <Period> <TimeInterval v="2014-03-13T23:00Z/2014-03-14T23:00Z" /> <Resolution v="PT15M" />

    I had to change the content of file as i am not supposed to share but solving the problem is also important. Please take a look and see if you can find something. alternatively i will go threough the debug steps mentioned in link. Thanks.

      #!/usr/bin/perl -w use strict; use Time::Local; my $finaltime = UTCtoLocal(); print "$finaltime \n"; sub UTCtoLocal { my @ActTime = map {/"(.*?)"/} grep {/MessageDateTime/} (<DATA>); my $iso_time = join("", @ActTime); my $expected_epoch = 1 * 60 * 60 + 1 * 60 + 1; my ($date, $time) = split /T/ => $iso_time; my ($year, $mon, $mday) = split /-/ => $date; $year -= 1900; $mon -= 1; my ($hour, $min, $sec) = split /:/ => $time; my $nsec = chop($sec); my $mtime = timegm($sec, $min, $hour, $mday, $mon, $year); return ($mtime); } __DATA__ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ScheduleMessage SYSTEM "../schedulev2r3/dtd/schedule-xml.dtd +"> <ScheduleMessage DtdVersion="2" DtdRelease="3"> <MessageIdentification v="8787897987897897" /> <MessageVersion v="097" /> <MessageType v="A01" /> <ProcessType v="A02" /> <ScheduleClassificationType v="A01" /> <SenderIdentification v="9090900" codingScheme="A01" /> <SenderRole v="A01" /> <ReceiverIdentification v="453543453453" codingScheme="A01" /> <ReceiverRole v="A04" /> <MessageDateTime v="2014-03-18T15:41:14Z" /> <ScheduleTimeInterval v="2014-03-13T23:00Z/2014-03-14T23:00Z" /> <ScheduleTimeSeries> <SendersTimeSeriesIdentification v="65765675765" /> <SendersTimeSeriesVersion v="001" /> <BusinessType v="A06" /> <Product v="8716867000016" /> <ObjectAggregation v="A01" /> <InArea v="10YFRkjkjkl" codingScheme="A01" /> <OutArea v="10YCHiuiuoiu" codingScheme="A01" /> <InParty v="jkkljkljlkj" codingScheme="A01" /> <OutParty v="uiouiouoiuo" codingScheme="A01" /> <MeasurementUnit v="MAW" /> <Period> <TimeInterval v="2014-03-13T23:00Z/2014-03-14T23:00Z" /> <Resolution v="PT15M" />
      outputs 1395157274 as I would expect. You have scrubbed the issue out of your code. Unless you post material that displays the issue you are referencing, I cannot help.

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re^4: Month '-1' out of range 0..11
by swissknife (Novice) on Mar 18, 2014 at 16:35 UTC
    my OP reference the issue which i am facing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1078801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2014-12-26 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls