summaryrefslogtreecommitdiff
path: root/fml/lib/Mail/Message/Date.pm
diff options
context:
space:
mode:
authorfukachan <fukachan>2003-07-21 13:59:30 +0000
committerfukachan <fukachan>2003-07-21 13:59:30 +0000
commit06f7ffcc353096bfc1a954a9010d27959320058d (patch)
tree1d455a37919b17434f6e77f327cef1ae1b439f72 /fml/lib/Mail/Message/Date.pm
parent6f1a9ee4f370bcc831fea3d4979f2eed024b4b21 (diff)
downloadfml8-06f7ffcc353096bfc1a954a9010d27959320058d.tar.gz
fml8-06f7ffcc353096bfc1a954a9010d27959320058d.tar.bz2
fml8-06f7ffcc353096bfc1a954a9010d27959320058d.zip
implement speculate_timezone() to remove hard-coded timezone +0900 :-).
Diffstat (limited to 'fml/lib/Mail/Message/Date.pm')
-rw-r--r--fml/lib/Mail/Message/Date.pm38
1 files changed, 35 insertions, 3 deletions
diff --git a/fml/lib/Mail/Message/Date.pm b/fml/lib/Mail/Message/Date.pm
index 4ad54071..165d4ce6 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.20 2003/03/14 06:53:01 fukachan Exp $
+# $FML: Date.pm,v 1.21 2003/07/21 10:37:13 fukachan Exp $
#
package Mail::Message::Date;
@@ -88,8 +88,7 @@ sub _date
my @Month = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
- # XXX-TODO: default timezone is +0900. o.k. ? :-)
- $TimeZone ||= '+0900';
+ $TimeZone ||= speculate_timezone();
my ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime($time))[0..6];
$date->{'log_file_style'} =
@@ -414,6 +413,39 @@ sub date_to_unixtime
}
+# Descriptions: speculate timezone and return the string e.g. +0900.
+# Arguments: NUM($_offset)
+# Side Effects: none
+# Return Value: STR
+sub speculate_timezone
+{
+ my ($_offset) = @_;
+
+ use Time::Timezone;
+ my $offset = $_offset || tz_local_offset();
+ my $hour = int(abs($offset)/3600);
+ my $shift = (abs($offset) - $hour*3600)/3600;
+
+ if ($offset > 0) {
+ return sprintf("+%02d%02d", $hour, $shift*60);
+ }
+ elsif ($offset < 0) {
+ return sprintf("-%02d%02d", $hour, $shift*60);
+ }
+ else {
+ return '+0000';
+ }
+}
+
+
+if ($0 eq __FILE__) {
+ print "default\ttimezone = ", speculate_timezone(), "\n";
+ for my $t (qw(-5400 1800 3600 5400 7200)) {
+ print "$t\ttimezone = ", speculate_timezone($t), "\n";
+ }
+}
+
+
=head1 CODING STYLE
See C<http://www.fml.org/software/FNF/> on fml coding style guide.