[PATCH stable] hgweb: fix dynamic date calculation not working under Safari

Brodie Rao brodie at bitheap.org
Mon Oct 24 14:02:22 CDT 2011


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1319482749 25200
# Branch stable
# Node ID 714c10ff19b7f4c87970a457f12d7441eb4b670b
# Parent  6d6b1b9aeea6ae692079cc33f60bef90c41bb966
hgweb: fix dynamic date calculation not working under Safari

While Chrome, Firefox, and IE 6+ support the current date format being
passed to Date(), Safari doesn't:

> new Date('Mon Oct 24 13:58:01 2011 +0200')
Invalid Date

However, the rfc3339date format does work:

> new Date('2011-10-24T13:58:01+02:00')
Mon Oct 24 2011 04:58:01 GMT-0700 (PDT)

This change adds a new data-date attribute to all age/date elements in
each theme. If process_dates() sees an age element with that
attribute, it'll prefer it over using the element's text content.

Tested in IE 6, Safari 5.1.1, Google Chrome 15, and Firefox 6.0.1.

diff --git a/mercurial/templates/coal/map b/mercurial/templates/coal/map
--- a/mercurial/templates/coal/map
+++ b/mercurial/templates/coal/map
@@ -199,7 +199,7 @@ indexentry = '
     <td><a href="{url}{sessionvars%urlparameter}">{name|escape}</a></td>
     <td>{description}</td>
     <td>{contact|obfuscate}</td>
-    <td class="age">{lastchange|date}</td>
+    <td class="age" data-date="{lastchange|rfc3339date}">{lastchange|date}</td>
     <td class="indexlinks">{archives%indexarchiveentry}</td>
   </tr>\n'
 indexarchiveentry = '<a href="{url}archive/{node|short}{extension|urlescape}"> ↓{type|escape}</a>'
diff --git a/mercurial/templates/gitweb/changelogentry.tmpl b/mercurial/templates/gitweb/changelogentry.tmpl
--- a/mercurial/templates/gitweb/changelogentry.tmpl
+++ b/mercurial/templates/gitweb/changelogentry.tmpl
@@ -1,5 +1,5 @@
 <div>
-<a class="title" href="{url}rev/{node|short}{sessionvars%urlparameter}"><span class="age">{date|date}</span>{desc|strip|firstline|escape|nonempty}<span class="logtags"> {inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}{bookmarks%bookmarktag}</span></a>
+<a class="title" href="{url}rev/{node|short}{sessionvars%urlparameter}"><span class="age" data-date="{date|rfc3339date}">{date|date}</span>{desc|strip|firstline|escape|nonempty}<span class="logtags"> {inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}{bookmarks%bookmarktag}</span></a>
 </div>
 <div class="title_text">
 <div class="log_link">
diff --git a/mercurial/templates/gitweb/changeset.tmpl b/mercurial/templates/gitweb/changeset.tmpl
--- a/mercurial/templates/gitweb/changeset.tmpl
+++ b/mercurial/templates/gitweb/changeset.tmpl
@@ -32,7 +32,7 @@ changeset |
 <div class="title_text">
 <table cellspacing="0">
 <tr><td>author</td><td>{author|obfuscate}</td></tr>
-<tr><td></td><td class="date age">{date|date}</td></tr>
+<tr><td></td><td class="date age" data-date="{date|rfc3339date}">{date|date}</td></tr>
 {branch%changesetbranch}
 <tr><td>changeset {rev}</td><td style="font-family:monospace">{node|short}</td></tr>
 {parent%changesetparent}
diff --git a/mercurial/templates/gitweb/fileannotate.tmpl b/mercurial/templates/gitweb/fileannotate.tmpl
--- a/mercurial/templates/gitweb/fileannotate.tmpl
+++ b/mercurial/templates/gitweb/fileannotate.tmpl
@@ -40,7 +40,7 @@ annotate |
  <td>{author|obfuscate}</td></tr>
 <tr>
  <td></td>
