.packageName <- "time"
"getTime" <-
function () {
    datesep <- strsplit(date(), split = " ")[[1]];
    if (datesep[3] == "") { #if this is a single digit numbered day
	timeindex <- 5;
    }
    else {
	timeindex <- 4;
    }
#return desired time vector
    as.numeric(strsplit(datesep[timeindex], split = ":")[[1]])
}

"progressBar" <-
function ( prop=0,prev=0 ) {
	if ( prev < 50 ) {
		if ( prop > 1 ) { #then they must have given us a percent
			prop <- prop/100
		}
		bars <- round(prop*50, digits = 0) - prev;
		prev <- bars + prev;
		if ( prop == 0 ) {
			cat("          |2%      |20%      |40%      |60%      |80%      |100%\n",
				"Progress: ",sep="");
		}
		else {
			while ( bars > 0 ) {
				cat("|");
				bars <- bars - 1;
			}
		}
		if ( prev == 50 ) {
			cat("\n");
		} #We're done!
	
		return(prev)
    }
    
    prev
}

"timeChar" <-
function ( time = getTime() ) {
	result <- vector(mode="character",length=0); #init b4 paste
	plural <- c("","","");
	for ( i in 1:3 ) {
	if ( time[i] != 1 ) {
		plural[i] <- "s";
	}
	}
	if ( time[1] != 0 ) { # hours
		result <- paste(result,time[1]," hour",plural[1],sep="");
	}
	if ( time[1] != 0 && (time[2] != 0 || time[3] != 0) ) {
		result <- paste(result,", ",sep="")
	}
	if ( time[2] != 0 ) { # minutes
		result <- paste(result,time[2]," minute",plural[2],sep="");
	}
	if ( time[3] != 0 && (time[2] != 0 || time[1] != 0) ) {
		result <- paste(result,", ",sep="")
	}
	if ( time[3] != 0 ) { # seconds
		result <- paste(result,time[3]," second",plural[3],sep="");
	}
	result;
}

"timeElapsed" <-
function( old, new = getTime() ) {
    el <- new-old;
    if (el[2] < 0) {
	el[1] <- el[1] - 1;
	el[2] <- 60 + el[2];
    }
    if (el[3] < 0) {
	el[2] <- el[2] - 1;
	el[3] <- 60 + el[3];
    }
    el;
}

"timeReport" <-
function ( time ) {
	cat("The calculation took ",
		timeChar(
			timeElapsed(
				time
			)
		),
		"\n",
		sep=""
	)
}

