Commit 0ad55fb2 authored by Fred Drake's avatar Fred Drake

Update the descriptions of strftime() and strptime() to avoid

confusion, and describe what the "directives" are about.
parent e94e3fbb
...@@ -20,35 +20,35 @@ look at \code{gmtime(0)}.% ...@@ -20,35 +20,35 @@ look at \code{gmtime(0)}.%
\index{epoch} \index{epoch}
\item \item
The functions in this module don't handle dates and times before the The functions in this module do not handle dates and times before the
epoch or far in the future. The cut-off point in the future is epoch or far in the future. The cut-off point in the future is
determined by the C library; for \UNIX{}, it is typically in 2038.% determined by the \C{} library; for \UNIX{}, it is typically in 2038.%
\index{Year 2038} \index{Year 2038}
\item \item
\strong{Year 2000 (Y2K) issues}: Python depends on the platform's C library, \strong{Year 2000 (Y2K) issues}: Python depends on the platform's \C{}
which generally doesn't have year 2000 issues, since all dates and library, which generally doesn't have year 2000 issues, since all
times are represented internally as seconds since the epoch. dates and times are represented internally as seconds since the
Functions accepting a time tuple (see below) generally require a epoch. Functions accepting a time tuple (see below) generally require
4-digit year. For backward compatibility, 2-digit years are supported a 4-digit year. For backward compatibility, 2-digit years are
if the module variable \code{accept2dyear} is a non-zero integer; this supported if the module variable \code{accept2dyear} is a non-zero
variable is initialized to \code{1} unless the environment variable integer; this variable is initialized to \code{1} unless the
\code{PYTHONY2K} is set to a non-empty string, in which case it is environment variable \envvar{PYTHONY2K} is set to a non-empty string,
initialized to \code{0}. Thus, you can set \code{PYTHONY2K} in the in which case it is initialized to \code{0}. Thus, you can set
environment to \code{x} to require 4-digit years for all year input. \envvar{PYTHONY2K} in the environment to \code{x} to require 4-digit
When 2-digit years are accepted, they are converted according to the years for all year input. When 2-digit years are accepted, they are
POSIX or X/Open standard: values 69-99 are mapped to 1969-1999, and converted according to the \POSIX{} or X/Open standard: values 69-99
values 0--68 are mapped to 2000--2068. Values 100--1899 are always are mapped to 1969-1999, and values 0--68 are mapped to 2000--2068.
illegal. Note that this is new as of Python 1.5.2(a2); earlier Values 100--1899 are always illegal. Note that this is new as of
versions, up to Python 1.5.1 and 1.5.2a1, would add 1900 to year Python 1.5.2(a2); earlier versions, up to Python 1.5.1 and 1.5.2a1,
values below 1900.% would add 1900 to year values below 1900.%
\index{Year 2000}% \index{Year 2000}%
\index{Y2K} \index{Y2K}
\item \item
UTC is Coordinated Universal Time (formerly known as Greenwich Mean UTC is Coordinated Universal Time (formerly known as Greenwich Mean
Time). The acronym UTC is not a mistake but a compromise between Time, or GMT). The acronym UTC is not a mistake but a compromise
English and French.% between English and French.%
\index{UTC}% \index{UTC}%
\index{Coordinated Universal Time}% \index{Coordinated Universal Time}%
\index{Greenwich Mean Time} \index{Greenwich Mean Time}
...@@ -103,9 +103,9 @@ Only use this if \code{daylight} is nonzero. ...@@ -103,9 +103,9 @@ Only use this if \code{daylight} is nonzero.
\end{datadesc} \end{datadesc}
\begin{funcdesc}{asctime}{tuple} \begin{funcdesc}{asctime}{tuple}
Convert a tuple representing a time as returned by \code{gmtime()} or Convert a tuple representing a time as returned by \function{gmtime()}
\code{localtime()} to a 24-character string of the following form: or \function{localtime()} to a 24-character string of the following form:
\code{'Sun Jun 20 23:21:05 1993'}. Note: unlike the C function of \code{'Sun Jun 20 23:21:05 1993'}. Note: unlike the \C{} function of
the same name, there is no trailing newline. the same name, there is no trailing newline.
\end{funcdesc} \end{funcdesc}
...@@ -139,13 +139,12 @@ set to \code{1} when DST applies to the given time. ...@@ -139,13 +139,12 @@ set to \code{1} when DST applies to the given time.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{mktime}{tuple} \begin{funcdesc}{mktime}{tuple}
This is the inverse function of \code{localtime}. Its argument is the This is the inverse function of \function{localtime()}. Its argument
full 9-tuple (since the dst flag is needed --- pass \code{-1} as the is the full 9-tuple (since the dst flag is needed --- pass \code{-1}
dst flag if it is unknown) which expresses the time as the dst flag if it is unknown) which expresses the time in
in \emph{local} time, not UTC. It returns a floating \emph{local} time, not UTC. It returns a floating point number, for
point number, for compatibility with \function{time()}. If the input compatibility with \function{time()}. If the input value cannot be
value cannot be represented as a valid time, \exception{OverflowError} represented as a valid time, \exception{OverflowError} is raised.
is raised.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{sleep}{secs} \begin{funcdesc}{sleep}{secs}
...@@ -154,11 +153,14 @@ be a floating point number to indicate a more precise sleep time. ...@@ -154,11 +153,14 @@ be a floating point number to indicate a more precise sleep time.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{strftime}{format, tuple} \begin{funcdesc}{strftime}{format, tuple}
Convert a tuple representing a time as returned by \code{gmtime()} or Convert a tuple representing a time as returned by \function{gmtime()}
\code{localtime()} to a string as specified by the format argument. or \function{localtime()} to a string as specified by the \var{format}
argument. \var{format} must be a string.
The following directives, shown without the optional field width and The following directives can be embedded in the \var{format} string.
precision specification, are replaced by the indicated characters: They are shown without the optional field width and precision
specification, and are replaced by the indicated characters in the
\function{strftime()} result:
\begin{tableii}{c|p{24em}}{code}{Directive}{Meaning} \begin{tableii}{c|p{24em}}{code}{Directive}{Meaning}
\lineii{\%a}{Locale's abbreviated weekday name.} \lineii{\%a}{Locale's abbreviated weekday name.}
...@@ -190,25 +192,25 @@ precision specification, are replaced by the indicated characters: ...@@ -190,25 +192,25 @@ precision specification, are replaced by the indicated characters:
\end{tableii} \end{tableii}
Additional directives may be supported on certain platforms, but Additional directives may be supported on certain platforms, but
only the ones listed here have a meaning standardized by ANSI C. only the ones listed here have a meaning standardized by ANSI \C{}.
On some platforms, an optional field width and precision On some platforms, an optional field width and precision
specification can immediately follow the initial \code{\%} of a specification can immediately follow the initial \character{\%} of a
directive in the following order; this is also not portable. directive in the following order; this is also not portable.
The field width is normally 2 except for \code{\%j} where it is 3. The field width is normally 2 except for \code{\%j} where it is 3.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{strptime}{string\optional{, format}} \begin{funcdesc}{strptime}{string\optional{, format}}
Parse a string representing a time according to a format. The return Parse a string representing a time according to a format. The return
value is a tuple as returned by \code{gmtime()} or \code{localtime()}. value is a tuple as returned by \function{gmtime()} or
The format uses the same directives as those used by \function{localtime()}. The \var{format} parameter uses the same
\code{strftime()}; it defaults to \code{"\%a \%b \%d \%H:\%M:\%S \%Y"} directives as those used by \function{strftime()}; it defaults to
which matches the formatting returned by \code{ctime()}. The same \code{"\%a \%b \%d \%H:\%M:\%S \%Y"} which matches the formatting
platform caveats apply; see the local Unix documentation for returned by \function{ctime()}. The same platform caveats apply; see
restrictions or additional supported directives. This function may the local \UNIX{} documentation for restrictions or additional
not be defined on all platforms. supported directives. If \var{string} cannot be parsed according to
\var{format}, \exception{ValueError} is raised. This function may not
be defined on all platforms.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{time}{} \begin{funcdesc}{time}{}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment