2015-04-25 20:58:39 +08:00
|
|
|
export default function humanTime(time) {
|
2015-02-10 15:35:40 +08:00
|
|
|
var m = moment(time);
|
2015-02-02 14:28:23 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
var minute = 6e4;
|
|
|
|
var hour = 36e5;
|
|
|
|
var day = 864e5;
|
|
|
|
var ago = null;
|
2015-02-02 14:28:23 +08:00
|
|
|
|
2015-04-25 20:58:39 +08:00
|
|
|
var diff = m.diff(moment());
|
2015-02-02 14:28:23 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
if (diff < -30 * day) {
|
2015-04-25 20:58:39 +08:00
|
|
|
if (m.year() === moment().year()) {
|
2015-02-10 15:35:40 +08:00
|
|
|
ago = m.format('D MMM');
|
2015-02-02 14:28:23 +08:00
|
|
|
} else {
|
2015-02-10 15:35:40 +08:00
|
|
|
ago = m.format('MMM \'YY');
|
2015-02-02 14:28:23 +08:00
|
|
|
}
|
2015-02-10 15:35:40 +08:00
|
|
|
} else {
|
|
|
|
ago = m.fromNow();
|
|
|
|
}
|
2015-02-02 14:28:23 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
return ago;
|
|
|
|
};
|