From d1784f1f8791cd8662e3e611f36ce12048dc9218 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 7 Jun 2013 18:27:25 +1000 Subject: [PATCH] more moment goodness --- .../discourse/components/formatter.js | 25 +++++++++++++------ .../discourse/helpers/application_helpers.js | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/components/formatter.js b/app/assets/javascripts/discourse/components/formatter.js index 5b6374fc815..d9c3b2aa9eb 100644 --- a/app/assets/javascripts/discourse/components/formatter.js +++ b/app/assets/javascripts/discourse/components/formatter.js @@ -1,10 +1,14 @@ Discourse.Formatter = (function(){ - var updateRelativeAge, autoUpdatingRelativeAge, relativeAge, relativeAgeTiny, relativeAgeMedium, relativeAgeMediumSpan; + var updateRelativeAge, autoUpdatingRelativeAge, relativeAge, relativeAgeTiny, relativeAgeMedium, relativeAgeMediumSpan, longDate; - var shortDateNoYear = Ember.String.i18n("dates.short_date_no_year"); - var longDate = Ember.String.i18n("dates.long_date"); - var shortDate = Ember.String.i18n("dates.short_date"); + var shortDateNoYearFormat = Ember.String.i18n("dates.short_date_no_year"); + var longDateFormat = Ember.String.i18n("dates.long_date"); + var shortDateFormat = Ember.String.i18n("dates.short_date"); + + longDate = function(dt) { + return moment(dt).format(longDateFormat); + }; updateRelativeAge = function(elems) { elems.each(function(){ @@ -107,7 +111,7 @@ Discourse.Formatter = (function(){ return "—"; } - fullReadable = moment(date).format(longDate); + fullReadable = longDate(date); displayDate = ""; fiveDaysAgo = 432000; oneMinuteAgo = 60; @@ -116,9 +120,9 @@ Discourse.Formatter = (function(){ displayDate = Em.String.i18n("now"); } else if (distance > fiveDaysAgo) { if ((new Date()).getFullYear() !== date.getFullYear()) { - displayDate = moment(date).format(shortDate); + displayDate = moment(date).format(shortDateFormat); } else { - displayDate = moment(date).format(shortDateNoYear); + displayDate = moment(date).format(shortDateNoYearFormat); } } else { displayDate = relativeAgeMediumSpan(distance, leaveAgo); @@ -140,5 +144,10 @@ Discourse.Formatter = (function(){ return "UNKNOWN FORMAT"; }; - return {relativeAge: relativeAge, autoUpdatingRelativeAge: autoUpdatingRelativeAge, updateRelativeAge: updateRelativeAge}; + return { + longDate: longDate, + relativeAge: relativeAge, + autoUpdatingRelativeAge: autoUpdatingRelativeAge, + updateRelativeAge: updateRelativeAge + }; })(); diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index e396191eaf4..a3c6f3223a2 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -174,7 +174,7 @@ Handlebars.registerHelper('avatar', function(user, options) { **/ Handlebars.registerHelper('unboundDate', function(property, options) { var dt = new Date(Ember.Handlebars.get(this, property, options)); - return dt.format("long"); + return Discourse.Formatter.longDate(dt); }); /**