Objects of class.time
can be created using the new
function, in
which case they are constructed to have length 0 and the default format and
zone from timeDateOptions("time.out.format")
and timeDateOptions("time.zone")
respectively. Alternatively, they can be created using the timeDate
and
timeCalendar
functions.There are as
relationships set up for timeDate
objects to coerce them to
and from character
, numeric
, and integer
.
For numbers, the integer part is the julian day, and the fractional part is the
fraction of the day given by the number of milliseconds divided by the
number of milliseconds in a day, in GMT.
Addition of numbers to time objects and subtraction of numerics from time objects works as
though the time were converted to a number, the operation were
performed, and the number was converted back to a
time. Their subtraction results in a timeSpan
object, and a
timeSpan
object can be added to or subtracted from a time.
Only a few other mathematical functions make sense for time objects:
floor
, ceiling
, min
, max
, mean
, and range
.
Multiplication, division, and other operations that do not
make sense for times and dates (in the absence of an origin) result in
numbers, via automatic coercion to class numeric
.
Note that while conversion to/from numerics is always in GMT, floor
and ceiling
take account of
the time zone to ouput time objects whose time is midnight in their
time zone, and whose date is no later than the input time's date for
floor
, and no earlier for ceiling
. In addition to these mathematical
operations, all of the standard comparison operators have methods for
comparing two time objects.
There are also functions for time objects that pick out particular
parts. See days
, hours
, and mdy
for more information.
Various options are used by the time class, primarily for printing to and
reading from character strings. See timeDateOptions
for documentation.