time-process.js 916 Bytes
/**
 * 需要格式化的时间格式
 */

'use strict';

const helpers = global.yoho.helpers;

const timeFormat = {
    d: '剩{d}天',
    h: '剩{h}小时',
    m: '剩{m}分钟',
    s: '剩{s}秒',
    dh: '剩{d}天{h}小时',
    dhms: '剩{d}天{h}小时{m}分钟{s}秒',
    hms: '剩{h}小时{m}分钟{s}秒',
    ms: '剩{m}分钟{s}秒'
};

const anHour = 3600;
const aDay = anHour * 24;

/**
 * 折扣专场专题列表过期时间处理
 * @param  {[string]} time
 * @return {[object]}
 */
const processTime = (time) => {
    let data = {};
    let type = '';

    if (time < anHour) {
        data.warnColor = true;
        data.time = '低于1小时';
    } else {
        if (time > aDay) {
            type = 'dh';
        } else {
            type = 'h';
        }

        data.time = helpers.dateDiffFormat(timeFormat[type], time, 's');
    }

    return data;
};

module.exports = processTime;