From 02a3fbb876792caf4d5346d64f8de6bda72e7507 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Mon, 29 Aug 2016 14:50:01 +0200 Subject: [PATCH 1/4] Detect strftime year/month/day specifiers in weechat.look.buffer_time_format Accodingly include year/month/day into our time format. --- js/connection.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/js/connection.js b/js/connection.js index e20a29e..419de16 100644 --- a/js/connection.js +++ b/js/connection.js @@ -77,6 +77,10 @@ weechat.factory('connection', ); }; + var _timeDelimiter = function(delim) { + return "'" + delim + "'"; + }; + var _parseWeechatTimeFormat = function() { // Fetch the buffer time format from weechat var timeFormat = models.wconfig['weechat.look.buffer_time_format']; @@ -88,7 +92,7 @@ weechat.factory('connection', // one of four formats, (short|long) (12|24)-hour time var angularFormat = ""; - var timeDelimiter = "':'"; + var timeDelimiter = _timeDelimiter(":"); var left12 = "hh" + timeDelimiter + "mm"; var right12 = "' 'a"; @@ -132,6 +136,19 @@ weechat.factory('connection', angularFormat = short24; } + if (timeFormat.indexOf("%d") > -1) { + angularFormat = "dd" + _timeDelimiter(" ") + angularFormat; + if (timeFormat.indexOf("%m") > -1) { + angularFormat = "MM" + _timeDelimiter("-") + angularFormat; + if (timeFormat.indexOf("%y") > -1) { + angularFormat = "yy" + _timeDelimiter("-") + angularFormat; + } + if (timeFormat.indexOf("%Y") > -1) { + angularFormat = "yyyy" + _timeDelimiter("-") + angularFormat; + } + } + } + $rootScope.angularTimeFormat = angularFormat; }; From e65804c7a7a0af1ec80319ceab81461b8ecb7550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 19 Sep 2016 09:35:52 +0200 Subject: [PATCH 2/4] Date format: detect %e, too, and add some comments --- js/connection.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/js/connection.js b/js/connection.js index 419de16..8648b5b 100644 --- a/js/connection.js +++ b/js/connection.js @@ -77,11 +77,12 @@ weechat.factory('connection', ); }; - var _timeDelimiter = function(delim) { - return "'" + delim + "'"; - }; - var _parseWeechatTimeFormat = function() { + // helper function to get a custom delimiter span + var _timeDelimiter = function(delim) { + return "'" + delim + "'"; + }; + // Fetch the buffer time format from weechat var timeFormat = models.wconfig['weechat.look.buffer_time_format']; @@ -136,14 +137,18 @@ weechat.factory('connection', angularFormat = short24; } - if (timeFormat.indexOf("%d") > -1) { + // Check for day of month in time string + if (timeFormat.indexOf("%d") > -1 || timeFormat.indexOf("%e") > -1) { angularFormat = "dd" + _timeDelimiter(" ") + angularFormat; + + // month, too? if (timeFormat.indexOf("%m") > -1) { angularFormat = "MM" + _timeDelimiter("-") + angularFormat; + + // year as well? if (timeFormat.indexOf("%y") > -1) { angularFormat = "yy" + _timeDelimiter("-") + angularFormat; - } - if (timeFormat.indexOf("%Y") > -1) { + } else if (timeFormat.indexOf("%Y") > -1) { angularFormat = "yyyy" + _timeDelimiter("-") + angularFormat; } } From 79e77ffef0223d804a1d8931500d1d6c8caeeb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 19 Sep 2016 10:02:31 +0200 Subject: [PATCH 3/4] Date format: match ordering of components in weechat --- js/connection.js | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/js/connection.js b/js/connection.js index 8648b5b..1484661 100644 --- a/js/connection.js +++ b/js/connection.js @@ -137,21 +137,39 @@ weechat.factory('connection', angularFormat = short24; } - // Check for day of month in time string - if (timeFormat.indexOf("%d") > -1 || timeFormat.indexOf("%e") > -1) { - angularFormat = "dd" + _timeDelimiter(" ") + angularFormat; + // Assemble day of month + var date_components = []; - // month, too? - if (timeFormat.indexOf("%m") > -1) { - angularFormat = "MM" + _timeDelimiter("-") + angularFormat; + // Check for day of month in time format + var day_pos = Math.max(timeFormat.indexOf("%d"), + timeFormat.indexOf("%e")); + date_components.push([day_pos, "dd"]); - // year as well? - if (timeFormat.indexOf("%y") > -1) { - angularFormat = "yy" + _timeDelimiter("-") + angularFormat; - } else if (timeFormat.indexOf("%Y") > -1) { - angularFormat = "yyyy" + _timeDelimiter("-") + angularFormat; - } + // month of year? + var month_pos = timeFormat.indexOf("%m"); + date_components.push([month_pos, "MM"]); + + // year as well? + var year_pos = Math.max(timeFormat.indexOf("%y"), + timeFormat.indexOf("%Y")); + if (timeFormat.indexOf("%y") > -1) { + date_components.push([year_pos, "yy"]); + } else if (timeFormat.indexOf("%Y") > -1) { + date_components.push([year_pos, "yyyy"]); + } + + // if there is a date, assemble it in the right order + if (date_components.length > 0) { + date_components.sort(); + var format_array = []; + for (var i = 0; i < date_components.length; i++) { + if (date_components[i][0] == -1) continue; + format_array.push(date_components[i][1]); } + // TODO: parse delimiter as well? For now, use '/' as it is + // more common internationally than '-' + var date_format = format_array.join(_timeDelimiter("/")); + angularFormat = date_format + _timeDelimiter(" ") + angularFormat; } $rootScope.angularTimeFormat = angularFormat; From cc4d4bf20e2b9ce99f2a49b6c33a4e570990e365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 19 Sep 2016 10:04:15 +0200 Subject: [PATCH 4/4] Fix comment --- js/connection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/connection.js b/js/connection.js index 1484661..2570a63 100644 --- a/js/connection.js +++ b/js/connection.js @@ -137,7 +137,7 @@ weechat.factory('connection', angularFormat = short24; } - // Assemble day of month + // Assemble date format var date_components = []; // Check for day of month in time format