import dayjs from 'dayjs';

export const datetimeStr = (date) =>{
    
    return dateFormat(date,"DD-MM-YYYY HH:mm:ss")
};

export const dateStr = (date) =>{
    return dateFormat(date,"YYYY-MM-DD")
};

export const datetimeStr_Cht = (date) =>{ 
    return dateFormat(date,"YYYY年MM月DD日 HH:mm:ss")
};

export const dateStr_Cht = (date) =>{
    return dateFormat(date,"YYYY年MM月DD日")
};

export const datetimeFieldFormat = (date) =>{
    return dateFormat(date,"YYYY-MM-DDTHH:mm");
};

export const convertToDate = (date)=>{
    if(typeof date == 'number'){
        return dayjs(date).toDate();
    }else if(Array.isArray(date)){
        // if(date.length==3){
        //     return new Date(date[0],date[1]-1,date[2],0,0,0);
        // }else if(date.length==4){
        //     return new Date(date[0],date[1]-1,date[2],0,0,0);
        // }
        return new Date(date[0]
            ,date[1]-1
            ,date[2]
            ,date.length>=4?date[3]:0
            ,date.length>=5?date[4]:0
            ,date.length>=6?date[5]:0);
    }else if(typeof date == "string"){
        return new Date(date);
    }
    
    return date;
}

export const dateFormat = (date, format) =>{
    date = convertToDate(date);
    return dayjs(date).format(format);
};
