framework/ember/common/app/utils/human-time.js

43 lines
690 B
JavaScript
Raw Normal View History

2015-02-02 14:28:23 +08:00
import Ember from 'ember';
moment.locale('en', {
relativeTime : {
future: "in %s",
past: "%s ago",
s: "seconds",
m: "1m",
mm: "%dm",
h: "1h",
hh: "%dh",
d: "1d",
dd: "%dd",
M: "a month",
MM: "%d months",
y: "a year",
yy: "%d years"
}
2015-02-02 14:28:23 +08:00
});
export default function(time) {
var m = moment(time);
2015-02-02 14:28:23 +08:00
var minute = 6e4;
var hour = 36e5;
var day = 864e5;
var ago = null;
2015-02-02 14:28:23 +08:00
var diff = m.diff(moment(new Date));
2015-02-02 14:28:23 +08:00
if (diff < -30 * day) {
if (m.year() === moment(new Date).year()) {
ago = m.format('D MMM');
2015-02-02 14:28:23 +08:00
} else {
ago = m.format('MMM \'YY');
2015-02-02 14:28:23 +08:00
}
} else {
ago = m.fromNow();
}
2015-02-02 14:28:23 +08:00
return ago;
};