- <td class="date age">{date|date}</td></tr>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td></tr>
 {branch%filerevbranch}
 <tr>
  <td>changeset {rev}</td>
diff --git a/mercurial/templates/gitweb/filerevision.tmpl b/mercurial/templates/gitweb/filerevision.tmpl
--- a/mercurial/templates/gitweb/filerevision.tmpl
+++ b/mercurial/templates/gitweb/filerevision.tmpl
@@ -40,7 +40,7 @@ file |
  <td>{author|obfuscate}</td></tr>
 <tr>
  <td></td>
- <td class="date age">{date|date}</td></tr>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td></tr>
 {branch%filerevbranch}
 <tr>
  <td>changeset {rev}</td>
diff --git a/mercurial/templates/gitweb/map b/mercurial/templates/gitweb/map
--- a/mercurial/templates/gitweb/map
+++ b/mercurial/templates/gitweb/map
@@ -162,7 +162,7 @@ fileannotatechild = '
 tags = tags.tmpl
 tagentry = '
   <tr class="parity{parity}">
-    <td class="age"><i class="age">{date|date}</i></td>
+    <td class="age"><i class="age" data-date="{date|rfc3339date}">{date|date}</i></td>
     <td><a class="list" href="{url}rev/{node|short}{sessionvars%urlparameter}"><b>{tag|escape}</b></a></td>
     <td class="link">
       <a href="{url}rev/{node|short}{sessionvars%urlparameter}">changeset</a> |
@@ -173,7 +173,7 @@ tagentry = '
 bookmarks = bookmarks.tmpl
 bookmarkentry = '
   <tr class="parity{parity}">
-    <td class="age"><i class="age">{date|date}</i></td>
+    <td class="age"><i class="age" data-date="{date|rfc3339date}">{date|date}</i></td>
     <td><a class="list" href="{url}rev/{node|short}{sessionvars%urlparameter}"><b>{bookmark|escape}</b></a></td>
     <td class="link">
       <a href="{url}rev/{node|short}{sessionvars%urlparameter}">changeset</a> |
@@ -184,7 +184,7 @@ bookmarkentry = '
 branches = branches.tmpl
 branchentry = '
   <tr class="parity{parity}">
-    <td class="age"><i class="age">{date|date}</i></td>
+    <td class="age"><i class="age" data-date="{date|rfc3339date}">{date|date}</i></td>
     <td><a class="list" href="{url}shortlog/{node|short}{sessionvars%urlparameter}"><b>{node|short}</b></a></td>
     <td class="{status}">{branch|escape}</td>
     <td class="link">
@@ -228,7 +228,7 @@ inbranchtag = '<span class="inbranchtag"
 bookmarktag = '<span class="bookmarktag" title="{name}">{name}</span> '
 shortlogentry = '
   <tr class="parity{parity}">
-    <td class="age"><i class="age">{date|date}</i></td>
+    <td class="age"><i class="age" data-date="{date|rfc3339date}">{date|date}</i></td>
     <td><i>{author|person}</i></td>
     <td>
       <a class="list" href="{url}rev/{node|short}{sessionvars%urlparameter}">
@@ -243,7 +243,7 @@ shortlogentry = '
   </tr>'
 filelogentry = '
   <tr class="parity{parity}">
-    <td class="age"><i class="age">{date|date}</i></td>
+    <td class="age"><i class="age" data-date="{date|rfc3339date}">{date|date}</i></td>
     <td>
       <a class="list" href="{url}rev/{node|short}{sessionvars%urlparameter}">
         <b>{desc|strip|firstline|escape|nonempty}</b>
@@ -262,7 +262,7 @@ indexentry = '
     </td>
     <td>{description}</td>
     <td>{contact|obfuscate}</td>
