JScript - 24 hours

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
pepe_lepew1962
Forum Commoner
Posts: 44
Joined: Thu Nov 20, 2008 10:29 am

JScript - 24 hours

Post by pepe_lepew1962 »

Hello:

I am using this calendar program that is just brilliant, but 1 of the faults if that it does not display the time, 24 hour, with the leading zero. I was wondering if someone could peek at the below code and help me with it. I am fairly sure this is the problem:

Code: Select all

//Time Picker

function tPicker(timeFieldId) {
	var timeField = $(timeFieldId);
	var hhmm;

	//compute tpicker coordinates (beneath timeField)
	var x = timeField.offsetLeft + timeField.offsetWidth + 22;
	var y = timeField.offsetTop - 95;
 
	//deal with elements inside tables and such
	var parent = timeField;
	while (parent.offsetParent) {
		parent = parent.offsetParent;
		x += parent.offsetLeft;
		y += parent.offsetTop ;
	}

	//If not present, create tpDiv, move it to x,y and toggle visibility
	var tpDiv = createDiv("tpDiv", x, y);

 	//draw the timepicker table; the timeField object will receive the time
	var html='<div class="tpFrame">';
	var apm = /\s*a/i.exec(tFormat);
	if (apm != null) {
		var am = String(apm).replace("a","am").replace("A","AM"); 
		var pm = String(apm).replace("a","pm").replace("A","PM"); 
	}
	if (apm != null) { html += '- AM -'; }
	for (var i=7;i<24;i++){
		if (i==7) { html += '<div class="tpAM">'; }
		if (i==12 && (apm != null)) { html += '- PM -'; }
		if (i==12) { html += '<div class="tpPM">'; }
		if (i==18) { html += '<div class="tpEM">'; }
		for (var j=0;j<60;j += 15) {
			if (apm != null) {
				hh = i;
				ampm = (hh < 12) ? am : pm;
				if (hh >= 13) { hh -= 12; }
				hhmm1 = String(hh) + ":" + String("0" + j).slice(-2) + ampm;
				hhmm2 = String("0" + hh).slice(-2) + ":" + String("0" + j).slice(-2);
			} else {
				hhmm1 = hhmm2 = String("0" + i).slice(-2) + ":" + String("0" + j).slice(-2)
			}
			html += '<a class="tpPick" href="#" onclick="updateTimeField(\''+timeFieldId+'\', \''+hhmm1+'\');">'+hhmm2+'</a>';
			if (j<45) { html += '&nbsp;&nbsp;'; }
		}
		html += (i==11 || i==17 || i==23) ? '</div>' : '<br>';
	}
	html += '</div>';
	tpDiv.innerHTML = html;
}

function updateTimeField(timeFieldId, timeString) {
	var timeField = $(timeFieldId);
	if (timeString) { timeField.value = timeString; }
	var tpDiv = $("tpDiv");
	tpDiv.style.visibility = "hidden";
	tpDiv.style.display = "none";
	timeField.focus();
}
Last edited by Benjamin on Tue Dec 04, 2012 8:42 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: JScript - 24 hours

Post by social_experiment »

Is there html that goes with the javascript?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: JScript - 24 hours

Post by Weirdan »

it seems the code have a global configuration variable called tFormat which would cause it to use 24h format when its contents does not have " a" substring
Post Reply