diff --git a/app/assets/javascripts/discourse/components/formatter.js b/app/assets/javascripts/discourse/components/formatter.js index d9c3b2aa9eb..43082ddc75e 100644 --- a/app/assets/javascripts/discourse/components/formatter.js +++ b/app/assets/javascripts/discourse/components/formatter.js @@ -98,11 +98,12 @@ Discourse.Formatter = (function(){ break; } - return formatted; + return formatted || '&mdash'; }; relativeAgeMedium = function(date, options){ var displayDate, fiveDaysAgo, oneMinuteAgo, fullReadable, leaveAgo, val; + var wrapInSpan = options.wrapInSpan ? true : false; leaveAgo = options.leaveAgo; var distance = Math.round((new Date() - date) / 1000); @@ -116,7 +117,7 @@ Discourse.Formatter = (function(){ fiveDaysAgo = 432000; oneMinuteAgo = 60; - if (distance >= 0 && distance < oneMinuteAgo) { + if (distance < oneMinuteAgo) { displayDate = Em.String.i18n("now"); } else if (distance > fiveDaysAgo) { if ((new Date()).getFullYear() !== date.getFullYear()) { @@ -127,7 +128,11 @@ Discourse.Formatter = (function(){ } else { displayDate = relativeAgeMediumSpan(distance, leaveAgo); } - return "" + displayDate + ""; + if(wrapInSpan) { + return "" + displayDate + ""; + } else { + return displayDate; + } }; // mostly lifted from rails with a few amendments diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index 6e0af1f217e..79e51360ec5 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -210,14 +210,9 @@ Handlebars.registerHelper('unboundAge', function(property, options) { @for Handlebars **/ Handlebars.registerHelper('editDate', function(property, options) { - var dt, yesterday; - dt = Date.create(Ember.Handlebars.get(this, property, options)); - yesterday = new Date() - (60 * 60 * 24 * 1000); - if (yesterday > dt.getTime()) { - return dt.format("long"); - } else { - return dt.relative(); - } + // autoupdating this is going to be painful + var date = new Date(Ember.Handlebars.get(this, property, options)); + return new Handlebars.SafeString(Discourse.Formatter.relativeAge(date, {format: 'medium', leaveAgo: true, wrapInSpan: false})); }); /**