Changeset 10060


Ignore:
Timestamp:
Feb 1, 2010, 1:08:11 AM (12 years ago)
Author:
kjg
Message:

(trunk web) friendlier formatTimestamp display

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/javascript/common.js

    r9523 r10060  
    202202Math.formatTimestamp = function(seconds) {
    203203        var myDate = new Date(seconds*1000);
    204         return myDate.toGMTString();
     204        var now = new Date();
     205
     206        var date = "";
     207        var time = "";
     208
     209        var sameYear = now.getFullYear() == myDate.getFullYear();
     210        var sameMonth = now.getMonth() == myDate.getMonth();
     211
     212        var dateDiff = now.getDate() - myDate.getDate();
     213        if(sameYear && sameMonth && Math.abs(dateDiff) <= 1){
     214                if(dateDiff == 0){
     215                        date = "Today";
     216                }
     217                else if(dateDiff == 1){
     218                        date = "Yesterday";
     219                }
     220                else{
     221                        date = "Tomorrow";
     222                }
     223        }
     224        else{
     225                date = myDate.toDateString();
     226        }
     227
     228        var hours = myDate.getHours();
     229        var period = "AM";
     230        if(hours > 12){
     231                hours = hours - 12;
     232                period = "PM";
     233        }
     234        if(hours == 0){
     235                hours = 12;
     236        }
     237
     238        time = [hours, myDate.getMinutes(), myDate.getSeconds()].join(':');
     239
     240        return [date, time, period].join(' ');
    205241};
    206242
Note: See TracChangeset for help on using the changeset viewer.