|
|
/**
|
|
|
* 需要格式化的时间格式
|
|
|
*/
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const timeFormat = {
|
|
|
y: '剩{y}年{M}月{d}天',
|
|
|
M: '剩{M}月{d}天',
|
|
|
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;
|
|
|
const aMonth = aDay * 30;
|
|
|
const aYear = aMonth * 12;
|
|
|
|
|
|
/**
|
|
|
* 折扣专场专题列表过期时间处理 单位:s
|
|
|
* @param {[string]} time
|
|
|
* @return {[object]}
|
|
|
*/
|
|
|
const processTime = (time) => {
|
|
|
let data = {};
|
|
|
let type = '';
|
|
|
|
|
|
if (time < anHour) {
|
|
|
data.warnColor = true;
|
|
|
data.time = '低于1小时';
|
|
|
} else {
|
|
|
if (time > aYear) {
|
|
|
type = 'y';
|
|
|
} else if (time > aMonth) {
|
|
|
type = 'M';
|
|
|
} else if (time > aDay) {
|
|
|
type = 'dh';
|
|
|
} else {
|
|
|
type = 'h';
|
|
|
}
|
|
|
|
|
|
data.time = helpers.dateDiffFormat(timeFormat[type], time, 's');
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
module.exports = processTime; |