date helper uses the formatter now

This commit is contained in:
Sam 2013-06-07 18:09:10 +10:00
parent 5fa20ce357
commit 000847b8d2
1 changed files with 5 additions and 27 deletions

View File

@ -262,7 +262,7 @@ Handlebars.registerHelper('number', function(property, options) {
@for Handlebars @for Handlebars
**/ **/
Handlebars.registerHelper('date', function(property, options) { Handlebars.registerHelper('date', function(property, options) {
var displayDate, dt, fiveDaysAgo, oneMinuteAgo, fullReadable, humanized, leaveAgo, val; var leaveAgo, val;
if (property.hash) { if (property.hash) {
if (property.hash.leaveAgo) { if (property.hash.leaveAgo) {
leaveAgo = property.hash.leaveAgo === "true"; leaveAgo = property.hash.leaveAgo === "true";
@ -272,32 +272,10 @@ Handlebars.registerHelper('date', function(property, options) {
} }
} }
val = Ember.Handlebars.get(this, property, options); val = Ember.Handlebars.get(this, property, options);
if (!val) { var date = null;
return new Handlebars.SafeString("—"); if (val) {
date = new Date(val);
} }
dt = new Date(val); return new Handlebars.SafeString(Discourse.Formatter.relativeAge(date, {format: 'medium', leaveAgo: leaveAgo}));
fullReadable = dt.format("long");
displayDate = "";
fiveDaysAgo = (new Date()) - 432000000;
oneMinuteAgo = (new Date()) - 60000;
if (oneMinuteAgo <= dt.getTime() && dt.getTime() <= (new Date())) {
displayDate = Em.String.i18n("now");
} else if (fiveDaysAgo > (dt.getTime())) {
if ((new Date()).getFullYear() !== dt.getFullYear()) {
displayDate = dt.format("short");
} else {
displayDate = dt.format("short_no_year");
}
} else {
humanized = dt.relative();
if (!humanized) {
return "";
}
displayDate = humanized;
if (!leaveAgo) {
displayDate = (dt.millisecondsAgo()).duration();
}
}
return new Handlebars.SafeString("<span class='date' title='" + fullReadable + "'>" + displayDate + "</span>");
}); });