time-process.js
962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* 需要格式化的时间格式
*/
'use strict';
const library = '../../../library';
const helpers = require(`${library}/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;