Date change: prettier messages, code cleaning

Has a weird bug:
https://github.com/glowing-bear/glowing-bear/pull/677#issuecomment-158891237
This commit is contained in:
Lorenz Hübschle-Schneider 2015-11-23 10:59:00 +01:00
parent 38d2f332db
commit 5dc40cb134

View file

@ -20,26 +20,32 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific
}; };
// inject a fake buffer line for date change // inject a fake buffer line for date change
var injectDateChangeMessage = function(message, buffer, d1, d2) { var injectDateChangeMessage = function(message, buffer, old_date, new_date) {
var d1_plus_one = d1; var old_date_plus_one = old_date;
d1_plus_one.setDate(d1_plus_one.getDate() + 1); old_date_plus_one.setDate(old_date.getDate() + 1);
d1.setHours(0, 0, 0, 0);
d2.setHours(0, 0, 0, 0); new_date.setHours(0, 0, 0, 0);
old_date.setHours(0, 0, 0, 0);
// it's not always true that a date with time 00:00:00 // it's not always true that a date with time 00:00:00
// plus one day will be time 00:00:00 // plus one day will be time 00:00:00
d1_plus_one.setHours(0, 0, 0, 0); old_date_plus_one.setHours(0, 0, 0, 0);
var content = "";
if (d1_plus_one.valueOf() === d2.valueOf()) { var content = "\u001943" + // styling
content = "\u001943Date changed to " + d2.toDateString(); "Date changed to " + new_date.toDateString();
// Comparing dates in javascript is beyond tedious
if (old_date_plus_one.valueOf() !== new_date.valueOf()) {
var date_diff = Math.round((new_date - old_date)/(24*60*60*1000));
if (date_diff < 0) {
date_diff = -1*(date_diff + 1);
content += " (" + date_diff + " days before " + old_date.toDateString() + ")";
} else { } else {
var date_diff = Math.round((d2 - d1)/(24*60*60*1000)); content += " (" + date_diff + " days have passed since " + old_date.toDateString() + ")";
date_diff = date_diff >= 0 ? date_diff : date_diff + 1;
content = "\u001943Date changed to " + d2.toDateString();
content += " (" + date_diff + " days from " + d1.toDateString() + ")";
} }
}
var line = { var line = {
buffer: buffer, buffer: buffer,
date: d2, date: new_date,
prefix: '\u001943\u2500\u2500', prefix: '\u001943\u2500\u2500',
tags_array: [], tags_array: [],
displayed: true, displayed: true,