AlaK4X
Linux lhjmq-records 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 x86_64



Your IP : 3.133.155.253


Current Path : /var/www/lhjmq-records.qc.ca/public_html/administration/js/
Upload File :
Current File : /var/www/lhjmq-records.qc.ca/public_html/administration/js/timeFuncs.js

function isTime_relative(time, minTime, maxTime){
	//System constants
	var AllowedNotations = "hms";
	var AllowedChars = "0123456789:hms";
	var i = 0;
	//Check if the time contains nothing other than double dots, numbers and standard time notation letters
	for(i=0; i<time.length; i++){
		if(AllowedChars.indexOf(time.substr(i,1)) == -1){
			return false;
		}
		if(AllowedNotations.indexOf(time.substr(i,1)) != -1){
			time = time.replace("h", ":");
			time = time.replace("m", ":");
			time = time.replace("s", ":");
		}
	}
	//Split the time according to the time format
	if(time.indexOf(":") == -1){
		//Split the time in relative no delimitation format (000000) (standard time with no delimitations)
		var timeArray = splitInTime_relative_no_delimitations(time);
	}else{
		//Split the time in relative format (00:00:00) (standard time)
		var timeArray = splitInTime_relative(time);
	}
	//Check the numbers so that they do not go over or under the standard time
	if(timeArray.length == 1){
		//Supose the time is in seconds[0] (00)
		if(timeArray[0] < 0 || timeArray[0] > 59){
			return false;
		}
	}
	if(timeArray.length == 2){
		//Supose the time is in seconds[1] and minutes[0] (00:00)
		if(timeArray[0] < 0 || timeArray[0] > 59){
			return false;
		}
		if(timeArray[1] < 0 || timeArray[1] > 59){
			return false;
		}
	}
	if(timeArray.length == 3){
		//Supose the time is in seconds[2], minutes[1] and hours[0] (00:00:00)
		if(timeArray[0] < 0 || timeArray[0] > 23){
			return false;
		}
		if(timeArray[1] < 0 || timeArray[1] > 59){
			return false;
		}
		if(timeArray[2] < 0 || timeArray[2] > 59){
			return false;
		}
	}
	//Check the user defined boundaries
	var minTimeArray = splitInTime_relative(minTime);
	var maxTimeArray = splitInTime_relative(maxTime);
	if(timeArray.length == 1){
		//Check the seconds only
		if((minTimeArray[1] - 0) > (timeArray[0] - 0)){
			alert("a");
			return false;
		}else if((maxTimeArray[1] - 0) < (timeArray[0] - 0)){
			alert((maxTimeArray[1] - 0) + " < " + (timeArray[0] - 0));
			return false;
		}
	}else if(timeArray.length == 2){
		//Check minutes, if minutes are equal on any min or max side check seconds also
		//if hour is lower than minimum hour
		if((minTimeArray[0] - 0) > (timeArray[0] - 0)){
			return false;
		//if hour is higher than maximum hour
		}else if((maxTimeArray[0] - 0) < (timeArray[0] - 0)){
			return false;
		//if max hour = hour and max minute < minutes
		}else if((maxTimeArray[0] - 0) == (timeArray[0] - 0) && (maxTimeArray[1] - 0) < (timeArray[1] - 0)){
			return false;
		//If min hour = hour and min minutes > minutes
		}else if((minTimeArray[0] - 0) == (timeArray[0] - 0) && (minTimeArray[1] - 0) > (timeArray[1] - 0)){
			return false;
		}
	}else if(timeArray.length == 3){
		//Check hours, if hours are equal on any min or max side check minutes, if minutes are equal on any min or max side, check the seconds
		if((minTimeArray[0] - 0) > (timeArray[0] - 0)){
			return false;
		}else if((maxTimeArray[0] - 0) < (timeArray[0] - 0)){
			return false;
		}else if((maxTimeArray[0] - 0) == (timeArray[0] - 0) && (maxTimeArray[1] - 0) < (timeArray[1] - 0)){
			return false;
		}else if((minTimeArray[0] - 0) == (timeArray[0] - 0) && (minTimeArray[1] - 0) > (timeArray[1] - 0)){
			return false;
		}else if((maxTimeArray[0] - 0) == (timeArray[0] - 0) && (maxTimeArray[1] - 0) == (timeArray[1] - 0) && (maxTimeArray[2] - 0) < (timeArray[2] - 0)){
			return false;
		}else if((minTimeArray[0] - 0) == (timeArray[0] - 0) && (minTimeArray[1] - 0) == (timeArray[1] - 0) && (minTimeArray[2] - 0) > (timeArray[2] - 0)){
			return false;
		}
	}
	//Return true, everything ok
	return true;
}

function isTime_abs_s(){
	//Split the time in absolute second format (0) (seconds, minutes and hours mixed together)
}

function isTime_abs_m(){
	//Split the time in absolute minute format (0.00) (minutes and hours mixed together before the dot)
}

function isTime_abs_h(){
	//Split the time in absolute hour format (0.00) (minutes and seconds mixed together after the dot)
}

function splitInTime_relative(time){
	//Time is in relative format (00:00:00)
	var splitArray = time.split(":");
	//Fill in the array correctly
	if(splitArray.length == 1){
		var timeArray = new Array(0, 0, splitArray[0]);
	}else if(splitArray.length == 2){
		var timeArray = new Array(0, splitArray[0], splitArray[1]);
	}else if(splitArray.length == 3){
		var timeArray = new Array(splitArray[0], splitArray[1], splitArray[2]);
	}
	return timeArray;
}

function splitInTime_relative_no_delimitations(time){
	//Time is in "no delimitation" format, 
	//  get the seconds from the 2 last numbers,
	//  get the minutes from the 2 4rth numbers from last numbers
	// get the hours from the 2 6th numbers from the last numbers
	switch(time.length){
		case 0:
			var timeArray = new Array(0, 0, 0);
			break;
		case 1:
			var timeArray = new Array(0, 0, time.substr(time.length - 1, 1));
			break;
		case 2:
			var timeArray = new Array(0, 0, time.substr(time.length - 2, 2));
			break;
		case 3:
			var timeArray = new Array(0, time.substr(time.length - 3, 1), time.substr(time.length - 2, 2));
			break;
		case 4:
			var timeArray = new Array(0, time.substr(time.length - 4, 2), time.substr(time.length - 2, 2));
			break;
		case 5:
			var timeArray = new Array(time.substr(time.length - 5, 1), time.substr(time.length - 4, 2), time.substr(time.length - 2, 2));
			break;
		case 6:
		default:
			var timeArray = new Array(time.substr(time.length - 6, 2), time.substr(time.length - 4, 2), time.substr(time.length - 2, 2));
			break;
	}
	return timeArray;
}