5 package Email::Date::Format;
7 our $VERSION = '1.002';
8 our @EXPORT_OK = qw[email_date email_gmdate];
11 BEGIN { our @ISA = 'Exporter' }
16 Email::Date::Format - produce RFC 2822 date strings
20 use Email::Date::Format qw(email_date);
22 my $header = email_date($date->epoch);
24 Email::Simple->create(
33 This module provides a simple means for generating an RFC 2822 compliant
34 datetime string. (In case you care, they're not RFC 822 dates, because they
35 use a four digit year, which is not allowed in RFC 822.)
43 my $date = email_date; # now
44 my $date = email_date( time - 60*60 ); # one hour ago
46 C<email_date> accepts an epoch value, such as the one returned by C<time>.
47 It returns a string representing the date and time of the input, as
48 specified in RFC 2822. If no input value is provided, the current value
51 C<format_date> is exported only if requested.
55 my $date = email_gmdate;
57 C<email_gmdate> is identical to C<email_date>, but it will return a string
58 indicating the time in Greenwich Mean Time, rather than local time.
60 C<format_gmdate> is exported only if requested.
67 my $diff = Time::Local::timegm(localtime $time)
68 - Time::Local::timegm(gmtime $time);
70 my $direc = $diff < 0 ? '-' : '+';
72 my $tz_hr = int( $diff / 3600 );
73 my $tz_mi = int( $diff / 60 - $tz_hr * 60 );
75 return ($direc, $tz_hr, $tz_mi);
83 $time = time unless defined $time;
85 my ($sec, $min, $hour, $mday, $mon, $year, $wday)
86 = $local ? (localtime $time) : (gmtime $time);
88 my $day = (qw[Sun Mon Tue Wed Thu Fri Sat])[$wday];
89 my $month = (qw[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec])[$mon];
92 my ($direc, $tz_hr, $tz_mi) = $local ? _tz_diff($time)
95 sprintf "%s, %d %s %d %02d:%02d:%02d %s%02d%02d",
96 $day, $mday, $month, $year, $hour, $min, $sec, $direc, $tz_hr, $tz_mi;
101 *email_date = _format_date(1);
102 *email_gmdate = _format_date(0);
111 =head1 PERL EMAIL PROJECT
113 This module is maintained by the Perl Email Project
115 L<http://emailproject.perl.org/wiki/Email::Date::Format>
119 Ricardo SIGNES, <F<rjbs@cpan.org>>.
121 Adapted from Email::Date, by Casey West.
125 Copyright (c) 2007, Ricarod SIGNES. This module is free software; you can
126 redistribute it and/or modify it under the same terms as Perl itself.