R/H-prevMonth.R

Defines functions prevMonth

prevMonth <- function(dateObject){
  
  prevMonthNumber <-
    ifelse(as.character(lubridate::month(dateObject))=="01"
           ,"12"
           ,ifelse(
             lubridate::month(dateObject)-1 < 10
             ,paste0("0",as.character(lubridate::month(dateObject)-1))
             ,as.character(lubridate::month(dateObject)-1)
           )
    )
  
  prevAssociatedYear <- prevYear(dateObject, prevMonthNumber)
  
  endOfMonth <- timeLastDayInMonth(paste0(prevAssociatedYear,"-",prevMonthNumber,"-","01"))
  
  return(endOfMonth)
  
}
erolbicero/tsconv documentation built on May 13, 2017, 8:23 p.m.