Morten Guldager skrev i meddelelsen ...
>Hejsa,
>
>Jeg vil gerne omsætte nedenstående til sekunder siden 1970
>...
>Det er Date: felter fra usenet artikler.
Nøj, hvor smart at der findes moduler til den slags - som Peter og Mads
skriver. Jeg var ikke vaksere end at skrive en rutine selv, da jeg
skulle bruge én. Jeg ved ikke om den er hurtig, men du må gerne
prøve...
-- Klaus.
# decode_date - convert a Date: field to its (local) time representation
sub decode_date {
my $date = shift;
$date = $date->{date} if ref $date eq 'HASH';
$date =~ /(?: \w{3} \s* ,)? \s* # wday "," (not used)
(\d{1,2}) \s* # $1 = mday
(\w{3}) \s* # $2 = month
(\d{2,4}) \s* # $3 = year
(\d{2}) \s* # $4 = hours
: \s* # ":"
(\d{2}) \s* # $5 = minutes
:? \s* # [":"]
(\d{2})? \s* # [$6 = seconds]
(\w{1,3} | [+-] \s* \d{4}) # $7 = TZ (or offset)
/x;
my ($mday, $month, $year, $hour, $min, $sec, $tz)
= ($1, $2, $3, $4, $5, $6, $7);
return -1 if not $mday;
my %month = ( Jan => 0, Feb => 1, Mar => 2, Apr => 3,
May => 4, Jun => 5, Jul => 6, Aug => 7,
Sep => 8, Oct => 9, Nov => 10, Dec => 11 );
my $mil = "MLKIHGFEDCBAZNOPQRSTUVXY";
$month = $month{$month}; #
$tz =~ s/\s*//g;
for ($tz) {
/UTC?|GMT/ and $tz = 0, last;
/EDT/ and $tz = -4, last;
/EST|CDT/ and $tz = -5, last;
/CST|MDT/ and $tz = -6, last;
/MST|PDT/ and $tz = -7, last;
/PST/ and $tz = -8, last;
/[A-Z]/ and $tz = index($mil, $tz) - 12, last;
/\+(\d\d)(\d\d)/ and $tz = $1 + $2 / 60, last;
/\-(\d\d)(\d\d)/ and $tz = - $1 - $2 / 60, last;
}
return timelocal($sec, $min, $hour, $mday, $month, $year) + $tz*3600
+ $TZ;
# (from Time::Local)
}