as.second {datetime}R Documentation

Interconvert Nominal Time Units

Description

Perform standard conversions among various common time units.

Usage

as.second(x, ...)
as.minute(x, ...)
as.hour(x, ...)
as.day(x, ...)
as.week(x, ...)
as.month(x, ...)
as.year(x, ...)

Arguments

x

numeric

...

ignored

Details

The functions listed above are generic. Methods exist, either explictly or implicitly, for objects classified to represent second, minute, hour, day, week, month, and year. All these objects are subclasses of "duration"; as.<n>.duration serves wherever explicit methods are omitted. For each generic, methods exist for class "numeric". For each class, methods exist for the generics "format" and "print".

The strategy for time unit conversion is to classify a numeric vector according to some unit, and then coerce that object to some other class. Thus, as.day(7) is not particularly interesting, but as.week(as.day(7)) yields 1.

Conversions use 60 seconds per minute, 60 minutes per hour, 24 hours per day, 7 days per week, 28 days per month, and 365.25 days per year. Currently, no other relationships are specified. Note that 12 nominal months does not make a full year. This is experimental, and may change in future versions.

The duration classes are also subclasses of timeline, which exists to support addition and subtraction of durations and timepoints. See examples here, and at timeline. You cannot add two timepoints, nor can you subtract a timepoint from a non-timepoint. When one argument is a timepoint, the other is coerced using as.second, and the result is the timepoint class. For two durations, the second value is coerced to the class of the first, with a message, if necessary. Otherwise, if only one argument is a duration, the other is coerced to that class. Negative durations are allowed.

Value

an S3 "num" object with class c(n, 'duration','timeline','numeric'), where ‘n’ is "second", "minute", "hour", "day", "week", "month", or "year", as implied.

Author(s)

Tim Bergsma

See Also

Examples

as.year(as.month(12))
as.year(as.day(365.25))
as.second(as.year(1))
as.month(2) + as.week(2)
as.week(2) + as.month(1)
as.month(2) - as.week(2)
as.week(2) - as.month(1)
as.week(2) + 1
as.week(2) - 1
2 + as.week(1)
2 - as.week(1)
class(c(as.day(1),as.day(2)))
class(as.day(1:5)[3])
class(as.day(1:5)[[3]])
class(seq(from=as.day(2),to=as.day(6)))
class(rep(as.day(1),5))

[Package datetime version 0.1.4 Index]