FIX: null dates crashed the client app. last_posted_at was not updating properly on split topic.

This commit is contained in:
Robin Ward
2013-06-17 13:00:34 -04:00
parent 876a570e3a
commit 3c7eb3a4e8
4 changed files with 15 additions and 6 deletions
@@ -18,6 +18,8 @@ Discourse.Formatter = (function(){
}
longDate = function(dt) {
if (!dt) return;
return moment(dt).longDate();
};
@@ -30,6 +32,9 @@ Discourse.Formatter = (function(){
};
autoUpdatingRelativeAge = function(date,options) {
if (!date) return "";
options = options || {};
var format = options.format || "tiny";
@@ -272,7 +272,7 @@ Handlebars.registerHelper('number', function(property, options) {
@for Handlebars
**/
Handlebars.registerHelper('date', function(property, options) {
var leaveAgo, val;
var leaveAgo;
if (property.hash) {
if (property.hash.leaveAgo) {
leaveAgo = property.hash.leaveAgo === "true";
@@ -281,11 +281,11 @@ Handlebars.registerHelper('date', function(property, options) {
property = property.hash.path;
}
}
val = Ember.Handlebars.get(this, property, options);
var date = null;
var val = Ember.Handlebars.get(this, property, options);
if (val) {
date = new Date(val);
var date = new Date(val);
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', leaveAgo: leaveAgo}));
}
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', leaveAgo: leaveAgo}));
});