-    <td class="age">{lastchange|date}</td>
+    <td class="age" data-date="{lastchange|rfc3339date}">{lastchange|date}</td>
     <td class="indexlinks">{archives%indexarchiveentry}</td>
     <td><div class="rss_logo"><a href="{url}rss-log">RSS</a> <a href="{url}atom-log">Atom</a></div></td>
   </tr>\n'
diff --git a/mercurial/templates/monoblue/changelogentry.tmpl b/mercurial/templates/monoblue/changelogentry.tmpl
--- a/mercurial/templates/monoblue/changelogentry.tmpl
+++ b/mercurial/templates/monoblue/changelogentry.tmpl
@@ -1,6 +1,6 @@
 <h3 class="changelog"><a class="title" href="{url}rev/{node|short}{sessionvars%urlparameter}">{desc|strip|firstline|escape|nonempty}<span class="logtags"> {inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}{bookmarks%bookmarktag}</span></a></h3>
 <ul class="changelog-entry">
-    <li class="age">{date|date}</li>
+    <li class="age" data-date="{date|rfc3339date}">{date|date}</li>
     <li>by <span class="name">{author|obfuscate}</span> <span class="revdate">[{date|rfc822date}] rev {rev}</span></li>
     <li class="description">{desc|strip|escape|addbreaks|nonempty}</li>
 </ul>
diff --git a/mercurial/templates/monoblue/changeset.tmpl b/mercurial/templates/monoblue/changeset.tmpl
--- a/mercurial/templates/monoblue/changeset.tmpl
+++ b/mercurial/templates/monoblue/changeset.tmpl
@@ -38,7 +38,7 @@
     <h2 class="no-link no-border">changeset</h2>
 
     <h3 class="changeset"><a href="{url}raw-rev/{node|short}">{desc|strip|escape|firstline|nonempty} <span class="logtags">{inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}{bookmarks%bookmarktag}</span></a></h3>
-    <p class="changeset-age age">{date|date}</p>
+    <p class="changeset-age age" data-date="{date|rfc3339date}">{date|date}</p>
 
     <dl class="overview">
         <dt>author</dt>
diff --git a/mercurial/templates/monoblue/fileannotate.tmpl b/mercurial/templates/monoblue/fileannotate.tmpl
--- a/mercurial/templates/monoblue/fileannotate.tmpl
+++ b/mercurial/templates/monoblue/fileannotate.tmpl
@@ -40,7 +40,7 @@
 
     <h2 class="no-link no-border">{file|escape}@{node|short} (annotated)</h2>
     <h3 class="changeset">{file|escape}</h3>
-    <p class="changeset-age age">{date|date}</p>
+    <p class="changeset-age age" data-date="{date|rfc3339date}">{date|date}</p>
 
     <dl class="overview">
         <dt>author</dt>
diff --git a/mercurial/templates/monoblue/filerevision.tmpl b/mercurial/templates/monoblue/filerevision.tmpl
--- a/mercurial/templates/monoblue/filerevision.tmpl
+++ b/mercurial/templates/monoblue/filerevision.tmpl
@@ -40,7 +40,7 @@
 
     <h2 class="no-link no-border">{file|escape}@{node|short}</h2>
     <h3 class="changeset">{file|escape}</h3>
-    <p class="changeset-age age">{date|date}</p>
+    <p class="changeset-age age" data-date="{date|rfc3339date}">{date|date}</p>
 
     <dl class="overview">
         <dt>author</dt>
diff --git a/mercurial/templates/monoblue/map b/mercurial/templates/monoblue/map
--- a/mercurial/templates/monoblue/map
+++ b/mercurial/templates/monoblue/map
@@ -141,7 +141,7 @@ fileannotatechild = '
 tags = tags.tmpl
 tagentry = '
   <tr class="parity{parity}">
-    <td class="nowrap age">{date|date}</td>
+    <td class="nowrap age" data-date="{date|rfc3339date}">{date|date}</td>
     <td><a href="{url}rev/{node|short}{sessionvars%urlparameter}">{tag|escape}</a></td>
     <td class="nowrap">
       <a href="{url}rev/{node|short}{sessionvars%urlparameter}">changeset</a> |
