const date = {
    dateformat(t, islong = false, splitChar = '-') {
        if (typeof t == 'string')
            t = t.replaceAll('-', '/').substring(0, 19);
        const dt = new Date(t);
        const m = dt.getMonth() + 1;
        const d = dt.getDate();
        const h = dt.getHours();
        const mm = dt.getMinutes();
        const s = dt.getSeconds();
        let res = dt.getFullYear() + splitChar + (m < 10 ? '0' + m : m) + splitChar + (d < 10 ? '0' + d : d);
        if (islong) {
            res += islong ? ' ' + (h < 10 ? '0' + h : h) + ':' + (mm < 10 ? '0' + mm : mm) + ':' + (s < 10 ? '0' + s : s) : '';
        }
        return res;
    },
    getNow(islong = false, splitChar = '-') {
        var t = new Date();
        return this.dateformat(t, islong, splitChar);
    },
    getTS() {
        return new Date() - 0;
    },
    dtShortcuts: [
        {
            text: "今天",
            value: () => {
                const date = new Date();
                date.setTime(date.getTime() - 0);
                return date;
            },
        },
        {
            text: "昨天",
            value: () => {
                const date = new Date();
                date.setTime(date.getTime() - 3600 * 1000 * 24);
                return date;
            },
        },
        {
            text: "一周前",
            value: () => {
                const date = new Date();
                date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                return date;
            },
        },
        {
            text: "一月前",
            value: () => {
                const date = new Date();
                date.setTime(date.getTime() - 3600 * 1000 * 24 * 30);
                return date;
            },
        },
    ],
    dtRangeShortcuts: [
        {
            text: "今天",
            value: () => {
                const st = new Date(new Date().setHours(0, 0, 0, 0));
                const ed = new Date(new Date().setHours(23, 59, 59, 999));
                return [st, ed];
            },
        },
        {
            text: "昨天",
            value: () => {
                const st = new Date();
                const ed = new Date();
                st.setTime((new Date(st.getTime() - 3600 * 1000 * 24)).setHours(0, 0, 0, 0));
                ed.setTime((new Date(ed.getTime() - 3600 * 1000 * 24)).setHours(23, 59, 59, 999));
                return [st, ed];
            },
        },
        {
            text: "一周前",
            value: () => {
                const st = new Date();
                const ed = new Date(new Date().setHours(23, 59, 59, 999));
                st.setTime((new Date(st.getTime() - 3600 * 1000 * 24 * 7).setHours(0, 0, 0, 0)));
                return [st, ed];
            },
        },
        {
            text: "一月前",
            value: () => {
                const st = new Date();
                const ed = new Date(new Date().setHours(23, 59, 59, 999));
                st.setTime((new Date(st.getTime() - 3600 * 1000 * 24 * 30).setHours(0, 0, 0, 0)));
                return [st, ed];
            },
        },
    ],
    getMonth_C() {
        const m = new Date().getMonth();
        return ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'][m];
    },
}

export default date;