Skip to content

Commit 0ad55fb

Browse files
committed
Update the descriptions of strftime() and strptime() to avoid
confusion, and describe what the "directives" are about.
1 parent e94e3fb commit 0ad55fb

1 file changed

Lines changed: 47 additions & 45 deletions

File tree

Doc/lib/libtime.tex

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,35 @@ \section{\module{time} ---
2020
\index{epoch}
2121

2222
\item
23-
The functions in this module don't handle dates and times before the
23+
The functions in this module do not handle dates and times before the
2424
epoch or far in the future. The cut-off point in the future is
25-
determined by the C library; for \UNIX{}, it is typically in 2038.%
25+
determined by the \C{} library; for \UNIX{}, it is typically in 2038.%
2626
\index{Year 2038}
2727

2828
\item
29-
\strong{Year 2000 (Y2K) issues}: Python depends on the platform's C library,
30-
which generally doesn't have year 2000 issues, since all dates and
31-
times are represented internally as seconds since the epoch.
32-
Functions accepting a time tuple (see below) generally require a
33-
4-digit year. For backward compatibility, 2-digit years are supported
34-
if the module variable \code{accept2dyear} is a non-zero integer; this
35-
variable is initialized to \code{1} unless the environment variable
36-
\code{PYTHONY2K} is set to a non-empty string, in which case it is
37-
initialized to \code{0}. Thus, you can set \code{PYTHONY2K} in the
38-
environment to \code{x} to require 4-digit years for all year input.
39-
When 2-digit years are accepted, they are converted according to the
40-
POSIX or X/Open standard: values 69-99 are mapped to 1969-1999, and
41-
values 0--68 are mapped to 2000--2068. Values 100--1899 are always
42-
illegal. Note that this is new as of Python 1.5.2(a2); earlier
43-
versions, up to Python 1.5.1 and 1.5.2a1, would add 1900 to year
44-
values below 1900.%
29+
\strong{Year 2000 (Y2K) issues}: Python depends on the platform's \C{}
30+
library, which generally doesn't have year 2000 issues, since all
31+
dates and times are represented internally as seconds since the
32+
epoch. Functions accepting a time tuple (see below) generally require
33+
a 4-digit year. For backward compatibility, 2-digit years are
34+
supported if the module variable \code{accept2dyear} is a non-zero
35+
integer; this variable is initialized to \code{1} unless the
36+
environment variable \envvar{PYTHONY2K} is set to a non-empty string,
37+
in which case it is initialized to \code{0}. Thus, you can set
38+
\envvar{PYTHONY2K} in the environment to \code{x} to require 4-digit
39+
years for all year input. When 2-digit years are accepted, they are
40+
converted according to the \POSIX{} or X/Open standard: values 69-99
41+
are mapped to 1969-1999, and values 0--68 are mapped to 2000--2068.
42+
Values 100--1899 are always illegal. Note that this is new as of
43+
Python 1.5.2(a2); earlier versions, up to Python 1.5.1 and 1.5.2a1,
44+
would add 1900 to year values below 1900.%
4545
\index{Year 2000}%
4646
\index{Y2K}
4747

4848
\item
4949
UTC is Coordinated Universal Time (formerly known as Greenwich Mean
50-
Time). The acronym UTC is not a mistake but a compromise between
51-
English and French.%
50+
Time, or GMT). The acronym UTC is not a mistake but a compromise
51+
between English and French.%
5252
\index{UTC}%
5353
\index{Coordinated Universal Time}%
5454
\index{Greenwich Mean Time}
@@ -103,9 +103,9 @@ \section{\module{time} ---
103103
\end{datadesc}
104104

105105
\begin{funcdesc}{asctime}{tuple}
106-
Convert a tuple representing a time as returned by \code{gmtime()} or
107-
\code{localtime()} to a 24-character string of the following form:
108-
\code{'Sun Jun 20 23:21:05 1993'}. Note: unlike the C function of
106+
Convert a tuple representing a time as returned by \function{gmtime()}
107+
or \function{localtime()} to a 24-character string of the following form:
108+
\code{'Sun Jun 20 23:21:05 1993'}. Note: unlike the \C{} function of
109109
the same name, there is no trailing newline.
110110
\end{funcdesc}
111111

@@ -139,13 +139,12 @@ \section{\module{time} ---
139139
\end{funcdesc}
140140

141141
\begin{funcdesc}{mktime}{tuple}
142-
This is the inverse function of \code{localtime}. Its argument is the
143-
full 9-tuple (since the dst flag is needed --- pass \code{-1} as the
144-
dst flag if it is unknown) which expresses the time
145-
in \emph{local} time, not UTC. It returns a floating
146-
point number, for compatibility with \function{time()}. If the input
147-
value cannot be represented as a valid time, \exception{OverflowError}
148-
is raised.
142+
This is the inverse function of \function{localtime()}. Its argument
143+
is the full 9-tuple (since the dst flag is needed --- pass \code{-1}
144+
as the dst flag if it is unknown) which expresses the time in
145+
\emph{local} time, not UTC. It returns a floating point number, for
146+
compatibility with \function{time()}. If the input value cannot be
147+
represented as a valid time, \exception{OverflowError} is raised.
149148
\end{funcdesc}
150149

151150
\begin{funcdesc}{sleep}{secs}
@@ -154,11 +153,14 @@ \section{\module{time} ---
154153
\end{funcdesc}
155154

156155
\begin{funcdesc}{strftime}{format, tuple}
157-
Convert a tuple representing a time as returned by \code{gmtime()} or
158-
\code{localtime()} to a string as specified by the format argument.
156+
Convert a tuple representing a time as returned by \function{gmtime()}
157+
or \function{localtime()} to a string as specified by the \var{format}
158+
argument. \var{format} must be a string.
159159

160-
The following directives, shown without the optional field width and
161-
precision specification, are replaced by the indicated characters:
160+
The following directives can be embedded in the \var{format} string.
161+
They are shown without the optional field width and precision
162+
specification, and are replaced by the indicated characters in the
163+
\function{strftime()} result:
162164

163165
\begin{tableii}{c|p{24em}}{code}{Directive}{Meaning}
164166
\lineii{\%a}{Locale's abbreviated weekday name.}
@@ -190,25 +192,25 @@ \section{\module{time} ---
190192
\end{tableii}
191193

192194
Additional directives may be supported on certain platforms, but
193-
only the ones listed here have a meaning standardized by ANSI C.
195+
only the ones listed here have a meaning standardized by ANSI \C{}.
194196

195197
On some platforms, an optional field width and precision
196-
specification can immediately follow the initial \code{\%} of a
198+
specification can immediately follow the initial \character{\%} of a
197199
directive in the following order; this is also not portable.
198200
The field width is normally 2 except for \code{\%j} where it is 3.
199-
200201
\end{funcdesc}
201202

202203
\begin{funcdesc}{strptime}{string\optional{, format}}
203204
Parse a string representing a time according to a format. The return
204-
value is a tuple as returned by \code{gmtime()} or \code{localtime()}.
205-
The format uses the same directives as those used by
206-
\code{strftime()}; it defaults to \code{"\%a \%b \%d \%H:\%M:\%S \%Y"}
207-
which matches the formatting returned by \code{ctime()}. The same
208-
platform caveats apply; see the local Unix documentation for
209-
restrictions or additional supported directives. This function may
210-
not be defined on all platforms.
211-
205+
value is a tuple as returned by \function{gmtime()} or
206+
\function{localtime()}. The \var{format} parameter uses the same
207+
directives as those used by \function{strftime()}; it defaults to
208+
\code{"\%a \%b \%d \%H:\%M:\%S \%Y"} which matches the formatting
209+
returned by \function{ctime()}. The same platform caveats apply; see
210+
the local \UNIX{} documentation for restrictions or additional
211+
supported directives. If \var{string} cannot be parsed according to
212+
\var{format}, \exception{ValueError} is raised. This function may not
213+
be defined on all platforms.
212214
\end{funcdesc}
213215

214216
\begin{funcdesc}{time}{}

0 commit comments

Comments
 (0)