summaryrefslogtreecommitdiff
path: root/fml/lib/Mail/Message
diff options
context:
space:
mode:
authorfukachan <fukachan>2003-07-21 10:37:12 +0000
committerfukachan <fukachan>2003-07-21 10:37:12 +0000
commitabb87ebf2e413f500648cd38c5d22df15c62bdd7 (patch)
tree15798d31447f2d6297d38db1e3e4812ba7b8ea53 /fml/lib/Mail/Message
parenta85de35fc6dcd6c0ade02d04f688483c7c5b9c0b (diff)
downloadfml8-abb87ebf2e413f500648cd38c5d22df15c62bdd7.tar.gz
fml8-abb87ebf2e413f500648cd38c5d22df15c62bdd7.tar.bz2
fml8-abb87ebf2e413f500648cd38c5d22df15c62bdd7.zip
method-ify date_to_unixtime() of Mail::Message::Date.
Diffstat (limited to 'fml/lib/Mail/Message')
-rw-r--r--fml/lib/Mail/Message/Date.pm77
1 files changed, 36 insertions, 41 deletions
diff --git a/fml/lib/Mail/Message/Date.pm b/fml/lib/Mail/Message/Date.pm
index 819e6c51..4ad54071 100644
--- a/fml/lib/Mail/Message/Date.pm
+++ b/fml/lib/Mail/Message/Date.pm
@@ -2,7 +2,7 @@
#
# Copyright (C) 2000,2001,2002,2003 Ken'ichi Fukamachi
#
-# $FML: Date.pm,v 1.19 2003/01/26 03:23:10 fukachan Exp $
+# $FML: Date.pm,v 1.20 2003/03/14 06:53:01 fukachan Exp $
#
package Mail::Message::Date;
@@ -279,29 +279,19 @@ sub _log
# Descriptions: convert Date: string to UNIXTIME (sec)
-# Arguments: STR($in)
+# Arguments: OBJ($self) STR($in)
# Side Effects: none
# Return Value: NUM(unix time)
sub date_to_unixtime
{
- my ($in) = @_;
- my ($input) = $in;
- my ($day, $month, $year, $hour, $min, $sec, $pm);
- my ($shift, $shift_t, $shift_m);
- my (%month);
- my ($zone);
-
- # cheap sanity, but ok?;)
+ my ($self, $in) = @_;
+ my ($day, %month, $month, $year, $hour, $min, $sec, $pm, $zone,
+ $shift, $shift_t, $shift_m);
+
+ # cheap sanity, but "return 0" is ok?;)
return 0 unless defined $in;
return 0 unless $in;
- # XXX-TODO: method-ify date_to_unixtime() ?
- # XXX-TODO: more documents
-
- $in =~ s/[\s\n]*$//;
-
- require 'timelocal.pl';
-
# hints
my $c = 1;
for my $month ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
@@ -309,6 +299,9 @@ sub date_to_unixtime
$month{ $month } = $c++;
}
+ # $in = clean up-ed string. $input = original one.
+ my $input = $in;
+ $in =~ s/[\s\n]*$//;
if ($in =~ /([A-Z]+)\s*$/) {
$zone = $1;
if ($zone{$zone} ne "") {
@@ -332,15 +325,15 @@ sub date_to_unixtime
if ($in =~
/(\d+)\s+(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+([\+\-])(\d\d)(\d\d)/) {
if ($debug_mti) { print STDERR "Date2UnixTime: Standard\n";}
- $day = $1;
- $month = ($month{$2} || $month) - 1;
- $year = $3 > 1900 ? $3 - 1900 : $3;
- $hour = $4;
- $min = $5;
- $sec = $6;
+ $day = $1;
+ $month = ($month{$2} || $month) - 1;
+ $year = $3 > 1900 ? $3 - 1900 : $3;
+ $hour = $4;
+ $min = $5;
+ $sec = $6;
# time zone
- $pm = $7;
+ $pm = $7;
$shift_t = $8;
$shift_m = $9;
}
@@ -350,15 +343,15 @@ sub date_to_unixtime
print STDERR "Date2UnixTime: Standard without \$sec\n";
}
- $day = $1;
- $month = ($month{$2} || $month) - 1;
- $year = $3 > 1900 ? $3 - 1900 : $3;
- $hour = $4;
- $min = $5;
- $sec = 0;
+ $day = $1;
+ $month = ($month{$2} || $month) - 1;
+ $year = $3 > 1900 ? $3 - 1900 : $3;
+ $hour = $4;
+ $min = $5;
+ $sec = 0;
# time zone
- $pm = $6;
+ $pm = $6;
$shift_t = $7;
$shift_m = $8;
}
@@ -366,15 +359,15 @@ sub date_to_unixtime
# no timezone case ... WHAT SHOULD WE DO ? ;_;
elsif ($in =~ /([A-Za-z]+)\s+(\d{1,2})\s+(\d+):(\d+):(\d+)\s+(\d{4})\s*/) {
if ($debug_mti) { print STDERR "Date2UnixTime: Japan specific?\n";}
- $month = ($month{$1} || $month) - 1;
- $day = $2;
- $hour = $3;
- $min = $4;
- $sec = $5;
- $year = $6 > 1900 ? $6 - 1900 : $6;
+ $month = ($month{$1} || $month) - 1;
+ $day = $2;
+ $hour = $3;
+ $min = $4;
+ $sec = $5;
+ $year = $6 > 1900 ? $6 - 1900 : $6;
# time zone
- $pm = '+';
+ $pm = '+';
$shift_t = '09';
$shift_m = '00';
}
@@ -398,13 +391,15 @@ sub date_to_unixtime
return 0;
}
- # get gmtime
+ # calculate shift between local time and UTC
$shift_t =~ s/^0*//;
$shift_m =~ s/^0*//;
$shift_m = 0 unless $shift_m;
+ $shift = $shift_t + ($shift_m/60);
+ $shift = ($pm eq '+' ? -1 : +1) * $shift;
- $shift = $shift_t + ($shift_m/60);
- $shift = ($pm eq '+' ? -1 : +1) * $shift;
+ # conversion to gmtime (UTC)
+ require 'timelocal.pl';
if ($debug_mti) {
print STDERR