Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

release

  • Loading branch information...
commit b7b77a5d34b95b637bda470e488fad3fd84df2b0 1 parent 81b01a8
Ricardo Signes authored
Showing with 45 additions and 36 deletions.
  1. +6 −0 Changes
  2. +1 −1  Makefile.PL
  3. +1 −1  README
  4. +37 −34 lib/Email/Date/Format.pm
6 Changes
View
@@ -1,4 +1,10 @@
Revision history for Email-Date-Format
+1.002 2007-12-03
+ brings all docs into agreement: this produces 2822, not 822, dates
+
+1.001 2007-12-01
+ be isa Exporter, since "use Exporter 'import'" wasn't in 5.006
+
1.000 2007-11-30
refactored from Email::Date to avoid large prereq chain
2  Makefile.PL
View
@@ -3,7 +3,7 @@ use ExtUtils::MakeMaker;
WriteMakefile (
AUTHOR => 'Ricardo SIGNES <rjbs@cpan.org>',
- ABSTRACT => "produce RFC 822 date strings",
+ ABSTRACT => "produce RFC 8822 date strings",
NAME => 'Email::Date::Format',
(eval { ExtUtils::MakeMaker->VERSION(6.21) } ? (LICENSE => 'perl') : ()),
PREREQ_PM => {
2  README
View
@@ -1,3 +1,3 @@
-This module can be used to emit RFC 822 style date strings.
+This module can be used to emit RFC 2822 style date strings.
71 lib/Email/Date/Format.pm
View
@@ -4,15 +4,16 @@ use warnings;
package Email::Date::Format;
-our $VERSION = '1.000';
+our $VERSION = '1.002';
our @EXPORT_OK = qw[email_date email_gmdate];
-use Exporter 'import';
+use Exporter;
+BEGIN { our @ISA = 'Exporter' }
use Time::Local ();
=head1 NAME
-Email::Date::Format - produce RFC 822 date strings
+Email::Date::Format - produce RFC 2822 date strings
=head1 SYNOPSIS
@@ -21,16 +22,17 @@ Email::Date::Format - produce RFC 822 date strings
my $header = email_date($date->epoch);
Email::Simple->create(
- header => [
- Date => $header,
- ],
- body => '...',
+ header => [
+ Date => $header,
+ ],
+ body => '...',
);
=head1 DESCRIPTION
This module provides a simple means for generating an RFC 2822 compliant
-datetime string.
+datetime string. (In case you care, they're not RFC 822 dates, because they
+use a four digit year, which is not allowed in RFC 822.)
=head2 FUNCTIONS
@@ -60,38 +62,39 @@ C<format_gmdate> is exported only if requested.
=cut
sub _tz_diff {
- my ($time) = @_;
+ my ($time) = @_;
- my $diff = Time::Local::timegm(localtime $time)
- - Time::Local::timegm(gmtime $time);
+ my $diff = Time::Local::timegm(localtime $time)
+ - Time::Local::timegm(gmtime $time);
- my $direc = $diff < 0 ? '-' : '+';
- $diff = abs $diff;
- my $tz_hr = int( $diff / 3600 );
- my $tz_mi = int( $diff / 60 - $tz_hr * 60 );
+ my $direc = $diff < 0 ? '-' : '+';
+ $diff = abs $diff;
+ my $tz_hr = int( $diff / 3600 );
+ my $tz_mi = int( $diff / 60 - $tz_hr * 60 );
- return ($direc, $tz_hr, $tz_mi);
+ return ($direc, $tz_hr, $tz_mi);
}
sub _format_date {
- my ($local) = @_;
-
- sub {
- my ($time) = @_;
- $time = time unless defined $time;
-
- my ($sec, $min, $hour, $mday, $mon, $year, $wday) =
- $local ? (localtime $time) : (gmtime $time);
- my $day = (qw[Sun Mon Tue Wed Thu Fri Sat])[$wday];
- my $month = (qw[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec])[$mon];
- $year += 1900;
-
- my ($direc, $tz_hr, $tz_mi) = $local ? _tz_diff($time)
- : ('+', 0, 0);
-
- sprintf "%s, %d %s %d %02d:%02d:%02d %s%02d%02d",
- $day, $mday, $month, $year, $hour, $min, $sec, $direc, $tz_hr, $tz_mi;
- }
+ my ($local) = @_;
+
+ sub {
+ my ($time) = @_;
+ $time = time unless defined $time;
+
+ my ($sec, $min, $hour, $mday, $mon, $year, $wday)
+ = $local ? (localtime $time) : (gmtime $time);
+
+ my $day = (qw[Sun Mon Tue Wed Thu Fri Sat])[$wday];
+ my $month = (qw[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec])[$mon];
+ $year += 1900;
+
+ my ($direc, $tz_hr, $tz_mi) = $local ? _tz_diff($time)
+ : ('+', 0, 0);
+
+ sprintf "%s, %d %s %d %02d:%02d:%02d %s%02d%02d",
+ $day, $mday, $month, $year, $hour, $min, $sec, $direc, $tz_hr, $tz_mi;
+ }
}
BEGIN {
Please sign in to comment.
Something went wrong with that request. Please try again.