Home > Domino Tips > Developer > JavaScript > Showing elapsed time in web views without using Today
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVASCRIPT

Showing elapsed time in web views without using Today


Serdar Basegmez
08.26.2002
Rating: -3.75- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


If you use @today or @now function in view columns or selection formulas, it will result in noticable performance problem on server.

In Web environment, we have a powerful tool: javascript...

We will have a view with a field StartDateTime and we are going to show the time between now and StartDateTime.

Code is self-explanatory...



Code

 <SCRIPT>
function showElapsed() {

// **************************************************************
//  Display elapsed time at the web client
//  (C) Serdar Basegmez
//  sbasegmez%yahoo.com   (anti-spam precaution :)))
// **************************************************************
// 1-->
// dateadjustment is a variable that needs to be computed at the top of form. It shows us the difference of server's now and browser's now. We
// avoid negative elapsed times with the variable. At the top of template of the view ($$View Template of XXX), place a computed-for-display 
// field with the following formula. This notation is used to avoid date format conflicts...
//
//    yr:=@Text(@Year(@Now));
//    mnt:=@Text(@Month(@Now)-1);
//    dy:=@Text(@Day(@Now));
//    hr:=@Text(@Hour(@Now));
//    mn:=@Text(@Minute(@Now));
//    sc:=@Text(@Second(@Now));
//    "[<SCRIPT>var dayAtServer=new Date("+yr+"," +mnt+ "," +dy+ "," + hr+ "," +mn + "," +sc+ "); 
//     var dateadjustment=((new Date())-dayAtServer)"+"</SCRIPT>]"

// 2 -->
// You should place a declaration in JS Header of template of the view:
//
// var dates=new Array();

// 3-->
// You should place a column in a view that has a formula: It creates div's with unique names. The code set inner html's of div's according to related
// member of dates array. You should beware of replication conflicts and response documents... I have excluding these documents in the view.
//
// ourdate:=StartDateTime;
// yr:=@Text(@Year(ourdate));
// mnt:=@Text(@Month(ourdate)-1);
// dy:=@Text(@Day(ourdate));
// hr:=@Text(@Hour(ourdate));
// mn:=@Text(@Minute(ourdate));
// sc:=@Text(@Second(ourdate));
// order:=@Text(@DocNumber(""));
//
// "[<div ID='ElapsedTime"+order+"'></DIV><SCRIPT>dates["+order+"]=new Date("+yr+"," +mnt+ "," +dy+ "," + hr+ "," +mn + "," +sc+ ");</SCRIPT>]"


var datenow=(new Date())-dateadjustment;  // computes date of the server.
var i=1;

while (dates[i]!=null)  // Loop until the last doc...
{
var elapsed=0;
elapsed=Math.floor((datenow-dates[i])/60000);  //compute elapsed time in minutes. This can be replaced... division by 1000 gives time in seconds.
showdt="";


if (elapsed>=1440) {
 showdt+=String(Math.floor(elapsed/1440))+"d:";   //compute # of days...
 elapsed=elapsed%1440;
}
if (elapsed>=60) {
 showdt+=String(Math.floor(elapsed/60))+"h:";   // compute # of hours
 elapsed=elapsed%60;
} 
if (elapsed!=0) {
 showdt+=String(Math.floor(elapsed))+"m";   //compute # of minutes
}

document.getElementById("ElapsedTime"+i).innerHTML = "<Center>"+showdt+"</Center>"; //place the element...
i++;
}

counter=setTimeout("showElapsed()",1000);  //I am using this command to refresh the elapsed times each second. I am not using it for large views.
}

</SCRIPT>

<SCRIPT>
showElapsed();   //initiate the function...
</SCRIPT>
  

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
JavaScript
Trap JavaScript runtime errors in Domino Web apps
JavaScript workaround fixes Lotus Notes 8.x PostOpen event issue
Write HTML and JavaScript in Notes view rows and columns on the Web
JavaScript detects Web browser type and version in Notes/Domino 8.0.2
JavaScript creates a jump box on a Lotus Notes Web form
How to create dynamic JavaScript in Notes Domino without formulas
Trap an attachment path via the Domino file upload control field
Converting Lotus Notes views to XML documents using JavaScript
Prevent errors on iFramed pages with JavaScript
How to add keyboard functionality for Lotus Notes documents

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts