Skip to content

Commit

Permalink
Changed add to add.bizdays
Browse files Browse the repository at this point in the history
The function `add` has been renamed to `add.bizdays`.
  • Loading branch information
wilsonfreitas committed Jun 16, 2014
1 parent 21d05e7 commit 97dabd6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 72 deletions.
10 changes: 5 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
S3method(add,Date)
S3method(add,POSIXct)
S3method(add,POSIXlt)
S3method(add,character)
S3method(add.bizdays,Date)
S3method(add.bizdays,POSIXct)
S3method(add.bizdays,POSIXlt)
S3method(add.bizdays,character)
S3method(adjust.next,Date)
S3method(adjust.next,POSIXct)
S3method(adjust.next,POSIXlt)
Expand Down Expand Up @@ -36,7 +36,7 @@ S3method(is.bizday,POSIXlt)
S3method(is.bizday,character)
S3method(print,Calendar)
export(Calendar)
export(add)
export(add.bizdays)
export(adjust.next)
export(adjust.previous)
export(bizdays)
Expand Down
44 changes: 22 additions & 22 deletions R/calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,39 +382,39 @@ bizseq.Date <- function(from, to, cal=bizdays.options$get('default.calendar')) {
#' @examples
#' data(holidaysANBIMA)
#' cal <- Calendar(holidaysANBIMA)
#' add("2013-01-02", 5, cal)
#' add.bizdays("2013-01-02", 5, cal)
#' dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day")
#' add(dates, 1, cal)
add <- function(dates, n, cal) UseMethod('add')
#' add.bizdays(dates, 1, cal)
add.bizdays <- function(dates, n, cal) UseMethod('add.bizdays')

#' @rdname add
#' @method add character
#' @S3method add character
add.character <- function(dates, n, cal=bizdays.options$get('default.calendar')) {
#' @rdname add.bizdays
#' @method add.bizdays character
#' @S3method add.bizdays character
add.bizdays.character <- function(dates, n, cal=bizdays.options$get('default.calendar')) {
dates <- as.Date(dates)
add(dates, n, cal)
add.bizdays(dates, n, cal)
}

#' @rdname add
#' @method add POSIXct
#' @S3method add POSIXct
add.POSIXct <- function(dates, n, cal=bizdays.options$get('default.calendar')) {
#' @rdname add.bizdays
#' @method add.bizdays POSIXct
#' @S3method add.bizdays POSIXct
add.bizdays.POSIXct <- function(dates, n, cal=bizdays.options$get('default.calendar')) {
dates <- as.Date(dates)
add(dates, n, cal)
add.bizdays(dates, n, cal)
}

#' @rdname add
#' @method add POSIXlt
#' @S3method add POSIXlt
add.POSIXlt <- function(dates, n, cal=bizdays.options$get('default.calendar')) {
#' @rdname add.bizdays
#' @method add.bizdays POSIXlt
#' @S3method add.bizdays POSIXlt
add.bizdays.POSIXlt <- function(dates, n, cal=bizdays.options$get('default.calendar')) {
dates <- as.Date(dates)
add(dates, n, cal)
add.bizdays(dates, n, cal)
}

#' @rdname add
#' @method add Date
#' @S3method add Date
add.Date <- function(dates, n, cal=bizdays.options$get('default.calendar')) {
#' @rdname add.bizdays
#' @method add.bizdays Date
#' @S3method add.bizdays Date
add.bizdays.Date <- function(dates, n, cal=bizdays.options$get('default.calendar')) {
if ( ! any(dates >= cal$start.date & dates <= cal$end.date) )
stop('Given date out of range.')
dates <- as.integer(dates)
Expand Down
14 changes: 7 additions & 7 deletions inst/tests/test-calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ test_that("it should generate a sequence of bizdays", {
context('offset by a number of business days')

test_that("it should offset the date by n business days", {
expect_equal(add('2013-01-02', 1, cal), as.Date('2013-01-03'))
expect_equal(add('2013-01-02', 3, cal), as.Date('2013-01-07'))
expect_equal(add('2013-01-02', 0, cal), as.Date('2013-01-02'))
expect_equal(add('2013-01-01', 0, cal), as.Date('2013-01-02'))
expect_equal(add('2013-01-01', -1, cal), as.Date('2012-12-28'), label=add('2013-01-01', -1, cal))
expect_equal(add.bizdays('2013-01-02', 1, cal), as.Date('2013-01-03'))
expect_equal(add.bizdays('2013-01-02', 3, cal), as.Date('2013-01-07'))
expect_equal(add.bizdays('2013-01-02', 0, cal), as.Date('2013-01-02'))
expect_equal(add.bizdays('2013-01-01', 0, cal), as.Date('2013-01-02'))
expect_equal(add.bizdays('2013-01-01', -1, cal), as.Date('2012-12-28'), label=add.bizdays('2013-01-01', -1, cal))
dates <- c(as.Date('2013-01-01'), as.Date('2013-01-02'))
expect_equal(add(dates, 1, cal), c(as.Date('2013-01-03'), as.Date('2013-01-03')))
expect_equal(add.bizdays(dates, 1, cal), c(as.Date('2013-01-03'), as.Date('2013-01-03')))
cal <- Calendar(start.date='2013-01-01', end.date='2013-01-31')
expect_error(add('2013-01-10', 30, cal))
expect_error(add.bizdays('2013-01-10', 30, cal))
})

38 changes: 0 additions & 38 deletions man/add.Rd

This file was deleted.

41 changes: 41 additions & 0 deletions man/add.bizdays.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
\name{add.bizdays}
\alias{add.bizdays}
\alias{add.bizdays.Date}
\alias{add.bizdays.POSIXct}
\alias{add.bizdays.POSIXlt}
\alias{add.bizdays.character}
\title{Adds \code{n} business days to the given \code{dates}.}
\usage{
add.bizdays(dates, n, cal)

\method{add.bizdays}{character}(dates, n,
cal = bizdays.options$get("default.calendar"))

\method{add.bizdays}{POSIXct}(dates, n,
cal = bizdays.options$get("default.calendar"))

\method{add.bizdays}{POSIXlt}(dates, n,
cal = bizdays.options$get("default.calendar"))

\method{add.bizdays}{Date}(dates, n,
cal = bizdays.options$get("default.calendar"))
}
\arguments{
\item{dates}{a date or a vector of dates to be offset}

\item{n}{the amount of business days to add}

\item{cal}{an instance of Calendar}
}
\description{
This function returns the given \code{dates} offset by the
given amount of \code{n} business days.
}
\examples{
data(holidaysANBIMA)
cal <- Calendar(holidaysANBIMA)
add.bizdays("2013-01-02", 5, cal)
dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day")
add.bizdays(dates, 1, cal)
}

0 comments on commit 97dabd6

Please sign in to comment.