因为写全局的公共方法没写容错处理额==,mark一下

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
/**
* 把分钟数转化为day天hour小时minute分钟
* @param minutes 总分钟数
* @param onlyToHour 是否只精确到小时(true/false)
*/
transferMinutesToTime(minutes,onlyToHour) {
const basicMinute = 60;
const basicHour = 24;
const basic = basicHour*basicMinute;

//如果minutes不是非负整数,返回null
if(!this.checkByRegExp.nonnegativeInt(minutes)){
return null;
}

//如果minutes等于0
if (minutes == 0) {
return onlyToHour ? {
day: 0,
hour: 0
} : {
day: 0,
hour: 0,
minute: 0
}
}

//如果minutes为正整数
let all = Number(minutes);
let day = Math.floor(all/basic);
let hour = Math.floor((all%basic)/basicMinute);
let minute = all%basic%basicMinute;

let data = {
day: day?day:0,
hour: hour?hour:0
}

if(!onlyToHour){
data.minute = minute?minute:0;
}

return data;
}