From 830cd92822fbfd06a35140c30aa2e77667d7580f Mon Sep 17 00:00:00 2001 From: Kevin Glowacz Date: Mon, 1 Feb 2010 01:08:11 +0000 Subject: [PATCH] (trunk web) friendlier formatTimestamp display --- web/javascript/common.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/web/javascript/common.js b/web/javascript/common.js index 57876ec61..daeb2e55b 100644 --- a/web/javascript/common.js +++ b/web/javascript/common.js @@ -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(' '); }; /*