Learn R Programming

splusTimeDate (version 1.5.0-72)

timeSpan-class: Time Span Class

Description

The timeSpan class represents time spans.

Arguments

Time span functions

You can create objects of class timeSpan by using either the new function (in which case they are set up to have length 0 and the default format from timeDateOptions("tspan.out.format")), or by using the timeSpan function.

as relationships are established for timeSpan objects to coerce them to and from character, numeric, and integer.

For numbers, the integer part is the number of days, 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. Adding or subtracting numbers to or from timeSpan objects works as though the timeSpan is converted to a number, the operation is performed, and the number is converted back to a timeSpan.

Multiplication and division by numbers are also defined. You can add, subtract, and divide two timeSpan objects. (For division, the result is a number.) You can add or subtract a timeSpan object to or from a timeDate object.

Only a few other mathematical functions make sense for timeSpan objects. These are floor, ceiling, min, max, sum, mean, and range. Multiplication, division, and operations that do not make sense directly for timeSpan objects result in numbers, via automatic coercion to class numeric. In addition to these mathematical operations, all of the standard comparison operators have methods for comparing two timeSpan objects.

Details

The timeSpan class is constructed to hold a vector of time spans. It extends the groupVec and groupVecVirtual classes, as well as timeInterval.

The groupVec portion of the time class object holds a day portion, stored as an integer vector of the number of full days in each time span, and a time portion, stored as a vector of the number of milliseconds in each time span. The groupVec column names are "julian.day" and "milliseconds", and the column classes are integer. The user can directly change the format specified by the format slot (see below), but it is not recommended to change the groupVec slots directly.

See Also

groupVec class, timeDate class, timeDateOptions, timeSpan function, format.timeSpan.

Examples

Run this code
## The default format for input is initially:
##   "[\%yy[ear[s]][,]] [\%dd[ay[s]][,]] [\%Hh[our[s]][,]]
##      [\%Mm[in[ute][s]][,]] [\%Ss[ec[ond][s]][,]] [\%NM[s][S]]"
##This allows reading strings such as
##   "378d 21h 04min 36s 365MS", "378 d", "-1y, -13d, -21h -4m"
##The default format for output is initially:
##   "\%dd \%Hh \%Mm \%Ss \%NMS"
##This results in output such as:
##   "378d 21h 4m 36s 365MS"   "-378d -21h -4m -36s -365MS"

Run the code above in your browser using DataLab