R/waterYear.R

#' Extract Water Year
#'
#' Extract year from Date object and convert to water year (Oct - Sep)
#' @param x Date object
#' @export
#' @return NULL
#' @examples
#' NULL

waterYear <- function(x){
  if (class(x) != "Date") stop("Must supply a 'Date' object")
  dt_year <- lubridate::year(x)
  dt_mon <- lubridate::month(x)
  dt_wy <- dt_year
  dt_wy[dt_mon >= 10] <- dt_wy[dt_mon >= 10] + 1
  return(dt_wy)
}
ssaxe-usgs/saxey documentation built on May 25, 2019, 5:02 a.m.