Skip to content

Commit

Permalink
Fix FORMAT::XML::convertToUnixTime for issue #43
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliaratnikova authored Jul 28, 2017
1 parent dc668ef commit 462e90c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions SpaceMon/Format/XML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ sub lookupTimeStamp{
}

sub convertToUnixTime {
# parses time formats like "2012-02-27T12:33:23.902495" or "2012-02-20T14:46:39Z"
# parses time formats like "2012-02-27T12:33:23.902495" (local) or "2012-02-20T14:46:39Z" (UTC)
# and returns unix time or undef if not parsable.
my ($time) = shift;
my $unixTime = undef;
my ($localtime, $mon, $year, $d, $t, @d, @t);
if ($time =~ m/^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)\D+/)
{$unixTime = timelocal($6, $5, $4, $3, $2-1, $1-1900)}
#$localtime = localtime($unixTime);
#print "the localtime:", $localtime->mon+1," ", $localtime->year+1900, "\n";
return $unixTime;
if ($time =~ m/^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)(\D+)/) {
if ($7 eq "Z") {
return timegm($6, $5, $4, $3, $2-1, $1-1900);
} else {
return timelocal($6, $5, $4, $3, $2-1, $1-1900);
}
} else {
return undef
}
}

1;

0 comments on commit 462e90c

Please sign in to comment.