From 9ffa28f17c191813a529be87b12fa7aadab6679c Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 3 Oct 2015 13:26:28 -0700 Subject: [PATCH] New: Show time instead of date if event occurs/occurred today Closes #808 --- src/UI/Cells/RelativeDateCell.js | 11 ++++++++--- src/UI/Shared/FormatHelpers.js | 2 +- src/UI/System/Logs/Table/LogTimeCell.js | 21 +++++++++++++++++++-- src/UI/System/Logs/logs.less | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/UI/Cells/RelativeDateCell.js b/src/UI/Cells/RelativeDateCell.js index 9dbd5228b..eb69fc855 100644 --- a/src/UI/Cells/RelativeDateCell.js +++ b/src/UI/Cells/RelativeDateCell.js @@ -12,14 +12,19 @@ module.exports = NzbDroneCell.extend({ if (dateStr) { var date = moment(dateStr); + var diff = date.diff(moment().zone(date.zone()).startOf('day'), 'days', true); var result = '{1}'; var tooltip = date.format(UiSettings.longDateTime()); var text; - if (UiSettings.get('showRelativeDates')) { - text = FormatHelpers.relativeDate(dateStr); + if (diff > 0 && diff < 1) { + text = date.format(UiSettings.time(true, false)); } else { - text = date.format(UiSettings.get('shortDateFormat')); + if (UiSettings.get('showRelativeDates')) { + text = FormatHelpers.relativeDate(dateStr); + } else { + text = date.format(UiSettings.get('shortDateFormat')); + } } this.$el.html(result.format(tooltip, text)); diff --git a/src/UI/Shared/FormatHelpers.js b/src/UI/Shared/FormatHelpers.js index 351501acd..303f60ff6 100644 --- a/src/UI/Shared/FormatHelpers.js +++ b/src/UI/Shared/FormatHelpers.js @@ -10,7 +10,7 @@ module.exports = { if (isNaN(size)) { return ''; } - + if (isNaN(rounding)) { rounding = 1; } diff --git a/src/UI/System/Logs/Table/LogTimeCell.js b/src/UI/System/Logs/Table/LogTimeCell.js index 3f8091058..1adbab10e 100644 --- a/src/UI/System/Logs/Table/LogTimeCell.js +++ b/src/UI/System/Logs/Table/LogTimeCell.js @@ -1,13 +1,30 @@ var NzbDroneCell = require('../../../Cells/NzbDroneCell'); var moment = require('moment'); +var FormatHelpers = require('../../../Shared/FormatHelpers'); var UiSettings = require('../../../Shared/UiSettingsModel'); module.exports = NzbDroneCell.extend({ className : 'log-time-cell', render : function() { - var date = moment(this._getValue()); - this.$el.html('{0}'.format(date.format(UiSettings.time(true, false)), date.format(UiSettings.longDateTime(true)))); + var dateStr = this._getValue(); + var date = moment(dateStr); + var diff = date.diff(moment().zone(date.zone()).startOf('day'), 'days', true); + var result = '{1}'; + var tooltip = date.format(UiSettings.longDateTime(true)); + var text; + + if (diff > 0 && diff < 1) { + text = date.format(UiSettings.time(true, false)); + } else { + if (UiSettings.get('showRelativeDates')) { + text = FormatHelpers.relativeDate(dateStr); + } else { + text = date.format(UiSettings.get('shortDateFormat')); + } + } + + this.$el.html(result.format(tooltip, text)); return this; } diff --git a/src/UI/System/Logs/logs.less b/src/UI/System/Logs/logs.less index f5deaf3c5..7142583ad 100644 --- a/src/UI/System/Logs/logs.less +++ b/src/UI/System/Logs/logs.less @@ -3,7 +3,7 @@ #logs-screen { .log-time-cell{ - width: 80px; + width: 100px; } .log-level-cell{