@@ -163,7 +163,7 @@ bookmarkentry = '
 branches = branches.tmpl
 branchentry = '
   <tr class="parity{parity}">
-    <td class="nowrap age">{date|date}</td>
+    <td class="nowrap age" data-date="{date|rfc3339date}">{date|date}</td>
     <td><a href="{url}shortlog/{node|short}{sessionvars%urlparameter}">{node|short}</a></td>
     <td class="{status}">{branch|escape}</td>
     <td class="nowrap">
@@ -196,7 +196,7 @@ inbranchtag = '<span class="inbranchtag"
 bookmarktag = '<span class="bookmarktag" title="{name}">{name}</span> '
 shortlogentry = '
   <tr class="parity{parity}">
-    <td class="nowrap age">{date|date}</td>
+    <td class="nowrap age" data-date="{date|rfc3339date}">{date|date}</td>
     <td>{author|person}</td>
     <td>
       <a href="{url}rev/{node|short}{sessionvars%urlparameter}">
@@ -211,7 +211,7 @@ shortlogentry = '
   </tr>'
 filelogentry = '
   <tr class="parity{parity}">
-    <td class="nowrap age">{date|date}</td>
+    <td class="nowrap age" data-date="{date|rfc3339date}">{date|date}</td>
     <td><a href="{url}rev/{node|short}{sessionvars%urlparameter}">{desc|strip|firstline|escape|nonempty}</a></td>
     <td class="nowrap">
       <a href="{url}file/{node|short}/{file|urlescape}{sessionvars%urlparameter}">file</a> | <a href="{url}diff/{node|short}/{file|urlescape}{sessionvars%urlparameter}">diff</a> | <a href="{url}annotate/{node|short}/{file|urlescape}{sessionvars%urlparameter}">annotate</a>
@@ -224,7 +224,7 @@ indexentry = '
     <td><a href="{url}{sessionvars%urlparameter}">{name|escape}</a></td>
     <td>{description}</td>
     <td>{contact|obfuscate}</td>
-    <td class="age">{lastchange|date}</td>
+    <td class="age" data-date="{lastchange|rfc3339date}">{lastchange|date}</td>
     <td class="indexlinks">{archives%indexarchiveentry}</td>
     <td>
       <div class="rss_logo">
diff --git a/mercurial/templates/paper/changeset.tmpl b/mercurial/templates/paper/changeset.tmpl
--- a/mercurial/templates/paper/changeset.tmpl
+++ b/mercurial/templates/paper/changeset.tmpl
@@ -49,7 +49,7 @@ files, or words in the commit message</d
 </tr>
 <tr>
  <th class="date">date</th>
- <td class="date age">{date|date}</td></tr>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td></tr>
 <tr>
  <th class="author">parents</th>
  <td class="author">{parent%changesetparent}</td>
diff --git a/mercurial/templates/paper/fileannotate.tmpl b/mercurial/templates/paper/fileannotate.tmpl
--- a/mercurial/templates/paper/fileannotate.tmpl
+++ b/mercurial/templates/paper/fileannotate.tmpl
@@ -54,7 +54,7 @@ files, or words in the commit message</d
 </tr>
 <tr>
  <th class="date">date</th>
- <td class="date age">{date|date}</td>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td>
 </tr>
 <tr>
  <th class="author">parents</th>
diff --git a/mercurial/templates/paper/filediff.tmpl b/mercurial/templates/paper/filediff.tmpl
--- a/mercurial/templates/paper/filediff.tmpl
+++ b/mercurial/templates/paper/filediff.tmpl
@@ -53,7 +53,7 @@ files, or words in the commit message</d
 </tr>
 <tr>
  <th>date</th>
- <td class="date age">{date|date}</td>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td>
 </tr>
 <tr>
  <th>parents</th>
