DateTi...::HTTP(3pm)
β¨ DateTime::Format::HTTP β¨
hey bestie π welcome to the User Contributed Perl Documentation page for DateTime::Format::HTTP, section 3pm. it's giving "date conversion routines" and honestly? she eats. let's get into it π
πΈ NAME πΈ
DateTime::Format::HTTP β date conversion routines. that's the whole vibe. converting dates. iconic behaviour fr fr.
π¦ SYNOPSIS π¦
use DateTime::Format::HTTP;
my $class = 'DateTime::Format::HTTP';
$string = $class->format_datetime($dt); # Format as GMT ASCII time
$time = $class->parse_datetime($string); # convert ASCII date to machine time
look at her go π one direction formats, other direction parses. no cap.
π DESCRIPTION π
so basically this module hands you functions that deal with the date formats used by the HTTP protocol. and then some more. she's generous like that π«Ά
π METHODS π
π parse_datetime( $str [, $zone] )
okay so parse_datetime() takes a string and turns it into machine time. and if the format of $str is unrecognized? error. thrown. immediately. no warning arc, just π. same deal if the time is outside the representable range. the formats she recognizes are listed right down below, keep scrolling bestie.
she also takes an optional second argument that says which default time zone to use when converting the date. and here's the tea: this parameter gets ignored if the zone is already found in the date string itself. the date string is the main character, we don't override her. but if you skip this parameter and the date string format has no zone spec at all? then we use the floating time zone. floats away. bye π
the zone should be one that's recognized by DateTime::TimeZone. keep that in mind.
actual parsing is done with the HTTP::Date module. at the time of writing it supports the formats listed next. go consult that module's documentation in case the list has been changed. i'm just the messenger π
"Wed, 09 Feb 1994 22:23:32 GMT" -- HTTP format
"Thu Feb 3 17:03:55 GMT 1994" -- ctime(3) format
"Thu Feb 3 00:00:00 1994", -- ANSI C asctime() format
"Tuesday, 08-Feb-94 14:15:29 GMT" -- old rfc850 HTTP format
"Tuesday, 08-Feb-1994 14:15:29 GMT" -- broken rfc850 HTTP format
"03/Feb/1994:17:03:55 -0700" -- common logfile format
"09 Feb 1994 22:23:32 GMT" -- HTTP format (no weekday)
"08-Feb-94 14:15:29 GMT" -- rfc850 format (no weekday)
"08-Feb-1994 14:15:29 GMT" -- broken rfc850 format (no weekday)
"1994-02-03 14:15:29 -0100" -- ISO 8601 format
"1994-02-03 14:15:29" -- zone is optional
"1994-02-03" -- only date
"1994-02-03T14:15:29" -- Use T as separator
"19940203T141529Z" -- ISO 8601 compact format
"19940203" -- only date
"08-Feb-94" -- old rfc850 HTTP format (no weekday, no time)
"08-Feb-1994" -- broken rfc850 HTTP format (no weekday, no time)
"09 Feb 1994" -- proposed new HTTP format (no weekday, no time)
"03/Feb/1994" -- common logfile format (no time, no offset)
"Feb 3 1994" -- Unix 'ls -l' format
"Feb 3 17:03" -- Unix 'ls -l' format
"11-15-96 03:52PM" -- Windows 'dir' format
(and yes that stray comma after the asctime line is in the original, we don't touch, we don't fix, we respect the canon π«‘)
the parser ignores leading and trailing whitespace. she's chill. she also allows the seconds to be missing, and the month to be numerical in most formats. flexible queen π
now the rules for guessing:
- if the year is missing, then we assume that the date is the first matching date before current month.
- if the year is given with only 2 digits, then parse_date() will select the century that makes the year closest to the current date.
no cap. that's just how she rolls.
π§ format_datetime()
format_datetime() converts a DateTime to a string. if the function is called without an argument, it will use the current time. lowkey convenient.
the string returned is in the format preferred for the HTTP protocol. it's a fixed length subset of the format defined by RFC 1123, represented in Universal Time (GMT). an example of a time stamp in this format is:
Sun, 06 Nov 1994 08:49:37 GMT
that string right there? she's the blueprint. β¨
π format_iso( [$time] )
same as format_datetime(), but she returns a "YYYY-MM-DD hh:mm:ss"-formatted string representing time in the local time zone.
β οΈ bestie, listen: it is strongly recommended that you useformat_isozorformat_datetimeinstead (as these provide time zone indication). local time with no zone marker is giving chaos energy π
π format_isoz( [$dt] )
same as format_iso(), but she returns a "YYYY-MM-DD hh:mm:ssZ"-formatted string representing Universal Time. the Z is for "zone, we got you" π«Ά
π THANKS π
- Gisle Aas (GAAS) for writing HTTP::Date. king behaviour.
- Iain, for never quite finishing "HTTP::Date::XS". iconic honestly. unfinished masterpiece. we still love you.
π«Ά SUPPORT π«Ά
support for this module is provided via the datetime@perl.org email list. see http://lists.perl.org/ for more details.
alternatively, log them via the CPAN RT system via the web or email:
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DateTime%3A%3AFormat%3A%3AHTTP
bug-datetime-format-http@rt.cpan.org
this makes it much easier for me to track things and thus means your problem is less likely to be neglected. do it for yourself bestie, get your bug seen π
π LICENCE AND COPYRIGHT π
copyright Iain Truskett, 2003. all rights reserved. sections of the documentation Gisle Aas, 1995-1999. changes since version 0.35 copyright David Rolsky, 2004.
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.000 or, at your option, any later version of Perl 5 you may have available.
the full text of the licences can be found in the Artistic and COPYING files included with this module, or in perlartistic and perlgpl as supplied with Perl 5.8.1 and later.
π AUTHOR π
originally written by Iain Truskett <spoon@cpan.org>, who died on December 29, 2003. ποΈ rest in peace, legend.
maintained by Dave Rolsky <autarch@urth.org> and Christiaan Kras <ckras@cpan.org>
π SEE ALSO π
- "datetime@perl.org" mailing list.
- http://datetime.perl.org/
- perl, DateTime, HTTP::Date, DateTime::TimeZone.
and that's the whole page, bestie π¦ this was perl v5.40.0, dated 2024-11-16, out here living her best 3pm life. go convert some dates, you absolute icon ππβ¨
π¦ where this page comes from
- debian trixie: libdatetime-format-http-perl 0.43-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdatetime-format-http-perl 0.43-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdatetime-format-http-perl 0.43-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms