man-pages/man3/HTTP::Date.3pm.html
2021-03-31 01:06:50 +01:00

242 lines
6.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of HTTP::Date</TITLE>
</HEAD><BODY>
<H1>HTTP::Date</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2019-11-23<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
HTTP::Date - HTTP::Date - date conversion routines
<A NAME="lbAC">&nbsp;</A>
<H2>VERSION</H2>
version 6.05
<A NAME="lbAD">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use HTTP::Date;
$string = time2str($time); # Format as GMT ASCII time
$time = str2time($string); # convert ASCII date to machine time
</PRE>
<A NAME="lbAE">&nbsp;</A>
<H2>DESCRIPTION</H2>
This module provides functions that deal the date formats used by the
<FONT SIZE="-1">HTTP</FONT> protocol (and then some more). Only the first two functions,
<B>time2str()</B> and <B>str2time()</B>, are exported by default.
<DL COMPACT>
<DT id="1">time2str( [$time] )<DD>
The <B>time2str()</B> function converts a machine time (seconds since epoch)
to a string. If the function is called without an argument or with an
undefined argument, it will use the current time.
<P>
The string returned is in the format preferred for the <FONT SIZE="-1">HTTP</FONT> protocol.
This is a fixed length subset of the format defined by <FONT SIZE="-1">RFC 1123,</FONT>
represented in Universal Time (<FONT SIZE="-1">GMT</FONT>). An example of a time stamp
in this format is:
<P>
<PRE>
Sun, 06 Nov 1994 08:49:37 GMT
</PRE>
<DT id="2">str2time( $str [, $zone] )<DD>
The <B>str2time()</B> function converts a string to machine time. It returns
<TT>&quot;undef&quot;</TT> if the format of <TT>$str</TT> is unrecognized, otherwise whatever the
<TT>&quot;Time::Local&quot;</TT> functions can make out of the parsed time. Dates
before the system's epoch may not work on all operating systems. The
time formats recognized are the same as for <B>parse_date()</B>.
<P>
The function also takes an optional second argument that specifies the
default time zone to use when converting the date. This parameter is
ignored if the zone is found in the date string itself. If this
parameter is missing, and the date string format does not contain any
zone specification, then the local time zone is assumed.
<P>
If the zone is not &quot;<TT>&quot;GMT&quot;</TT>`` or numerical (like ''<TT>&quot;-0800&quot;</TT>`` or
''<TT>+0100</TT>&quot;), then the <TT>&quot;Time::Zone&quot;</TT> module must be installed in order
to get the date recognized.
<DT id="3">parse_date( $str )<DD>
This function will try to parse a date string, and then return it as a
list of numerical values followed by a (possible undefined) time zone
specifier; ($year, <TT>$month</TT>, <TT>$day</TT>, <TT>$hour</TT>, <TT>$min</TT>, <TT>$sec</TT>, <TT>$tz</TT>). The <TT>$year</TT>
will be the full 4-digit year, and <TT>$month</TT> numbers start with 1 (for January).
<P>
In scalar context the numbers are interpolated in a string of the
``YYYY-MM-DD hh:mm:ss <FONT SIZE="-1">TZ</FONT>''-format and returned.
<P>
If the date is unrecognized, then the empty list is returned (<TT>&quot;undef&quot;</TT> in
scalar context).
<P>
The function is able to parse the following formats:
<P>
<PRE>
&quot;Wed, 09 Feb 1994 22:23:32 GMT&quot; -- HTTP format
&quot;Thu Feb 3 17:03:55 GMT 1994&quot; -- <A HREF="/cgi-bin/man/man2html?3+ctime">ctime</A>(3) format
&quot;Thu Feb 3 00:00:00 1994&quot;, -- ANSI C asctime() format
&quot;Tuesday, 08-Feb-94 14:15:29 GMT&quot; -- old rfc850 HTTP format
&quot;Tuesday, 08-Feb-1994 14:15:29 GMT&quot; -- broken rfc850 HTTP format
&quot;03/Feb/1994:17:03:55 -0700&quot; -- common logfile format
&quot;09 Feb 1994 22:23:32 GMT&quot; -- HTTP format (no weekday)
&quot;08-Feb-94 14:15:29 GMT&quot; -- rfc850 format (no weekday)
&quot;08-Feb-1994 14:15:29 GMT&quot; -- broken rfc850 format (no weekday)
&quot;1994-02-03 14:15:29 -0100&quot; -- ISO 8601 format
&quot;1994-02-03 14:15:29&quot; -- zone is optional
&quot;1994-02-03&quot; -- only date
&quot;1994-02-03T14:15:29&quot; -- Use T as separator
&quot;19940203T141529Z&quot; -- ISO 8601 compact format
&quot;19940203&quot; -- only date
&quot;08-Feb-94&quot; -- old rfc850 HTTP format (no weekday, no time)
&quot;08-Feb-1994&quot; -- broken rfc850 HTTP format (no weekday, no time)
&quot;09 Feb 1994&quot; -- proposed new HTTP format (no weekday, no time)
&quot;03/Feb/1994&quot; -- common logfile format (no time, no offset)
&quot;Feb 3 1994&quot; -- Unix 'ls -l' format
&quot;Feb 3 17:03&quot; -- Unix 'ls -l' format
&quot;11-15-96 03:52PM&quot; -- Windows 'dir' format
</PRE>
<P>
The parser ignores leading and trailing whitespace. It also allow the
seconds to be missing and the month to be numerical in most formats.
<P>
If the year is missing, then we assume that the date is the first
matching date <I>before</I> current month. If the year is given with only
2 digits, then <B>parse_date()</B> will select the century that makes the
year closest to the current date.
<DT id="4">time2iso( [$time] )<DD>
Same as <B>time2str()</B>, but returns a ``YYYY-MM-DD hh:mm:ss''-formatted
string representing time in the local time zone.
<DT id="5">time2isoz( [$time] )<DD>
Same as <B>time2str()</B>, but returns a ``YYYY-MM-DD hh:mm:ssZ''-formatted
string representing Universal Time.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>SEE ALSO</H2>
``time'' in perlfunc, Time::Zone
<A NAME="lbAG">&nbsp;</A>
<H2>AUTHOR</H2>
Gisle Aas &lt;<A HREF="mailto:gisle@activestate.com">gisle@activestate.com</A>&gt;
<A NAME="lbAH">&nbsp;</A>
<H2>COPYRIGHT AND LICENSE</H2>
This software is copyright (c) 1995-2019 by Gisle Aas.
<P>
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="6"><A HREF="#lbAB">NAME</A><DD>
<DT id="7"><A HREF="#lbAC">VERSION</A><DD>
<DT id="8"><A HREF="#lbAD">SYNOPSIS</A><DD>
<DT id="9"><A HREF="#lbAE">DESCRIPTION</A><DD>
<DT id="10"><A HREF="#lbAF">SEE ALSO</A><DD>
<DT id="11"><A HREF="#lbAG">AUTHOR</A><DD>
<DT id="12"><A HREF="#lbAH">COPYRIGHT AND LICENSE</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:45 GMT, March 31, 2021
</BODY>
</HTML>