Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) Standard preamble: ========================================================================
NAMEDateTime::Format::Mail - Convert between DateTime and RFC2822/822 formats
use DateTime::Format::Mail; # From RFC2822 via class method: my $datetime = DateTime::Format::Mail->parse_datetime( "Sat, 29 Mar 2003 22:11:18 -0800" ); print $datetime->ymd('.'); # "2003.03.29" # or via an object my $pf = DateTime::Format::Mail->new(); print $pf->parse_datetime( "Fri, 23 Nov 2001 21:57:24 -0600" )->ymd; # "2001-11-23" # Back to RFC2822 date use DateTime; my $dt = DateTime->new( year => 1979, month => 7, day => 16, hour => 16, minute => 45, second => 20, time_zone => "Australia/Sydney" ); my $str = DateTime::Format::Mail->format_datetime( $dt ); print $str; # "Mon, 16 Jul 1979 16:45:20 +1000" # or via an object $str = $pf->format_datetime( $dt ); print $str; # "Mon, 16 Jul 1979 16:45:20 +1000"
DESCRIPTIONRFCs 2822 and 822 specify date formats to be used by email. This module parses and emits such dates.
Despite the ease of generating and parsing perfectly valid
A strict parser that will only accept RFC2822dates, so you can see where you're right.
- A strict formatter, so you can generate the right stuff to begin with.
- A loose parser, so you can take the misbegotten output from other programs and turn it into something useful. This includes various minor errors as well as some somewhat more bizarre mistakes. The file t/sample_dates in this module's distribution should give you an idea of what's valid, while t/invalid.t should do the same for what's not. Those regarded as invalid are just a bit too strange to allow.
- Interoperation with the rest of the DateTime suite. These are a collection of modules to handle dates in a modern and accurate fashion. In particular, they make it trivial to parse, manipulate and then format dates. Shifting timezones is a doddle, and converting between formats is a cinch.
As a future direction, I'm contemplating an even stricter parser that will only accept dates with no obsolete elements.
newCreates a new "DateTime::Format::Mail" instance. This is generally not required for simple operations. If you wish to use a different parsing style from the default, strict, parser then you'll need to create an object.
my $parser = DateTime::Format::Mail->new() my $copy = $parser->new();
If called on an existing object then it clones the object.
It has two optional named parameters.
- "loose" should be a true value if you want a loose parser, else either don't specify it or give it a false value.
- "year_cutoff" should be an integer greater than or equal to zero specifying the cutoff year. See ``set_year_cutoff'' for details.
my $loose = DateTime::Format::Mail->new( loose => 1 ); my $post_2049 = DateTime::Format::Mail->new( year_cutoff => 60 );
cloneFor those who prefer to explicitly clone via a method called "clone()". If called as a class method it will die.
my $clone = $original->clone();
PARSING METHODSThese methods work on either our objects or as class methods.
loose, strictThese methods set the parsing strictness.
my $parser = DateTime::Format::Mail->new; $parser->loose; $parser->strict; # (the default) my $p = DateTime::Format::Mail->new->loose;
See the synopsis for examples.
set_year_cutoffTwo digit years are treated as valid in the loose translation and are translated up to a 19xx or 20xx figure. By default, following the specification of
"set_year_cutoff()" allows you to modify this behaviour by specifying a different cutoff.
The return value is the object itself.
$parser->set_year_cutoff( 60 );
year_cutoffReturns the current cutoff. Can be used as either a class or object method.
my $cutoff = $parser->set_year_cutoff;
default_cutoffReturns the default cutoff. A useful method to override for subclasses.
my $default = $parser->default_cutoff;
fix_yearTakes a year and returns it normalized.
my $fixed = $parser->fix_year( 3 );
format_datetimeGiven a "DateTime" object, return it as an
use DateTime; use DateTime::Format::Mail; my $dt = DateTime->new( year => 1979, month => 7, day => 16, time_zone => 'UTC' ); my $mail = DateTime::Format::Mail->format_datetime( $dt ); print $mail, "\n"; # or via an object my $formatter = DateTime::Format::Mail->new(); my $rfcdate = $formatter->format_datetime( $dt ); print $rfcdate, "\n";
THANKS FROM SPOONDave Rolsky (
Roderick A. Anderson for noting where the documentation was incomplete in places.
Joshua Hoblitt (
SUPPORTSupport for this module is provided via the firstname.lastname@example.org email list. See <datetime.perl.org/mailing_list.html> for more details.
Alternatively, log them via the
This makes it much easier for me to track things and thus means your problem is less likely to be neglected.
LICENCE AND COPYRIGHTCopyright © Iain Truskett, 2003. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the licences can be found in the
AUTHORSOriginally written by Iain Truskett <email@example.com>, who died on December 29, 2003.
Maintained by Dave Rolsky <firstname.lastname@example.org> from 2003 to 2013.
Maintained by Philippe Bruhat (BooK) <email@example.com> since 2014.
SEE ALSO"firstname.lastname@example.org" mailing list.
RFCs 2822 and 822.