wilsonfreitas / R-bizdays

Business Days Calculations and Utilities

Home Page:http://wilsonfreitas.github.io/R-bizdays/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bizdays::getdate do not return the "Last XXth" date

andrefpoli opened this issue · comments

Hi Wilson,

According to the reference manual (https://cran.r-project.org/web/packages/bizdays/bizdays.pdf) on page 14 it says that expr is a character string with two terms: <position> <day>, and it would be possible to get last and XXth.

As I could check in the function below, this case is not included and using expr, for example, "last 6th" will always return "Invalid expr".

Is it possible to get the last nth bizday using this function or maybe I'm using the wrong one?

Regards,

getdate <- function(expr, ref, cal = bizdays.options$get("default.calendar")) {
  cal <- check_calendar(cal)
  ref <- ref(ref)
  tok <- strsplit(expr, "\\s+")[[1]]
  if (length(tok) != 2) {
    stop("Invalid expr", expr)
  }
  n <- getnth_(tok[1])
  if (tok[2] == "day") {
    getnthday(ref, n, FALSE, cal)
  } else if (tok[2] == "bizday") {
    getnthday(ref, n, TRUE, cal)
  } else if (tok[2] %in% WEEKDAYS) {
    wday <- which(tok[2] == WEEKDAYS)
    getnthweekday(ref, n, wday, cal)
  } else {
    stop("Invalid expr", expr)
  }
}