interval {lubridate}R Documentation

Create an interval object.

Description

interval creates an Interval-class object with the specified start and end dates. If the start date occurs before the end date, the interval will be positive. Otherwise, it will be negative.

Usage

interval(start, end, tzone = attr(start, "tzone"))

is.interval(x)

Arguments

start

a POSIXt or Date date-time object

end

a POSIXt or Date date-time object

tzone

a recognized timezone to display the interval in

x

an R object

Details

Intervals are time spans bound by two real date-times. Intervals can be accurately converted to either period or duration objects using as.period, as.duration. Since an interval is anchored to a fixed history of time, both the exact number of seconds that passed and the number of variable length time units that occurred during the interval can be calculated.

%--% Creates an interval that covers the range spanned by two dates. It replaces the original behavior of lubridate, which created an interval by default whenever two date-times were subtracted.

Value

an Interval object

See Also

Interval-class, as.interval

Examples

interval(ymd(20090201), ymd(20090101))
# 2009-02-01 UTC--2009-01-01 UTC

date1 <- as.POSIXct("2009-03-08 01:59:59")
date2 <- as.POSIXct("2000-02-29 12:00:00")
interval(date2, date1)
# 2000-02-29 12:00:00 CST--2009-03-08 01:59:59 CST
interval(date1, date2)
# 2009-03-08 01:59:59 CST--2000-02-29 12:00:00 CST
span <- interval(ymd(20090101), ymd(20090201))
# 2009-01-01 UTC--2009-02-01 UTC

is.interval(period(months= 1, days = 15)) # FALSE
is.interval(interval(ymd(20090801), ymd(20090809))) # TRUE

[Package lubridate version 1.5.6 Index]