-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
54 lines (53 loc) · 1.25 KB
/
common.js
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
var Common = {
//返回:某天的0点0分
getTime0(dt) {
return new Date(dt.setHours(0, 0, 0, 0));
},
//日期相关操作
DateHelper: {
__getTime(dt, n) {
var now = dt;
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDay(); //返回星期几的某一天;
n = day == 0 ? n + 6 : n + (day - 1);
now.setDate(now.getDate() - n);
date = now.getDate();
month = now.getMonth() + 1;
year = now.getFullYear();
var s =
year +
"-" +
(month < 10 ? "0" + month : month) +
"-" +
(date < 10 ? "0" + date : date) +
" 00:00:00";
return new Date(s);
},
getTomorrow(dt) {
var now = dt.setDate(dt.getDate() + 1);
return new Date(now);
},
//获取上周起始时间
getLastWeekStart(dt) {
return this.__getTime(dt, 7);
},
getLastWeekEnd(dt) {
return this.__getTime(dt, 1);
},
getWeekStart(dt) {
return this.__getTime(dt, 0);
},
getWeekEnd(dt) {
return this.__getTime(dt, -6);
},
},
//对promise返回的数据进行一层包装
resolveObj(res, code) {
return {
data: res,
errno: code,
};
},
};
module.exports = Common;