changeset 14881:2e54387976d4 stable

web: Output a correct date in short format (issue2902)
author Benoit Allard <benoit@aeteurope.nl>
date Fri, 15 Jul 2011 10:18:24 +0200
parents 5233df79deed
children bb2cffe81a94
files mercurial/templates/static/mercurial.js
diffstat 1 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templates/static/mercurial.js	Fri Jul 15 16:28:09 2011 +0300
+++ b/mercurial/templates/static/mercurial.js	Fri Jul 15 10:18:24 2011 +0200
@@ -160,13 +160,31 @@
 		if (count > 1){
 			ret = ret + 's';
 		}
+ 		return ret;
+ 	}
+
+	function shortdate(date){
+		var ret = date.getFullYear() + '-';
+		// getMonth() gives a 0-11 result
+		var month = date.getMonth() + 1;
+		if (month <= 9){
+			ret += '0' + month;
+		} else {
+			ret += month;
+		}
+		ret += '-';
+		var day = date.getDate();
+		if (day <= 9){
+			ret += '0' + day;
+		} else {
+			ret += day;
+		}
 		return ret;
 	}
 
-	function age(datestr){
-		var now = new Date();
-		var once = new Date(datestr);
-
+ 	function age(datestr){
+ 		var now = new Date();
+ 		var once = new Date(datestr);
 		if (isNaN(once.getTime())){
 			// parsing error
 			return datestr;
@@ -184,7 +202,7 @@
 		}
 
 		if (delta > (2 * scales.year)){
-			return once.getFullYear() + '-' + once.getMonth() + '-' + once.getDate();
+			return shortdate(once);
 		}
 
 		for (unit in scales){