<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Date/Time Difference" 
category="tools" category2="lifestyle" description="Calcualte the difference in days, hours, minutes, and seconds between two dates, day, date, difference, hour, minute, second, between" 
title_url="http://gadget-blog.ro/" 
author="Johnny Kind" 
author_email="wattaman.a@gmail.com"  
author_photo="http://b.vimeocdn.com/ps/162/537/1625372_300.jpg" 
author_aboutme="Hey, check out http://cafebar.ro/" 
author_location="Bangkok, Thailand"
author_quote="I like doing gadgets!"
author_link="http://cafebar.ro/Alice" 
screenshot="http://farm8.staticflickr.com/7070/6968492493_ee24fe3dec_t.jpg" 
thumbnail="http://farm8.staticflickr.com/7070/6968492493_ee24fe3dec.jpg" 
height="260" width="260"></ModulePrefs>
<Content type="html" view="home">
<![CDATA[

<script language="javascript" type="text/javascript">
function p (i)
{
  return Math.floor(i / 10) + "" + i % 10;
}

function init ()
{
  var form = document.getElementById('form');
  var date = new Date();
  var s = p(date.getMonth() + 1) + "/" + p(date.getDate()) + "/" + date.getFullYear() + " " + p(date.getHours()) + ":" + p(date.getMinutes()) + ":" + p(date.getSeconds());
  if (form.date1.value == "")
    form.date1.value = s;
  if (form.date2.value == "")
    form.date2.value = s;
}

function trunc (i)
{
  var j = Math.round(i * 100);
  return Math.floor(j / 100) + (j % 100 > 0 ? "." + p(j % 100) : "");
}

function calculate (form)
{
  var date1 = new Date(form.date1.value);
  var date2 = new Date(form.date2.value);
  var sec = date2.getTime() - date1.getTime();
  if (isNaN(sec))
  {
    alert("Input data is incorrect!");
    return;
  }
  if (sec < 0)
  {
    alert("The second date ocurred earlier than the first one!");
    return;
  }

  var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;

  form.result_h.value = trunc(sec / hour);
  form.result_m.value = trunc(sec / minute);
  form.result_s.value = trunc(sec / second);

  var days = Math.floor(sec / day);
  sec -= days * day;
  var hours = Math.floor(sec / hour);
  sec -= hours * hour;
  var minutes = Math.floor(sec / minute);
  sec -= minutes * minute;
  var seconds = Math.floor(sec / second);
  form.result.value = days + " day" + (days != 1 ? "s" : "") + ", " + hours + " hour" + (hours != 1 ? "s" : "") + ", " + minutes + " minute" + (minutes != 1 ? "s" : "") + ", " + seconds + " second" + (seconds != 1 ? "s" : "");
}
</script>

<form id="form">
  <table cellpadding="3" style="border-collapse: collapse" border="1">
    <tr>
      <td>1st date</td>
      <td><input type="text" name="date1" placeholder="mm/dd/yy hh:mm:ss" /></td>
    </tr>
    <tr>
      <td>2nd date</td>
      <td><input type="text" name="date2" placeholder="mm/dd/yy hh:mm:ss" /></td>
    </tr>
    <tr>
      <td colspan="2" align="center">
<nobr><input type="button" name="submit" value="Find" onclick="calculate(this.form)" /> <input type="text" name="result" readonly="readonly" size="25"  placeholder="Results will display here" /></nobr><br>
<iframe border=0 frameborder=0 height=60 marginheight=0 marginwidth=0 name=explain scrolling=no src=http://atat.ro/about.html title=Portal width=234></iframe></td>
    </tr>
    <tr>
      <td>Hours</td>
      <td><input type="text" name="result_h" readonly="readonly" /></td>
    </tr>
    <tr>
      <td>Minutes</td>
      <td><input type="text" name="result_m" readonly="readonly" /></td>
    </tr>
    <tr>
      <td>Seconds</td>
      <td><input type="text" name="result_s" readonly="readonly" /></td>
    </tr>
  </table>
  </form>
<script language="JavaScript" type="text/javascript">
<!--
init();
//-->
</script>
  
   ]]>
</Content>
</Module>