Skip to content

Commit

Permalink
include date in timestamps > 1d
Browse files Browse the repository at this point in the history
  • Loading branch information
leedo committed Dec 19, 2011
1 parent e7459a7 commit 8fa7063
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
23 changes: 18 additions & 5 deletions share/static/alice.js
Expand Up @@ -11014,6 +11014,11 @@ Object.extend(Alice, {
url: /(https?:\/\/[^\s<"]*)/ig
},

Months: ['Jan','Feb','Mar','Apr','May','June','July','Aug',
'Sept','Oct','Nov','Dec'],

Days: ['Sun', 'Mon','Tue','Wed','Thu','Fri','Sat'],

cleanupCopy: function(node) {
if (!node.select("li.message").length) return;

Expand Down Expand Up @@ -11041,11 +11046,14 @@ Object.extend(Alice, {
node.cleanWhitespace();
},

epochToLocal: function(epoch, format) {
epochToLocal: function(epoch, format, show_date) {
var date = new Date(parseInt(epoch) * 1000);
if (!date) return epoch;

var hours = date.getHours();
var prefix = show_date ?
sprintf("%s, %s %d, ", Alice.Days[date.getDay()], Alice.Months[date.getMonth()], date.getDate())
: "";

if (format == "12") {
var ap;
Expand All @@ -11055,10 +11063,10 @@ Object.extend(Alice, {
} else {
ap = "a"
}
return sprintf("%d:%02d%s", hours, date.getMinutes(), ap);
return sprintf("%s%d:%02d%s", prefix, hours, date.getMinutes(), ap);
}

return sprintf("%02d:%02d", hours, date.getMinutes());
return sprintf("%s%02d:%02d", prefix, hours, date.getMinutes());
},

makeLinksClickable: function(elem) {
Expand Down Expand Up @@ -12296,21 +12304,26 @@ Alice.Application = Class.create({
var stamp = li.down('.timestamp');
if (!stamp) return;

var show_date = false;
var remove = false;
var seconds = stamp.innerHTML.strip();

if (li.hasClassName("message")) {
var time = new Date(seconds * 1000);
var diff = (time - win.lasttimestamp) / 1000;
remove = !(diff >= 300 || (diff > 60 && time.getMinutes() % 5 == 0));
if (!remove) win.lasttimestamp = time;
if (!remove) {
var now = new Date();
show_date = now.getDate() != win.lasttimestamp.getDate();
win.lasttimestamp = time;
}
}

if (remove) {
stamp.remove();
}
else {
stamp.update(Alice.epochToLocal(seconds, this.options.timeformat));
stamp.update(Alice.epochToLocal(seconds, this.options.timeformat, show_date));
stamp.style.opacity = 1;
}
},
Expand Down
9 changes: 7 additions & 2 deletions src/js/alice/src/alice/application.js
Expand Up @@ -861,21 +861,26 @@ Alice.Application = Class.create({
var stamp = li.down('.timestamp');
if (!stamp) return;

var show_date = false;
var remove = false;
var seconds = stamp.innerHTML.strip();

if (li.hasClassName("message")) {
var time = new Date(seconds * 1000);
var diff = (time - win.lasttimestamp) / 1000;
remove = !(diff >= 300 || (diff > 60 && time.getMinutes() % 5 == 0));
if (!remove) win.lasttimestamp = time;
if (!remove) {
var now = new Date();
show_date = now.getDate() != win.lasttimestamp.getDate();
win.lasttimestamp = time;
}
}

if (remove) {
stamp.remove();
}
else {
stamp.update(Alice.epochToLocal(seconds, this.options.timeformat));
stamp.update(Alice.epochToLocal(seconds, this.options.timeformat, show_date));
stamp.style.opacity = 1;
}
},
Expand Down
14 changes: 11 additions & 3 deletions src/js/alice/src/alice/util.js
Expand Up @@ -5,6 +5,11 @@ Object.extend(Alice, {
url: /(https?:\/\/[^\s<"]*)/ig
},

Months: ['Jan','Feb','Mar','Apr','May','June','July','Aug',
'Sept','Oct','Nov','Dec'],

Days: ['Sun', 'Mon','Tue','Wed','Thu','Fri','Sat'],

cleanupCopy: function(node) {
if (!node.select("li.message").length) return;

Expand Down Expand Up @@ -32,11 +37,14 @@ Object.extend(Alice, {
node.cleanWhitespace();
},

epochToLocal: function(epoch, format) {
epochToLocal: function(epoch, format, show_date) {
var date = new Date(parseInt(epoch) * 1000);
if (!date) return epoch;

var hours = date.getHours();
var prefix = show_date ?
sprintf("%s, %s %d, ", Alice.Days[date.getDay()], Alice.Months[date.getMonth()], date.getDate())
: "";

if (format == "12") {
var ap;
Expand All @@ -46,10 +54,10 @@ Object.extend(Alice, {
} else {
ap = "a"
}
return sprintf("%d:%02d%s", hours, date.getMinutes(), ap);
return sprintf("%s%d:%02d%s", prefix, hours, date.getMinutes(), ap);
}

return sprintf("%02d:%02d", hours, date.getMinutes());
return sprintf("%s%02d:%02d", prefix, hours, date.getMinutes());
},

makeLinksClickable: function(elem) {
Expand Down

0 comments on commit 8fa7063

Please sign in to comment.