Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Version 1.9.5.9999 (dev)
* Fix `month<-` assignment by month name. "April" and "May" were missing from
the lookup table, which produced `NA` for those names and incorrect month
numbers for June through December.
* `%/%` and `%%` between a Period/Duration and an Interval now report the
correct operator in the "Incompatible classes" error instead of `/`.
* `setdiff()` on intervals no longer errors when the inputs contain `NA`.
* `.int_to_period()` now uses the correct calendar year when computing month
lengths, fixing off-by-one-day results for periods crossing a February in
century years such as 1900 and 2000.


Version 1.9.5
Expand Down
4 changes: 2 additions & 2 deletions R/coercion.r
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ setMethod("as.period", signature(x = "Interval"), function(x, unit = NULL, ...)

pmonth <- end$mon[ndays]
pmonth[pmonth == 0] <- 1 # dec == jan == 31 days
prev_month_days <- .days_in_month(pmonth, end$year[ndays])
prev_month_days <- .days_in_month(pmonth, end$year[ndays] + 1900)

## difference in days:
## /need pmax to capture as.period(interval(ymd("1985-01-31"), ymd("1986-03-28")))/
Expand All @@ -485,7 +485,7 @@ setMethod("as.period", signature(x = "Interval"), function(x, unit = NULL, ...)
ndays <- negs & per$day < 0 & !is.na(per$day)
if (any(ndays)) {
add_months <- rep.int(1, sum(ndays))
this_month_days <- .days_in_month(end$mon[ndays] + 1, end$year[ndays])
this_month_days <- .days_in_month(end$mon[ndays] + 1, end$year[ndays] + 1900)

## Compute nr of days:
## /need pmax to capture as.period(interval(ymd("1985-01-31"), ymd("1986-03-28")))/
Expand Down
1 change: 1 addition & 0 deletions R/intervals.r
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ setdiff.Interval <- function(x, y, ...) {
aligned <- int_aligns(x, y)
inside <- y %within% x
makes2 <- !aligned & inside
makes2[is.na(makes2)] <- FALSE

if (sum(makes2)) {
stop(paste(
Expand Down
8 changes: 6 additions & 2 deletions R/ops-integer-division.r
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ setMethod("%/%", signature("Period", "Period"), trunc_divide)
#' @export
setMethod("%/%", signature("Interval", "Duration"), trunc_divide)
#' @export
setMethod("%/%", signature("Duration", "Interval"), trunc_divide)
setMethod("%/%", signature(e1 = "Duration", e2 = "Interval"), function(e1, e2) {
stop_incompatible_classes(e1, e2, "%/%")
})

#' @export
setMethod("%/%", signature("Interval", "Period"), trunc_divide)
#' @export
setMethod("%/%", signature("Period", "Interval"), trunc_divide)
setMethod("%/%", signature(e1 = "Period", e2 = "Interval"), function(e1, e2) {
stop_incompatible_classes(e1, e2, "%/%")
})
2 changes: 1 addition & 1 deletion R/ops-modulo.r
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ setMethod(
#' @export
setMethod(
"%%", signature(e1 = "Period", e2 = "Interval"),
function(e1, e2) modulo_period_by_period(e1, e2)
function(e1, e2) stop_incompatible_classes(e1, e2, "%%")
)
4 changes: 2 additions & 2 deletions tests/testthat/test-ops-integer-division.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Duration numerator
==================

> dur %/% int
Error: Incompatible classes: <Duration> / <Interval>
Error: Incompatible classes: <Duration> %/% <Interval>

> dur %/% dur
[1] 1
Expand All @@ -32,7 +32,7 @@ Period numeric
==============

> per %/% int
Error: Incompatible classes: <Period> / <Interval>
Error: Incompatible classes: <Period> %/% <Interval>

> per %/% dur
Error: Incompatible classes: <Period> %/% <Duration>
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ops-modulo.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("modulo operations return correct class", {
expect_s4_class(int %% months(1), "Interval")
expect_s4_class(int %% ddays(10), "Interval")

expect_error(months(3) %% int)
expect_error(months(3) %% int, "%%")
expect_s4_class(days(3) %% hours(2), "Period")
expect_error(days(5) %% dminutes(300))

Expand Down
Loading