hadley/lubridate — Issue #109: add_period_to_interval gives unintuitive result
Author: cornelius1729
Created: 2012-01-26 14:53:08+00:00
State: open

Currently adding a period to an interval extends the length of the interval, whereas it seems more intuitive to shift the whole interval.

For example,

new_interval(ymd("2012-01-02"), ymd("2012-01-06")) + weeks(1:4)

currently returns

[1] 2012-01-02 -- 2012-01-13 2012-01-02 -- 2012-01-20
[3] 2012-01-02 -- 2012-01-27 2012-01-02 -- 2012-02-03

and not the weekdays in January this year as expected.

Suggested new implementation.

add_period_to_interval <- function (per, int)
{
start <- int_start(int)
end <- int_end(int)
new_interval(end + per, start + per)
}