diff --git a/mercurial/templates/paper/filelogentry.tmpl b/mercurial/templates/paper/filelogentry.tmpl
--- a/mercurial/templates/paper/filelogentry.tmpl
+++ b/mercurial/templates/paper/filelogentry.tmpl
@@ -1,5 +1,5 @@
  <tr class="parity{parity}">
-  <td class="age">{date|date}</td>
+  <td class="age" data-date="{date|rfc3339date}">{date|date}</td>
   <td class="author">{author|person}</td>
   <td class="description"><a href="{url}rev/{node|short}{sessionvars%urlparameter}">{desc|strip|firstline|escape|nonempty}</a>{inbranch%changelogbranchname}{branches%changelogbranchhead}{tags%changelogtag}{rename%filelogrename}</td>
  </tr>
diff --git a/mercurial/templates/paper/filerevision.tmpl b/mercurial/templates/paper/filerevision.tmpl
--- a/mercurial/templates/paper/filerevision.tmpl
+++ b/mercurial/templates/paper/filerevision.tmpl
@@ -52,7 +52,7 @@ files, or words in the commit message</d
 </tr>
 <tr>
  <th class="date">date</th>
- <td class="date age">{date|date}</td>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td>
 </tr>
 <tr>
  <th class="author">parents</th>
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -198,7 +198,7 @@ indexentry = '
     <td><a href="{url}{sessionvars%urlparameter}">{name|escape}</a></td>
     <td>{description}</td>
     <td>{contact|obfuscate}</td>
-    <td class="age">{lastchange|date}</td>
+    <td class="age" data-date="{lastchange|rfc3339date}">{lastchange|date}</td>
     <td class="indexlinks">{archives%indexarchiveentry}</td>
   </tr>\n'
 indexarchiveentry = '<a href="{url}archive/{node|short}{extension|urlescape}"> ↓{type|escape}</a>'
diff --git a/mercurial/templates/paper/shortlogentry.tmpl b/mercurial/templates/paper/shortlogentry.tmpl
--- a/mercurial/templates/paper/shortlogentry.tmpl
+++ b/mercurial/templates/paper/shortlogentry.tmpl
@@ -1,5 +1,5 @@
  <tr class="parity{parity}">
-  <td class="age">{date|date}</td>
+  <td class="age" data-date="{date|rfc3339date}">{date|date}</td>
   <td class="author">{author|person}</td>
   <td class="description"><a href="{url}rev/{node|short}{sessionvars%urlparameter}">{desc|strip|firstline|escape|nonempty}</a>{inbranch%changelogbranchname}{branches%changelogbranchhead}{tags % '<span class="tag">{name|escape}</span> '}{bookmarks % '<span class="tag">{name|escape}</span> '}</td>
  </tr>
diff --git a/mercurial/templates/spartan/changelogentry.tmpl b/mercurial/templates/spartan/changelogentry.tmpl
--- a/mercurial/templates/spartan/changelogentry.tmpl
+++ b/mercurial/templates/spartan/changelogentry.tmpl
@@ -1,6 +1,6 @@
 <table class="logEntry parity{parity}">
  <tr>
-  <th><span class="age">{date|date}</span>:</th>
+  <th><span class="age" data-date="{date|rfc3339date}">{date|date}</span>:</th>
   <th class="firstline">{desc|strip|firstline|escape|nonempty}</th>
  </tr>
  <tr>
diff --git a/mercurial/templates/spartan/changeset.tmpl b/mercurial/templates/spartan/changeset.tmpl
--- a/mercurial/templates/spartan/changeset.tmpl
+++ b/mercurial/templates/spartan/changeset.tmpl
@@ -31,7 +31,7 @@
 </tr>
 <tr>
  <th class="date">date:</th>
- <td class="date age">{date|date}</td>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td>
 </tr>
 <tr>
  <th class="files">files:</th>
