Saturday, 7 September 2013

How to workout the time to get the return value

How to workout the time to get the return value

I would like to get a help with my jquery. I have got a problem with the
return value for those times in the HTML elements. I'm working out on the
times from between time1 and time2 how long it will last for, e.g.: 4:30pm
take away 6:30pm which the return value is 2.00.
Here's a sample of what the HTML is look like:
<span id='time1'>4:30 PM</span> - <span id='title1'>The Scorpion
King</span><br></br>
<span id='time2'>6:30 PM</span> - <span id='title2'>Gone in Sixty
Seconds</span><br></br>
<span id='time3'>9:00 PM</span> - <span id='title3'>The Fast and the
Furious</span><br></br>
<span id='time4'>11:30 PM</span> - <span id='title4'>The Fast and the
Furious</span><br></br>
<span id='time5'>2:00 AM</span> - <span id='title5'>The Scorpion
King</span><br></br>
<span id='time6'>4:00 AM</span> - <span id='title6'>New Sheer Cover Studio
mineral makeup</span><br></br>
<span id='time7'>8:49 PM</span> - <span id='title7'>Tamra's O.C.
Wedding</span><br></br>
In this case, I have a return value that it will show '-10.00' from the
time1 and time2 when I work out which the return value supposed to be
showing '2.00' for 2 hours. There are other values that do the same which
it will confuse me what hours the time will last for. I have no problem
for any other return values which I will get something like 1.00, 1.30,
2.00, 2.30..etc when I work out on a different time. I would like to work
out on the time to find out how long it will last for without get the
return value '-10.00', '-11.00' or whatever it is to be using something is
like '1.00', '2.00', '3.00'...etc before to do something.
I have tried the code like this, but it will get the wrong return values
to something like '-10.00', '-11.00' or whatever it is that it supposed to
be 1.00, 2.00 or whatever.
function getSchedule($link,j)
{
var widthval = 850;
var parts = $link.split("/");
var links = parts[parts.length-1];
var programlength = 0;
$.ajax({
url:$.trim(links),
type:'GET',
data:'',
success: function(data)
{
var $data = $(data);
var title1 = $data.filter("#title1").html();
var title2 = $data.filter("#title2").html();
var time1 = $data.filter("#time1").html();
var time2 = $data.filter("#time2").html();
time1 = time1.split(" ");
var time1AMPM = time1[1];
time1 = time1[0].split(":");
time1= time1[0]+'.'+time1[1];
if($.trim(time1AMPM) == 'AM' && time1<12)
time1 = parseFloat(time1)+12;
else if($.trim(time1AMPM) == 'PM' && time1<12)
time1 = parseFloat(time1)+12;
time2 = time2.split(" ");
var time2AMPM = time2[1];
time2 = time2[0].split(":");
time2= time2[0]+'.'+time2[1];
if($.trim(time2AMPM) == 'AM' && time2<12)
time2 = parseFloat(time2)+12;
else if($.trim(time2AMPM) == 'PM' && time2<12)
time2 = parseFloat(time2)+12;
var difftime2time1 = (parseFloat(time2) -
parseFloat(time1)).toFixed(2);
var difftime3time2 = (parseFloat(time3) -
parseFloat(time2)).toFixed(2);
if(isNaN(difftime2time1))
{
difftime2time1=0;
}
if(isNaN(difftime3time2))
{
difftime3time2=0;
}
var currenttotal = 0;
var firstele = ((j-1)*1)+1; // how many programme i want to output
in per block
var lastele = parseInt(firstele)+1; // how many programme i want to
output AFTER the firstele
var k = 1;
var programlength = 0;
for(;firstele <= lastele;firstele++)
{
var nexttimedate = parseInt(k)+1;
var programlength = eval('difftime'+nexttimedate+'time'+k);
//alert(programlength);
if(programlength >= 1.00 && programlength <= 1.29)
{
$('#programe'+firstele).addClass("span1hr");
width[j]=517;
}
if(programlength >= 1.30 && programlength <= 1.80)
{
$('#programe'+firstele).addClass("span1_5hr");
width[j]=784;
}
if(programlength >= 1.81 && programlength <= 1.99)
{
$('#programe'+firstele).addClass("span2hr");
width[j]=784;
}
if(programlength >= 2.00 && programlength <= 2.29)
{
$('#programe'+firstele).addClass("span2hr");
width[j]=1051;
}
if(programlength >= 2.30 && programlength <= 2.80)
{
$('#programe'+firstele).addClass("span2_5hr");
width[j]=1318;
}
//sort this out--------1 hour
if(programlength >= 13.00 && programlength <= 13.29)
{
$('#programe'+firstele).addClass("span1hr");
width[j]=517;
}
//sort this out--------1 hour and 30 mins
if(programlength >= 13.30 && programlength <= 13.80)
{
$('#programe'+firstele).addClass("span1_5hr");
width[j]=517;
}
//sort this out--------2 hour
if(programlength >= 14.00 && programlength <= 14.29)
{
$('#programe'+firstele).addClass("span2hr");
width[j]=1585;
}
//sort this out-------- 2 hours and 30 mins
if(programlength >= 14.30 && programlength <= 14.80)
{
$('#programe'+firstele).addClass("span2_5hr");
width[j]=1585;
}
if(programlength == -10.00) //sort this out ---- 2 hour program
{
$('#programe'+firstele).addClass("span2hr");
width[j]=1051;
}
currenttotal++;
pgmcontent[firstele] = eval('title'+k);
k++;
}
checksum+=j;
if(checksuminit == checksum)
{
for(var ii=1;ii<width.length-1;ii++)
{
widthval+=width[ii];
}
for(var jj=1;jj <= pgmcontent.length-1;jj++)
{
$('#programe'+jj).html(pgmcontent[jj]);
}
for(var kk=1;kk <= imagecontent.length-1;kk++)
{
$('#image'+kk).html(imagecontent[kk]);
}
$("body").find('.rowSubPgm').each(function(index) {
$(this).css( "width", widthval+"px");
});
}
}
});
}
I can't post the jsfiddle to show as example, because the alert won't
display when I work out on the time. However I'm happy to post my website
link, so you can see the alert messages with the difference values '1.00,
2.00, '13.00', '14.00' and '-10.00'. You will know what exactly I'm
talking about.
My website link: http://testbox.elementfx.com/test.php

No comments:

Post a Comment