Revision: bcfff714d2b9
Author:   Pekka Klärck
Date:     Thu Jun  9 04:09:24 2011
Log:      cleaned up showing generated times
http://code.google.com/p/robotframework/source/detail?r=bcfff714d2b9

Modified:
 /src/robot/webcontent/js/generatedAgo.js
 /src/robot/webcontent/log.html
 /src/robot/webcontent/report.html

=======================================
--- /src/robot/webcontent/js/generatedAgo.js    Sun May 29 22:33:49 2011
+++ /src/robot/webcontent/js/generatedAgo.js    Thu Jun  9 04:09:24 2011
@@ -1,53 +1,38 @@
-function get_end(number) {
-  if (number == 1) { return ' '; }
-  return 's ';
-}
-function get_sec_str(secs) {
-  return secs + ' second' + get_end(secs);
-}
-function get_min_str(mins) {
-  return mins + ' minute' + get_end(mins);
-}
-function get_hour_str(hours) {
-  return hours + ' hour' + get_end(hours);
-}
-function get_day_str(days) {
-  return days + ' day' + get_end(days);
-}
-function get_year_str(years) {
-  return years + ' year' + get_end(years);
-}
-var generated = Math.round(window.testdata.generated().getTime() / 1000);
-current = Math.round(new Date().getTime() / 1000);
-elapsed = current - generated;
-
-if (elapsed < 0) {
-  elapsed = Math.abs(elapsed);
-  prefix = '- ';
-}
-else {
-  prefix = '';
-}
-secs  = elapsed % 60;
-mins  = Math.floor(elapsed / 60) % 60;
-hours = Math.floor(elapsed / (60*60)) % 24;
-days  = Math.floor(elapsed / (60*60*24)) % 365;
-years = Math.floor(elapsed / (60*60*24*365));
-if (years > 0) {
-  // compensate the effect of leap years (not perfect but should be enough)
-  days = days - Math.floor(years / 4);
-  if (days < 0) { days = 0; }
-  output = get_year_str(years) + get_day_str(days);
-}
-else if (days > 0) {
-  output = get_day_str(days) +  get_hour_str(hours);
-}
-else if (hours > 0) {
-  output = get_hour_str(hours) + get_min_str(mins);
-}
-else if (mins > 0) {
-  output = get_min_str(mins) + get_sec_str(secs);
-}
-else {
-  output = get_sec_str(secs);
-}
+function createGeneratedAgoString(generatedAgoMillis) {
+    function timeString(time, shortUnit) {
+        var unit = {'y': 'year', 'd': 'day', 'h': 'hour',
+                    'm': 'minute', 's': 'second'}[shortUnit];
+        var end = time == 1 ? ' ' : 's ';
+        return time + ' ' + unit + end;
+    }
+    function compensateLeapYears(days, years) {
+        // Not a perfect algorithm but ought to be enough
+        return days - Math.floor(years / 4);
+    }
+    var generated = Math.round(generatedAgoMillis / 1000);
+    var current = Math.round(new Date().getTime() / 1000);
+    var elapsed = current - generated;
+    if (elapsed < 0) {
+        elapsed = Math.abs(elapsed);
+        prefix = '- ';
+    } else {
+        prefix = '';
+    }
+    var secs  = elapsed % 60;
+    var mins  = Math.floor(elapsed / 60) % 60;
+    var hours = Math.floor(elapsed / (60*60)) % 24;
+    var days  = Math.floor(elapsed / (60*60*24)) % 365;
+    var years = Math.floor(elapsed / (60*60*24*365));
+    if (years > 0) {
+        days = compensateLeapYears(days, years);
+        return prefix + timeString(years, 'y') + timeString(days, 'd');
+    } else if (days > 0) {
+        return prefix + timeString(days, 'd') + timeString(hours, 'h');
+    } else if (hours > 0) {
+        return prefix + timeString(hours, 'h') + timeString(mins, 'm');
+    } else if (mins > 0) {
+        return prefix + timeString(mins, 'm') + timeString(secs, 's');
+    } else {
+        return prefix + timeString(secs, 's');
+    }
+}
=======================================
--- /src/robot/webcontent/log.html      Wed Jun  8 04:21:18 2011
+++ /src/robot/webcontent/log.html      Thu Jun  9 04:09:24 2011
@@ -12,9 +12,6 @@
     color: black;
     padding: 6px;
   }
-  h2 {
-    margin-top: 1.2em;
-  }
   br {
     mso-data-placement: same-cell;  /* maintain line breaks in Excel */
   }
