adding language option format to musoDate funtion
This commit is contained in:
parent
71e488dc42
commit
13227008bc
@ -45,42 +45,50 @@ sumDaysOfPeriod <- function(year, periodlen, corrigated=TRUE){
|
|||||||
years <- year:(year+periodlen)
|
years <- year:(year+periodlen)
|
||||||
|
|
||||||
if(corrigated){
|
if(corrigated){
|
||||||
years100 <-length(which(years%%100==0))
|
years100 <-length(which(years%%100==0))
|
||||||
years400 <-length(which(years%%400==0))
|
years400 <-length(which(years%%400==0))
|
||||||
years4 <- length(which(years%%4==0))
|
years4 <- length(which(years%%4==0))
|
||||||
numberOfLeapdays <- years4-years100+years400
|
numberOfLeapdays <- years4-years100+years400
|
||||||
days <- periodlen*365+numberOfLeapdays
|
days <- periodlen*365+numberOfLeapdays
|
||||||
return(days)
|
return(days)
|
||||||
} else {
|
} else {
|
||||||
days <- periodlen*365
|
days <- periodlen*365
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
musoDate <- function(settings,timestep="d",combined=TRUE, corrigated=TRUE){
|
musoDate <- function(settings,timestep="d",combined=TRUE, corrigated=TRUE, format="en"){
|
||||||
##calculates a
|
##purpose: generate date label for muso
|
||||||
|
|
||||||
|
|
||||||
days <- sumDaysOfPeriod(settings$startyear,settings$numyears, corrigated=corrigated)
|
days <- sumDaysOfPeriod(settings$startyear,settings$numyears, corrigated=corrigated)
|
||||||
dates <- matrix(rep(NA,days*3),ncol=3)
|
dates <- matrix(rep(NA,days*3),ncol=3)
|
||||||
dates[1,] <- c(settings$startyear,1,1)
|
|
||||||
|
|
||||||
for(i in 2:days){
|
dates[1,] <- c(1,1,settings$startyear)
|
||||||
dates[i,]<-dates[(i-1),]
|
for(i in 2:days){
|
||||||
if((dates[i-1,2]==12)&(dates[i-1,3]==31)){
|
dates[i,]<-dates[(i-1),]
|
||||||
dates[i,] <-c((dates[(i-1),1]+1),1,1)
|
if((dates[i-1,2]==12)&(dates[i-1,1]==31)){
|
||||||
} else {
|
dates[i,] <-c(1,1,(dates[(i-1),3]+1))
|
||||||
if(dates[i-1,3]==(dayOfMonths(dates[(i-1),1],corrigated=corrigated)[dates[(i-1),2]] )){
|
|
||||||
dates[i,]<-c(dates[(i-1),1],(dates[(i-1),2]+1),1)
|
|
||||||
} else {
|
} else {
|
||||||
dates[i,3]<-dates[(i-1),3]+1
|
|
||||||
|
if(dates[i-1,1]==(dayOfMonths(dates[(i-1),3],corrigated=corrigated)[dates[(i-1),2]] )){
|
||||||
|
dates[i,]<-c(1,(dates[(i-1),2]+1),dates[(i-1),3])
|
||||||
|
} else {
|
||||||
|
dates[i,1]<-dates[(i-1),1]+1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(format=="en"){
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if(format=="hu"){
|
||||||
|
dates<-dates[,c(3,2,1)]
|
||||||
|
} else {
|
||||||
|
cat("format is coerced to english, because I don't know",format)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(combined==TRUE){
|
if(combined==TRUE){
|
||||||
dates <- apply(dates,1,function(x) paste(x,collapse="."))
|
dates <- apply(dates,1,function(x) paste(x,collapse="."))
|
||||||
return(dates)
|
return(dates)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user