web: Output a correct date in short format (issue2902) stable
authorBenoit Allard <benoit@aeteurope.nl>
Fri, 15 Jul 2011 10:18:24 +0200
branchstable
changeset 14881 2e54387976d4
parent 14880 5233df79deed
child 14882 bb2cffe81a94
web: Output a correct date in short format (issue2902)
mercurial/templates/static/mercurial.js
--- 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){