\HeaderA{DateTimeClasses}{Date-Time Classes}{DateTimeClasses}
\aliasA{+.POSIXt}{DateTimeClasses}{+.POSIXt}
\aliasA{-.POSIXt}{DateTimeClasses}{.Rdash..POSIXt}
\aliasA{.leap.seconds}{DateTimeClasses}{.leap.seconds}
\aliasA{all.equal.POSIXct}{DateTimeClasses}{all.equal.POSIXct}
\aliasA{as.data.frame.POSIXct}{DateTimeClasses}{as.data.frame.POSIXct}
\aliasA{as.data.frame.POSIXlt}{DateTimeClasses}{as.data.frame.POSIXlt}
\aliasA{as.matrix.POSIXlt}{DateTimeClasses}{as.matrix.POSIXlt}
\aliasA{c.POSIXct}{DateTimeClasses}{c.POSIXct}
\aliasA{c.POSIXlt}{DateTimeClasses}{c.POSIXlt}
\aliasA{check\_tzones}{DateTimeClasses}{check.Rul.tzones}
\aliasA{date-time}{DateTimeClasses}{date.Rdash.time}
\aliasA{duplicated.POSIXlt}{DateTimeClasses}{duplicated.POSIXlt}
\aliasA{is.na.POSIXlt}{DateTimeClasses}{is.na.POSIXlt}
\aliasA{Math.POSIXlt}{DateTimeClasses}{Math.POSIXlt}
\aliasA{Math.POSIXt}{DateTimeClasses}{Math.POSIXt}
\aliasA{mean.POSIXct}{DateTimeClasses}{mean.POSIXct}
\aliasA{mean.POSIXlt}{DateTimeClasses}{mean.POSIXlt}
\aliasA{Ops.POSIXt}{DateTimeClasses}{Ops.POSIXt}
\aliasA{POSIXct}{DateTimeClasses}{POSIXct}
\aliasA{POSIXlt}{DateTimeClasses}{POSIXlt}
\aliasA{POSIXt}{DateTimeClasses}{POSIXt}
\aliasA{print.POSIXct}{DateTimeClasses}{print.POSIXct}
\aliasA{print.POSIXlt}{DateTimeClasses}{print.POSIXlt}
\aliasA{str.POSIXt}{DateTimeClasses}{str.POSIXt}
\aliasA{Summary.POSIXct}{DateTimeClasses}{Summary.POSIXct}
\aliasA{summary.POSIXct}{DateTimeClasses}{summary.POSIXct}
\aliasA{Summary.POSIXlt}{DateTimeClasses}{Summary.POSIXlt}
\aliasA{summary.POSIXlt}{DateTimeClasses}{summary.POSIXlt}
\aliasA{unique.POSIXlt}{DateTimeClasses}{unique.POSIXlt}
\aliasA{[.POSIXct}{DateTimeClasses}{[.POSIXct}
\aliasA{[.POSIXlt}{DateTimeClasses}{[.POSIXlt}
\aliasA{[<\Rdash.POSIXct}{DateTimeClasses}{[<.Rdash..POSIXct}
\aliasA{[<\Rdash.POSIXlt}{DateTimeClasses}{[<.Rdash..POSIXlt}
\aliasA{[[.POSIXct}{DateTimeClasses}{[[.POSIXct}
\keyword{utilities}{DateTimeClasses}
\keyword{chron}{DateTimeClasses}
\begin{Description}\relax
Description of the classes \code{"POSIXlt"} and \code{"POSIXct"}
representing calendar dates and times (to the nearest second).
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'POSIXct':
print(x, ...)

## S3 method for class 'POSIXct':
summary(object, digits = 15, ...)

time + z
time - z
time1 lop time2
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, object}] An object to be printed or summarized from one of the
date-time classes.
\item[\code{digits}] Number of significant digits for the computations:
should be high enough to represent the least important time unit
exactly.
\item[\code{...}] Further arguments to be passed from or to other methods.
\item[\code{time}] date-time objects
\item[\code{time1, time2}] date-time objects or character vectors.  (Character
vectors are converted by \code{\LinkA{as.POSIXct}{as.POSIXct}}.)
\item[\code{z}] a numeric vector (in seconds)
\item[\code{lop}] One of \code{==}, \code{!=}, \code{<}, \code{<=}, \code{>}
or \code{>=}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
There are two basic classes of date/times.  Class \code{"POSIXct"}
represents the (signed) number of seconds since the beginning of 1970
as a numeric vector.  Class \code{"POSIXlt"} is a named list of
vectors representing
\describe{
\item[\code{sec}] 0--61: seconds
\item[\code{min}] 0--59: minutes
\item[\code{hour}] 0--23: hours
\item[\code{mday}] 1--31: day of the month
\item[\code{mon}] 0--11: months after the first of the year.
\item[\code{year}] Years since 1900.
\item[\code{wday}] 0--6 day of the week, starting on Sunday.
\item[\code{yday}] 0--365: day of the year.
\item[\code{isdst}] Daylight savings time flag.  Positive if in
force, zero if not, negative if unknown.
}
The classes correspond to the POSIX/C99 constructs of \sQuote{calendar
time} (the \code{time\_t} data type) and \sQuote{local time} (or
broken-down time, the \code{struct tm} data type), from which they
also inherit their names.

\code{"POSIXct"} is more convenient for including in data frames, and
\code{"POSIXlt"} is closer to human-readable forms.
A virtual class \code{"POSIXt"} inherits from both of the classes: it
is used to allow operations such as subtraction to mix the two classes.

Components \code{wday} and \code{yday} of \code{"POSIXlt"} are for
information, and are not used in the conversion to calendar time.
However, \code{isdst} is needed to distinguish times at the end of
DST: typically 1am to 2am occurs twice, first in DST and then in
standard time.  At all other times \code{isdst} can be deduced from
the first six values, but the behaviour if it is set incorrectly is
platform-dependent.

Logical comparisons and limited arithmetic are available for both
classes.  One can add or subtract a number of seconds
from a date-time object,
but not add two date-time objects.  Subtraction of two date-time objects
is equivalent to using \code{\LinkA{difftime}{difftime}}.  Be aware
that \code{"POSIXlt"} objects will be interpreted as being in the
current timezone for these operations, unless a timezone has been
specified.

\code{"POSIXlt"} objects will often have an attribute \code{"tzone"},
a character vector of length 3 giving the timezone name from the
\env{TZ} environment variable and the names of the base timezone
and the alternate (daylight-saving) timezone.  Sometimes this may
just be of length one, giving the timezone name.

\code{"POSIXct"} objects may also have an attribute \code{"tzone"}, a
character vector of length one.  If set, it will determine how the
object is converted to class \code{"POSIXlt"} and in particular how it
is printed.  This is usually desirable, but if you want to specify an
object in a particular timezone but to be printed in the current
timezone you may want to remove the \code{"tzone"} attribute (e.g. by
\code{c(x)}).

Unfortunately, the conversion is complicated by the operation of time
zones and leap seconds (23 days have been 86401 seconds long so far:
the times of the extra seconds are in the object \code{.leap.seconds}).
The details of this are entrusted to the OS services where possible.
This always covers the period 1970--2037, and on most machines
back to 1902 (when time zones were in their infancy).  Outside
the platform limits we use our own C code.  This uses the offset from
GMT in use either for 1902 (when there was no DST) or that predicted
for one of 2030 to 2037 (chosen so that the likely DST transition days
are Sundays), and uses the alternate (daylight-saving) timezone only
if \code{isdst} is positive or (if \code{-1}) if DST was predicted to
be in operation in the 2030s on that day.  (There is no reason to
suppose that the DST rules will remain the same in the future, and
indeed the US legislated in 2005 to change its rules as from 2007,
with a possible future reversion.)

It seems that some rare systems use leap seconds, but most ignore
them (as required by POSIX).  This is detected and corrected for at
build time, so all \code{"POSIXct"} times used by \R{} do not include
leap seconds. (Conceivably this could be wrong if the system has
changed since build time, just possibly by changing locales or the
\file{zoneinfo} database.)

Using \code{\LinkA{c}{c}} on \code{"POSIXlt"} objects converts them to the
current time zone.

A few times have specific issues.  First, the leapseconds are ignored,
and real times such as \code{"2005-12-31 23:59:60"} are (probably)
treated as the next second.  However, they will never be generated by
\R, and are unlikely to arise as input.  Second, on some OSes there is
a problem in the POSIX/C99 standard with \code{"1969-12-31 23:59:59"},
which is \code{-1} in calendar time and is used as an error code.
Thus \code{as.POSIXct("1969-12-31 23:59:59",
    format="\%Y-\%m-\%d \%H:\%M:\%S", tz="UTC")} may give \code{NA}, and
hence \code{as.POSIXct("1969-12-31 23:59:59", tz="UTC")} will give
\code{"1969-12-31 23:59:50"}.
Other OSes
report errors separately and so are able to handle that time as
valid.
\end{Details}
\begin{Section}{Sub-second Accuracy}
Classes \code{"POSIXct"} and  \code{"POSIXlt"} are able to express
fractions of a second.  (Conversion of fractions between the two forms
may not be exact, but will have better than microsecond accuracy.)

Fractional seconds are printed only if
\code{\LinkA{options}{options}("digits.secs")} is set: see \code{\LinkA{strftime}{strftime}}.
\end{Section}
\begin{Section}{Warning}
Some Unix-like systems (especially Linux ones) do not have \code{"TZ"}
set, yet have internal code that expects it (as does POSIX).  We have
tried to work around this, but if you get unexpected results try
setting \code{"TZ"}.  See \code{\LinkA{as.POSIXlt}{as.POSIXlt}} for valid settings.
\end{Section}
\begin{SeeAlso}\relax
\LinkA{Dates}{Dates} for dates without times.

\code{\LinkA{as.POSIXct}{as.POSIXct}} and \code{\LinkA{as.POSIXlt}{as.POSIXlt}} for conversion
between the classes.

\code{\LinkA{strptime}{strptime}} for conversion to and from character
representations.

\code{\LinkA{Sys.time}{Sys.time}} for clock time as a \code{"POSIXct"} object.

\code{\LinkA{difftime}{difftime}} for time intervals.

\code{\LinkA{cut.POSIXt}{cut.POSIXt}}, \code{\LinkA{seq.POSIXt}{seq.POSIXt}},
\code{\LinkA{round.POSIXt}{round.POSIXt}} and \code{\LinkA{trunc.POSIXt}{trunc.POSIXt}} for methods
for these classes.

\code{\LinkA{weekdays.POSIXt}{weekdays.POSIXt}} for convenience extraction functions.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
(z <- Sys.time())             # the current date, as class "POSIXct"

Sys.time() - 3600             # an hour ago

as.POSIXlt(Sys.time(), "GMT") # the current time in GMT
format(.leap.seconds)         # all 23 leapseconds in your timezone
print(.leap.seconds, tz="PST8PDT")  # and in Seattle's
\end{ExampleCode}
\end{Examples}

