more moment goodness
This commit is contained in:
parent
000847b8d2
commit
d1784f1f87
|
@ -1,10 +1,14 @@
|
||||||
Discourse.Formatter = (function(){
|
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 shortDateNoYearFormat = Ember.String.i18n("dates.short_date_no_year");
|
||||||
var longDate = Ember.String.i18n("dates.long_date");
|
var longDateFormat = Ember.String.i18n("dates.long_date");
|
||||||
var shortDate = Ember.String.i18n("dates.short_date");
|
var shortDateFormat = Ember.String.i18n("dates.short_date");
|
||||||
|
|
||||||
|
longDate = function(dt) {
|
||||||
|
return moment(dt).format(longDateFormat);
|
||||||
|
};
|
||||||
|
|
||||||
updateRelativeAge = function(elems) {
|
updateRelativeAge = function(elems) {
|
||||||
elems.each(function(){
|
elems.each(function(){
|
||||||
|
@ -107,7 +111,7 @@ Discourse.Formatter = (function(){
|
||||||
return "—";
|
return "—";
|
||||||
}
|
}
|
||||||
|
|
||||||
fullReadable = moment(date).format(longDate);
|
fullReadable = longDate(date);
|
||||||
displayDate = "";
|
displayDate = "";
|
||||||
fiveDaysAgo = 432000;
|
fiveDaysAgo = 432000;
|
||||||
oneMinuteAgo = 60;
|
oneMinuteAgo = 60;
|
||||||
|
@ -116,9 +120,9 @@ Discourse.Formatter = (function(){
|
||||||
displayDate = Em.String.i18n("now");
|
displayDate = Em.String.i18n("now");
|
||||||
} else if (distance > fiveDaysAgo) {
|
} else if (distance > fiveDaysAgo) {
|
||||||
if ((new Date()).getFullYear() !== date.getFullYear()) {
|
if ((new Date()).getFullYear() !== date.getFullYear()) {
|
||||||
displayDate = moment(date).format(shortDate);
|
displayDate = moment(date).format(shortDateFormat);
|
||||||
} else {
|
} else {
|
||||||
displayDate = moment(date).format(shortDateNoYear);
|
displayDate = moment(date).format(shortDateNoYearFormat);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
displayDate = relativeAgeMediumSpan(distance, leaveAgo);
|
displayDate = relativeAgeMediumSpan(distance, leaveAgo);
|
||||||
|
@ -140,5 +144,10 @@ Discourse.Formatter = (function(){
|
||||||
return "UNKNOWN FORMAT";
|
return "UNKNOWN FORMAT";
|
||||||
};
|
};
|
||||||
|
|
||||||
return {relativeAge: relativeAge, autoUpdatingRelativeAge: autoUpdatingRelativeAge, updateRelativeAge: updateRelativeAge};
|
return {
|
||||||
|
longDate: longDate,
|
||||||
|
relativeAge: relativeAge,
|
||||||
|
autoUpdatingRelativeAge: autoUpdatingRelativeAge,
|
||||||
|
updateRelativeAge: updateRelativeAge
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -174,7 +174,7 @@ Handlebars.registerHelper('avatar', function(user, options) {
|
||||||
**/
|
**/
|
||||||
Handlebars.registerHelper('unboundDate', function(property, options) {
|
Handlebars.registerHelper('unboundDate', function(property, options) {
|
||||||
var dt = new Date(Ember.Handlebars.get(this, property, options));
|
var dt = new Date(Ember.Handlebars.get(this, property, options));
|
||||||
return dt.format("long");
|
return Discourse.Formatter.longDate(dt);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue