R/teach_date.R

Defines functions teach_date

Documented in teach_date

#' The function generates the teaching dates for my semester
#' schelme
#' @author Guomin Li
#' @param begin.date: default = "2015-09-01"
#' @param weeks: default = 30
#' @param cat default=false (not cat the result)
#' @return date serials
#' @export
#' @examples
#' teach_date("2015-09-01")
#' holiday <- c("2017-03-30","2017-05-04")
#' add_date <-c("2017-04-01")
#' teach_date("2017-03-02",holiday,add_date,cat=TRUE)
#'

teach_date <- function(begin.date,holidays=c(""),add_dates=c(""),weeks=30,cat=FALSE){
	begin = as.Date(begin.date,"%Y-%m-%d")
	dates = begin + seq(from = 0, to = (weeks-1)*7,by=7)
	datess <- as.character(dates)
	# check up the added teaching dates
	if (add_dates !="" & holidays !="") {
		#hol_len <- length(holidays) - length(add_dates) #length("")=1

		data <- sort(c(datess[!(datess %in% holidays)],add_dates))
	} else if (add_dates == "" & holidays !="" ){
		data <- sort(datess[!(datess %in% holidays)])
	} else {
		data <- datess
	}
	data17 <- data[1:17]
	tdat = format(as.Date(data17,"%Y-%m-%d"),"%Y年%m月%d日")

	if (cat==TRUE) {
		cat(paste(1:length(tdat),tdat,sep="\t"),sep="\n")
		cat(tdat,sep="\n")
	}

	return(tdat)
}
Gabegit/gmdata documentation built on May 6, 2019, 5:32 p.m.