@@ -95,7 +92,7 @@
   }
   /* Misc Styles */
   .not_available {
-    color: gray;      /* no grey in IE */
+    color: gray;
     font-weight: normal;
   }
   .parent_name {
@@ -118,19 +115,14 @@
   h1 {
     margin: 0px;
     width: 70%;
-    float: left;
-  }
-  .times {
-    width: 29%;
+  }
+  #generated {
+    // TODO: Add width when timestamp in correct format
+    // width: 29%;
     float: right;
     text-align: right;
-  }
-  .generated_time, .generated_ago {
     font-size: 0.9em;
-  }
-  .spacer {
-    font-size: 0.8em;
-    clear: both;
+    white-space: nowrap;
   }
   /* Status text colors */
   .error, .fail {
@@ -158,7 +150,7 @@
   .header, table.details, table.statistics {
     width: 100%;
   }
-  .generated_ago, .expand {
+  #generated_ago, .expand {
     display: none;
   }
 </style>
@@ -282,7 +274,6 @@
 <body>
 <div class="header" id="header_div">
 </div>
-<div class="spacer">&nbsp;</div>
   <h2>Test Statistics</h2>
   <table class="statistics" id="total_stats">
     <tr>
@@ -327,12 +318,13 @@
     };
 });

+// TODO: This is duplicated in report.html
 function addHeader() {
+    var generatedAgoMillis = window.testdata.generated().getTime();
     var header = $.tmpl(window.templates.header, {
         header: document.title,
         generated: window.testdata.generated().toString(),
-        prefix: prefix,
-        output: output
+        generatedAgo: createGeneratedAgoString(generatedAgoMillis)
     });
     header.appendTo($('#header_div'));
 }
@@ -394,15 +386,13 @@
 };
 </script>

-<!--  BEGIN DYMAGIC CONTENT!!1! -->
+<!-- TODO: This is duplicated in report.html -->
 <script type="text/html" id="header_template">
-  <h1>${header}</h1>
-  <div class="times">
-    <span class="generated_time">Generated
-      <span id="generated_time">${generated}</span>
-    </span><br />
-    <span class="generated_ago">${prefix}${output}ago</span>
+  <div id="generated">
+    <span>Generated<br />${generated}</span><br />
+    <span id="generated_ago">${generatedAgo} ago</span>
   </div>
+  <h1>${header}</h1>
 </script>

 <script type="text/html" id="total_statistics_row">
=======================================
--- /src/robot/webcontent/report.html   Tue Jun  7 13:14:06 2011
+++ /src/robot/webcontent/report.html   Thu Jun  9 04:09:24 2011
@@ -21,9 +21,6 @@
   .non_critical_fail {
     background: #FF3333; /* BACKGROUND: non critical fail */
   }
-  h2 {
-    margin-top: 1.2em;
-  }
   br {
     mso-data-placement: same-cell;  /* maintain line breaks in Excel */
   }
@@ -218,7 +215,7 @@
   }
   /* Misc Styles */
   .not_available {
-    color: gray;      /* no grey in IE */
+    color: gray;
     font-weight: normal;
   }
   .parent_name {
@@ -241,19 +238,14 @@
   h1 {
     margin: 0px;
     width: 70%;
-    float: left;
-  }
-  .times {
-    width: 29%;
+  }
+  #generated {
+    // TODO: Add width when timestamp in correct format
+    // width: 29%;
     float: right;
     text-align: right;
-  }
-  .generated_time, .generated_ago {
     font-size: 0.9em;
-  }
-  .spacer {
-    font-size: 0.8em;
-    clear: both;
+    white-space: nowrap;
   }
   a.status_fail {
     color: red;
@@ -288,7 +280,7 @@
   .header, table.details, table.statistics {
     width: 100%;
   }
-  .generated_ago, .expand {
+  #generated_ago, .expand {
     display: none;
   }
 </style>
@@ -535,12 +527,13 @@
document.title = document.title.replace("[SUITE_NAME]", suite.name, "g");
 }

+// TODO: This is duplicated in log.html
 function addHeader() {
+    var generatedAgoMillis = window.testdata.generated().getTime();
     var header = $.tmpl(window.templates.header, {
         header: document.title,
-        generated:window.testdata.generated().toString(),
-        prefix:prefix,
-        output:output
+        generated: window.testdata.generated().toString(),
+        generatedAgo: createGeneratedAgoString(generatedAgoMillis)
     });
     header.appendTo($('#header_div'));
 }
@@ -587,21 +580,17 @@
         suiteDetails: $('#suite_details').template(),
         testDetailsTable: $('#test_details_table').template(),
         testDetailsRow: $('#report_test_details_row').template()
-
     };
 };
 </script>

+<!-- TODO: This is duplicated in log.html -->
 <script type="text/html" id="header_template">
-  <h1>${header}</h1>
-  <div class="times">
-    <span class="generated_time">Generated<br />
-        <span id="generated_time">${generated}</span>
-    </span><br />
-    <span class="generated_ago">
-    ${prefix}${output}ago
-    </span>
+  <div id="generated">
+    <span>Generated<br />${generated}</span><br />
+    <span id="generated_ago">${generatedAgo} ago</span>
   </div>
+  <h1>${header}</h1>
 </script>

 <script type="text/html" id="summary_table">

Reply via email to