timeProcess.js
1.1 KB
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
50
51
52
53
54
/**
* 需要格式化的时间格式
*/
'use strict';
import helper from './helper';
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]}
*/
export default function timeProcess(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;
}