diff --git a/R/coercion.r b/R/coercion.r index 8f826e93..413a531b 100644 --- a/R/coercion.r +++ b/R/coercion.r @@ -441,8 +441,11 @@ setMethod("as.period", signature(x = "Interval"), function(x, unit = NULL, ...) to.per$month[nmons] <- 12 + to.per$month[nmons] to.per$year[nmons] <- to.per$year[nmons] - 1 - new("Period", to.per$second, year = to.per$year, month = to.per$month, - day = to.per$day, hour = to.per$hour, minute = to.per$minute) + np <- new("Period", to.per$second, year = to.per$year, month = to.per$month, + day = to.per$day, hour = to.per$hour, minute = to.per$minute) + if (is.na(np@month) | is.na(np@day)) return(np) + if (abs(sign(np@month) - sign(np@day)) == 2) np@day <- 0 + np } setMethod("as.period", signature(x = "Duration"), function(x, unit = NULL, ...) {