bookCommon.js
2.6 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import util from './util';
import App from './api';
const {regeneratorRuntime} = global
module.exports ={
//时间戳转化日期
changedate:function(timestamp){
var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y= date.getFullYear();
var M =date.getMonth()+1;
var D =date.getDate();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
return {year:Y,month:M,day:D,hour:h,minute:m,second:s};
},
//获取星期
getweek:function (index) {
var week=['周日','周一','周二','周三','周四','周五','周六'];
return week[index]
},
//判断是否是整数
isInteger:function (obj) {
return obj%1 === 0
},
//时间转化时间戳
gettimestamp:function(stringTime){
var date = new Date(stringTime.replace(/-/g, '/'));
var timestamp2=Date.parse(date)/1000;
return timestamp2
},
//日期转换 8月8日----08-08
get_date:function(thiadate){
var thismoth=thiadate.split('月')[0];
var thisday=thiadate.split('月')[1].slice(0,-1);
var timedate=(parseInt(thismoth)<10 ? '0'+thismoth : thismoth)+'-'+(parseInt(thisday)<10 ? '0'+thisday : thisday);
return timedate;
},
//日期转换 08-08----8月8日
getdate_num:function(thisdate){
var thismonth=thisdate.split('-')[0][0]=='0' ? thisdate.split('-')[0][1] : thisdate.split('-')[0];
var thisday=thisdate.split('-')[1][0]=='0' ? thisdate.split('-')[1][1] : thisdate.split('-')[1];
console.log()
var timedate=thismonth+'月'+thisday+'日';
return timedate;
},
//获得营业时段时间戳,用 - 链接
async getTimeSpace(mmdd='',timeIndex=0,sc=null){
try {
let d=new Date()/1000;
if(!mmdd){
mmdd=util.unixtoTime(d,'MM-DD');
}
if(!sc){
let res = await App.Reserve.SellerInfo(util.cache('enter_params'));
sc = res.data;
}
if (sc.daily){
let ti=['morning','noon','night'];
let ts=sc.daily[ti[timeIndex]].split('-');
console.log(ts);
let stime=util.unixtoTime(d,'YYYY-'+mmdd+' '+ts[0]+':00');
console.log(stime);
let etime=util.unixtoTime(d,'YYYY-'+mmdd+' '+ts[1]+':00');
return util.timetouUnix(stime)+'-'+util.timetouUnix(etime);
}
}catch (e){
console(e);
}
return false;
}
}