]> granicus.if.org Git - transmission/commitdiff
(trunk web) friendlier formatTimestamp display
authorKevin Glowacz <kevin@glowacz.info>
Mon, 1 Feb 2010 01:08:11 +0000 (01:08 +0000)
committerKevin Glowacz <kevin@glowacz.info>
Mon, 1 Feb 2010 01:08:11 +0000 (01:08 +0000)
web/javascript/common.js

index 57876ec61581ef6c1b5d3defe52cfd63cce19d4e..daeb2e55b11079d1b34e16953ce4d3021322aea8 100644 (file)
@@ -201,7 +201,43 @@ Math.formatSeconds = function(seconds)
  */
 Math.formatTimestamp = function(seconds) {
        var myDate = new Date(seconds*1000);
-       return myDate.toGMTString();
+       var now = new Date();
+
+       var date = "";
+       var time = "";
+
+       var sameYear = now.getFullYear() == myDate.getFullYear();
+       var sameMonth = now.getMonth() == myDate.getMonth();
+
+       var dateDiff = now.getDate() - myDate.getDate();
+       if(sameYear && sameMonth && Math.abs(dateDiff) <= 1){
+               if(dateDiff == 0){
+                       date = "Today";
+               }
+               else if(dateDiff == 1){
+                       date = "Yesterday";
+               }
+               else{
+                       date = "Tomorrow";
+               }
+       }
+       else{
+               date = myDate.toDateString();
+       }
+
+       var hours = myDate.getHours();
+       var period = "AM";
+       if(hours > 12){
+               hours = hours - 12;
+               period = "PM";
+       }
+       if(hours == 0){
+               hours = 12;
+       }
+
+       time = [hours, myDate.getMinutes(), myDate.getSeconds()].join(':');
+
+       return [date, time, period].join(' ');
 };
 
 /*