2014-12-20 14:26:46 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
export default Ember.Handlebars.makeBoundHelper(function(time) {
|
|
|
|
var m = moment(time);
|
|
|
|
var datetime = m.format(),
|
|
|
|
full = m.format('LLLL');
|
|
|
|
|
2015-01-21 11:59:00 +08:00
|
|
|
// var second = 1e3;
|
2014-12-20 14:26:46 +08:00
|
|
|
var minute = 6e4;
|
|
|
|
var hour = 36e5;
|
|
|
|
var day = 864e5;
|
2015-01-21 11:59:00 +08:00
|
|
|
// var week = 6048e5;
|
2014-12-20 14:26:46 +08:00
|
|
|
var ago = null;
|
|
|
|
|
|
|
|
var diff = Math.abs(m.diff(moment()));
|
|
|
|
|
|
|
|
if (diff < 60 * minute) {
|
2015-01-16 14:40:54 +08:00
|
|
|
ago = moment.duration(diff).minutes()+'m ago';
|
2014-12-20 14:26:46 +08:00
|
|
|
} else if (diff < 24 * hour) {
|
2015-01-16 14:40:54 +08:00
|
|
|
ago = moment.duration(diff).hours()+'h ago';
|
2014-12-20 14:26:46 +08:00
|
|
|
} else if (diff < 30 * day) {
|
2015-01-16 14:40:54 +08:00
|
|
|
ago = moment.duration(diff).days()+'d ago';
|
2015-01-21 11:59:00 +08:00
|
|
|
} else if (m.year() === moment().year()) {
|
2014-12-20 14:26:46 +08:00
|
|
|
ago = m.format('D MMM');
|
|
|
|
} else {
|
|
|
|
ago = m.format('MMM \'YY');
|
|
|
|
}
|
|
|
|
|
2015-01-21 11:59:00 +08:00
|
|
|
return new Ember.Handlebars.SafeString('<time pubdate datetime="'+datetime+'" title="'+full+'">'+ago+'</time>');
|
2014-12-20 14:26:46 +08:00
|
|
|
});
|
|
|
|
|