Base our time format off of weechat's config
This commit is contained in:
parent
37ba46d379
commit
ac2966ff0b
|
@ -77,6 +77,64 @@ weechat.factory('connection',
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _parseWeechatTimeFormat = function() {
|
||||||
|
// Fetch the buffer time format from weechat
|
||||||
|
var timeFormat = models.wconfig['weechat.look.buffer_time_format'];
|
||||||
|
|
||||||
|
// Weechat uses strftime, with time specifiers such as %I:%M:%S for 12h time
|
||||||
|
// The time formatter we use, AngularJS' date filter, uses a different format
|
||||||
|
// Where %I:%M:%S would be represented as hh:mm:ss
|
||||||
|
// Here, we detect what format the user has set in Weechat and slot it into
|
||||||
|
// one of four formats, (short|long) (12|24)-hour time
|
||||||
|
var angularFormat = "";
|
||||||
|
|
||||||
|
var timeDelimiter = "'<span class=\"cof-chat_time_delimiters cob-chat_time_delimiters coa-chat_time_delimiters\">:</span>'";
|
||||||
|
|
||||||
|
var left12 = "hh" + timeDelimiter + "mm";
|
||||||
|
var right12 = "' 'a";
|
||||||
|
|
||||||
|
var short12 = left12 + right12;
|
||||||
|
var long12 = left12 + timeDelimiter + "ss" + right12;
|
||||||
|
|
||||||
|
var short24 = "HH" + timeDelimiter + "mm";
|
||||||
|
var long24 = short24 + timeDelimiter + "ss";
|
||||||
|
|
||||||
|
if (timeFormat.indexOf("%H") > -1 ||
|
||||||
|
timeFormat.indexOf("%k") > -1) {
|
||||||
|
// 24h time detected
|
||||||
|
if (timeFormat.indexOf("%S") > -1) {
|
||||||
|
// show seconds
|
||||||
|
angularFormat = long24;
|
||||||
|
} else {
|
||||||
|
// don't show seconds
|
||||||
|
angularFormat = short24;
|
||||||
|
}
|
||||||
|
} else if (timeFormat.indexOf("%I") > -1 ||
|
||||||
|
timeFormat.indexOf("%l") > -1 ||
|
||||||
|
timeFormat.indexOf("%p") > -1 ||
|
||||||
|
timeFormat.indexOf("%P") > -1) {
|
||||||
|
// 12h time detected
|
||||||
|
if (timeFormat.indexOf("%S") > -1) {
|
||||||
|
// show seconds
|
||||||
|
angularFormat = long12;
|
||||||
|
} else {
|
||||||
|
// don't show seconds
|
||||||
|
angularFormat = short12;
|
||||||
|
}
|
||||||
|
} else if (timeFormat.indexOf("%r") > -1) {
|
||||||
|
// strftime doesn't have an equivalent for short12???
|
||||||
|
angularFormat = long12;
|
||||||
|
} else if (timeFormat.indexOf("%T") > -1) {
|
||||||
|
angularFormat = long24;
|
||||||
|
} else if (timeFormat.indexOf("%R") > -1) {
|
||||||
|
angularFormat = short24;
|
||||||
|
} else {
|
||||||
|
angularFormat = short24;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rootScope.angularTimeFormat = angularFormat;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// First command asks for the password and issues
|
// First command asks for the password and issues
|
||||||
// a version command. If it fails, it means the we
|
// a version command. If it fails, it means the we
|
||||||
|
@ -98,6 +156,13 @@ weechat.factory('connection',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fetch weechat time format for displaying timestamps
|
||||||
|
fetchConfValue('weechat.look.buffer_time_format',
|
||||||
|
function() {
|
||||||
|
_parseWeechatTimeFormat();
|
||||||
|
});
|
||||||
|
// Will set models.wconfig['weechat.look.buffer_time_format']
|
||||||
|
|
||||||
_requestSync();
|
_requestSync();
|
||||||
$log.info("Connected to relay");
|
$log.info("Connected to relay");
|
||||||
$rootScope.connected = true;
|
$rootScope.connected = true;
|
||||||
|
|
19
js/models.js
19
js/models.js
|
@ -347,24 +347,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
var buffer = message.buffer;
|
var buffer = message.buffer;
|
||||||
var date = message.date;
|
var date = message.date;
|
||||||
var shortTime = $filter('date')(date, 'HH:mm');
|
var shortTime = $filter('date')(date, 'HH:mm');
|
||||||
var formattedTime = "";
|
var formattedTime = $filter('date')(date, $rootScope.angularTimeFormat);
|
||||||
|
|
||||||
if ($rootScope.supports_formatting_date) {
|
|
||||||
formattedTime = date.toLocaleTimeString([], {hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
second: "2-digit"});
|
|
||||||
} else {
|
|
||||||
formattedTime = $filter('date')(date, 'HH:mm:ss');
|
|
||||||
}
|
|
||||||
|
|
||||||
formattedTime = formattedTime.replace(/ /g, " ");
|
|
||||||
// If in 12h time the hour field has only one number, zero pad it
|
|
||||||
formattedTime = formattedTime.replace(/^(\d)(:|\.)/, '0$1$2');
|
|
||||||
// Wrap the first time separator in a span
|
|
||||||
formattedTime = formattedTime.replace(/(:|\.)/, '<span class="cof-chat_time_delimiters cob-chat_time_delimiters coa-chat_time_delimiters">$1</span>');
|
|
||||||
// Wrap the second time separator and seconds field in another span
|
|
||||||
// so that we can easily hide seconds using a CSS selector
|
|
||||||
formattedTime = formattedTime.replace(/(\d\d)(:|\.)(\d\d)/, '$1<span class="seconds"><span class="cof-chat_time_delimiters cob-chat_time_delimiters coa-chat_time_delimiters">$2</span>$3</span>');
|
|
||||||
|
|
||||||
var prefix = parseRichText(message.prefix);
|
var prefix = parseRichText(message.prefix);
|
||||||
var tags_array = message.tags_array;
|
var tags_array = message.tags_array;
|
||||||
|
|
Loading…
Reference in New Issue