timeago.js 557 Bytes
'use strict';

import TA from 'timeago.js';
import moment from 'moment';

export default function timeago(timestamp) {
    let timeagoStr = TA().format(timestamp, 'zh_CN');

    let isNSecondsAgo = timeagoStr.indexOf('秒');
    if (timeagoStr === '刚刚' || isNSecondsAgo !== -1) {
        return '1分钟前';
    }

    if (timeagoStr === '1天前') {
        return '昨天';
    }

    let isNDaysAgo = timeagoStr.indexOf('天');
    if (isNDaysAgo !== -1) {
        return moment(timestamp, 'x').format('MM.DD.YYYY');
    }

    return timeagoStr;
}