>function NewsFeedRefresh() >{ > window.clearTimeout(oTimerNewsFeed) > var lcID="" > var ldDate=null > var lnLength=oNewsFeed.length > var lnNoLanguage=0 > var loID=null > loDivNewsFeed=document.getElementById("DivNewsFeed") > if (loDivNewsFeed) > { > } > else > { > return true > } > if (lnLength==0) > { > oTimerNewsFeed=setTimeout("NewsFeedRefresh()",60000) > return true > } > for (lnCounter=0; lnCounter<lnLength; lnCounter++) > { > loID=document.getElementById("LX"+oNewsFeed[lnCounter][1]+"Time") > if (loID) > { > loID.innerHTML=SinceWhen(oNewsFeed[lnCounter][2], oNewsFeed[lnCounter][3]) > } > } > oTimerNewsFeed=setTimeout("NewsFeedRefresh()",60000) >} > >function SinceWhen(tdDate,tnNoLanguage) >{ // the benefit of manually cutting out of unnecessary operations will depend on the optimization strategy of Javascript Compiler/Interpreter // V8 might do those optimizations by itself > var ldDateNow=new Date() > var lnMillisecond=ldDateNow.getTime()-tdDate.getTime() > var lnSecond=parseInt(lnMillisecond/1000) > var lnDay=parseInt(lnSecond/86400) > var lnRemaining=lnSecond-(lnDay*86400) > var lnHour=parseInt(lnRemaining/3600) > lnRemaining=lnRemaining-(lnHour*3600) > var lnMinute=parseInt(lnRemaining/60) > lnSecond=lnRemaining-(lnMinute*60) // predefining/-allocating all possible results in a array housed "more global" is more difficult as you embed a variable string sometimes // as array index would have to be enforced via min() to 1 for cases like lnDay>0, speed gain of such an approach even more doubtful // might also be dependant on Javascript engine, so test in all browsers ! // return SinceWhenReturnOptions[][] // I would at least try out speed of ternary operator "?" compared to the most inner if-assignments > var lcTime="" > switch (tnNoLanguage) > { > case 1: > if (lnDay>0) > { > if (lnDay==1) > { > lcTime="Yesterday" > } > else > { > lcTime=lnDay+" days ago" > } > } > else > { > if (lnHour>0) > { > if (lnHour==1) > { > lcTime="One hour ago" > } > else > { > lcTime=lnHour+" hours ago" > } > } > else > { > if (lnMinute>0) > { > if (lnMinute==1) > { > lcTime="One minute ago" > } > else > { > lcTime=lnMinute+" minutes ago" > } > } > else > { > if (lnSecond<10) > { > lcTime="Just now" > } > else > { > lcTime=lnSecond+" seconds ago" > } > } > } > } > break > case 2: > if (lnDay>0) > { > if (lnDay==1) > { > lcTime="Hier" > } > else > { > lcTime="Il y a "+lnDay+" jours" > } > } > else > { > if (lnHour>0) > { > if (lnHour==1) > { > lcTime="Il y a une heure" > } > else > { > lcTime="Il y a "+lnHour+" heures" > } > } > else > { > if (lnMinute>0) > { > if (lnMinute==1) > { > lcTime="Il y a une minute" > } > else > { > lcTime="Il y a "+lnMinute+" minutes" > } > } > else > { > if (lnSecond<10) > { > lcTime="Maintenant" > } > else > { > lcTime="Il y a "+lnSecond+" secondes" > } > } > } > } > break > } > return lcTime >} >>