PDA

View Full Version : JScript - 24hrs with leading zero ...



pepe_lepew1962
12-05-2012, 02:37 AM
Hello:

I found this great calendar program that has 1 main fault. It does not display 24hrs with the leading zero. I think the below code is the root of the problem. Can anyone help me here please as I know no JScript:



//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();
}

Beverleyh
12-05-2012, 10:15 AM
With the snippet of information you provided, I Googled a random line of code and found that its from the "common/dtpicker.js" file bundled with LuxCal: http://www.luxsoft.eu/

Then having just done a quick search of their website, I see that your question has already been answered by the actual developer: http://www.luxsoft.eu/forum/index.php?a=vtopic&t=904

What can we learn from this?

1 - ask your question in the right place - the source is always the best place to start (especially when their help forum is current/active)

2 - patience is a virtue - its reasonable to wait a few days for a reply before posting in other unrelated script forums

3 - if you ask for help from elsewhere, provide the information upfront and dont expect others to go hunting for all the jigsaw pieces for you

traq
12-06-2012, 04:28 AM
3 - if you ask for help from elsewhere, provide the information upfront and dont expect others to go hunting for all the jigsaw pieces for you

The fact that you did go to all that trouble doesn't really help reinforce that last point. :p

Beverleyh
12-06-2012, 06:47 AM
Yeh, I know. I went through the "steps from helpful to P'd-off";

1. Maybe google isolated the script [innocent mistake - I'll try and put it back in context for them]
2. Source site located
3. A quick search for documentation
4. Find recent thread title in help forum that looks promising [pleased cos its dated the same day]
5. Read question
6. Read name
7. Read answer [oh so they *did* go to the source! They *did* know about and have access to the whole scripts! And they got an answer and didn't resolve the thread on DD!]
8. Realise my own precious time has been wasted by a careless act of thoughtlessness and impatience
9. Raaaaarrgghhh!