edit date to use formatter, compensate for invalid local time (at least don't blow up)

This commit is contained in:
Sam 2013-06-10 10:13:30 +10:00
parent 850123dce8
commit a92bb46966
2 changed files with 11 additions and 11 deletions
app/assets/javascripts/discourse

View File

@ -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 "<span class='date' title='" + fullReadable + "'>" + displayDate + "</span>";
if(wrapInSpan) {
return "<span class='date' title='" + fullReadable + "'>" + displayDate + "</span>";
} else {
return displayDate;
}
};
// mostly lifted from rails with a few amendments

View File

@ -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}));
});
/**