diff --git a/mercurial/templates/spartan/fileannotate.tmpl b/mercurial/templates/spartan/fileannotate.tmpl
--- a/mercurial/templates/spartan/fileannotate.tmpl
+++ b/mercurial/templates/spartan/fileannotate.tmpl
@@ -30,7 +30,7 @@
  <td>{author|obfuscate}</td></tr>
 <tr>
  <td class="metatag">date:</td>
- <td class="date age">{date|date}</td>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td>
 </tr>
 <tr>
  <td class="metatag">permissions:</td>
diff --git a/mercurial/templates/spartan/filelogentry.tmpl b/mercurial/templates/spartan/filelogentry.tmpl
--- a/mercurial/templates/spartan/filelogentry.tmpl
+++ b/mercurial/templates/spartan/filelogentry.tmpl
@@ -1,6 +1,6 @@
 <table class="logEntry parity{parity}">
  <tr>
-  <th><span class="age">{date|date}</span>:</th>
+  <th><span class="age" data-date="{date|rfc3339date}">{date|date}</span>:</th>
   <th class="firstline"><a href="{url}rev/{node|short}{sessionvars%urlparameter}">{desc|strip|firstline|escape|nonempty}</a></th>
  </tr>
  <tr>
diff --git a/mercurial/templates/spartan/filerevision.tmpl b/mercurial/templates/spartan/filerevision.tmpl
--- a/mercurial/templates/spartan/filerevision.tmpl
+++ b/mercurial/templates/spartan/filerevision.tmpl
@@ -30,7 +30,7 @@
  <td>{author|obfuscate}</td></tr>
 <tr>
  <td class="metatag">date:</td>
- <td class="date age">{date|date}</td></tr>
+ <td class="date age" data-date="{date|rfc3339date}">{date|date}</td></tr>
 <tr>
  <td class="metatag">permissions:</td>
  <td>{permissions|permissions}</td></tr>
diff --git a/mercurial/templates/spartan/map b/mercurial/templates/spartan/map
--- a/mercurial/templates/spartan/map
+++ b/mercurial/templates/spartan/map
@@ -168,7 +168,7 @@ indexentry = '
     <td><a href="{url}{sessionvars%urlparameter}">{name|escape}</a></td>
     <td>{description}</td>
     <td>{contact|obfuscate}</td>
-    <td class="age">{lastchange|date}</td>
+    <td class="age" data-date="{lastchange|rfc3339date}">{lastchange|date}</td>
     <td class="indexlinks">
       <a href="{url}rss-log">RSS</a>
       <a href="{url}atom-log">Atom</a>
diff --git a/mercurial/templates/spartan/shortlogentry.tmpl b/mercurial/templates/spartan/shortlogentry.tmpl
--- a/mercurial/templates/spartan/shortlogentry.tmpl
+++ b/mercurial/templates/spartan/shortlogentry.tmpl
@@ -1,6 +1,6 @@
 <table class="slogEntry parity{parity}">
  <tr>
-  <td class="age">{date|date}</td>
+  <td class="age" data-date="{date|rfc3339date}">{date|date}</td>
   <td class="author">{author|person}</td>
   <td class="node"><a href="{url}rev/{node|short}{sessionvars%urlparameter}">{desc|strip|firstline|escape|nonempty}</a></td>
  </tr>
diff --git a/mercurial/templates/static/mercurial.js b/mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js
+++ b/mercurial/templates/static/mercurial.js
@@ -226,7 +226,12 @@ process_dates = (function(document, RegE
 			var node = nodes[i];
 			var classes = node.className;
 			if (ageclass.test(classes)){
-				var agevalue = age(node.textContent);
+				var agevalue = node.getAttribute('data-date');
+				if (agevalue === null){
+					agevalue = node.textContent;
+				}
+				agevalue = age(agevalue);
+
 				if (dateclass.test(classes)){
 					// We want both: date + (age)
 					node.textContent += ' ('+agevalue+')';


More information about the Mercurial-devel mailing list