let data1 = [];
export function getYear(){
    let current = new Date();
    let year = current.getFullYear();
    let month = current.getMonth() + 1;
    let calendar = [];
    while (year > current.getFullYear() - 1 ||month > current.getMonth() + 1) {
        calendar.push(year + "/" + formatNumber(month));
        month -= 1;
        if (month <= 0) {
            year -= 1;
            month = 12;
        }
    }
    return calendar.reverse();
}
function formatNumber(value) {
    return (value < 10 ? "0" : "") + value;
}
function getDay(day) {
    var today = new Date();
    var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
    today.setTime(targetday_milliseconds);
    var tYear = today.getFullYear();
    var tMonth = today.getMonth();
    var tDate = today.getDate();
    tMonth = doHandleMonth(tMonth + 1);
    tDate = doHandleMonth(tDate);
     return tYear+"-"+tMonth+"-"+tDate; //年月日
    //return tMonth + "-" + tDate; //月日
}
export function getCurrentTime() {
    //获取当前时间并打印
    var currentTime = '';
    let yy = new Date().getFullYear();
    let mm = new Date().getMonth()+1;
    let dd = new Date().getDate();
    let hh = new Date().getHours();
    let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
    let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
    currentTime = yy+'/'+mm+'/'+dd+' '+hh+':'+mf+':'+ss;
    return currentTime;
}
function doHandleMonth(month) {
    var m = month;
    if (month.toString().length == 1) {
        m = "0" + month;
    }
    return m;
}

export function daysX(day) {  //拼接
    data1.splice(0);//请控之前的数据
    for (let i = 1; i < day + 1; i++) {
        data1.push(getDay(-i));//-i 代表之前  i代表将来
    }
    return data1.reverse()
}
export function daysY(day) {  //拼接
    let dataInUse = []
    for (let i = 0; i < day; i++) {
        dataInUse.push(0);//-i 代表之前  i代表将来
    }
    return dataInUse
}
function getNextDate(date,day) {
    var dd = new Date(date);
    dd.setDate(dd.getDate() + day);
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
    var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
    return y + "-" + m + "-" + d;
}
export function getWeek(date,day) {  //拼接
    let dataUse = [];
    for (let i = 0; i < day; i++) {
        dataUse.push(getNextDate(date,-i));//-i 代表之前  i代表将来
    }
    return dataUse.reverse()
}
function formatterDate(date) {
    var datetime = date.getFullYear()
        + "-"// "年"
        + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
            + (date.getMonth() + 1))
        + "-"// "月"
        + (date.getDate() < 10 ? "0" + date.getDate() : date
            .getDate());
    return datetime;
}
export function startTime() {
    let date =new Date();
    var startTime = date.getFullYear() + "-01-01";// "年"
    return startTime;
}
export function endTime() {
    let date =new Date();
    var endTime = date.getFullYear()
        + "-"// "年"
        + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
            + (date.getMonth() + 1))
        + "-"// "月"
        + (date.getDate() < 10 ? "0" + date.getDate() : date
            .getDate());
    return endTime;
}
export function getLastWeek() {
   let currentDate= new Date();
   let millisecond= 1000 * 60 * 60 * 24;//一天的毫秒数
    //起止日期数组
    let startStop;
    startStop = new Array();
    //返回date是一周中的某一天
    let week = currentDate.getDay();
    //减去的天数
    let minusDay = week != 0 ? week - 1 : 6;
    //获得当前周的第一天
    let currentWeekDayOne = new Date(currentDate.getTime() - (millisecond * minusDay));
    //上周最后一天即本周开始的前一天
    let priorWeekLastDay = new Date(currentWeekDayOne.getTime() - millisecond);
    //上周的第一天
    let priorWeekFirstDay = new Date(priorWeekLastDay.getTime() - (millisecond * 6));

    startStop.push(formatterDate(priorWeekFirstDay));
    startStop.push(formatterDate(priorWeekLastDay));
    //返回
    return startStop;
}
export function getParenthesesStr(text) {
    let result = ''
    if (text=='')
        return result
    let regex = /\((.+?)\)/g;
    let options = text.match(regex)
    if (options!=='') {
        let option = options[0]
        if (option!=='') {
            result = option.substring(1, option.length - 1)
        }
    }
    return result
}
