riku
2026-04-02 3282e95db0207ee133d1e98d9771dec9d83b0fc4
miniprogram_npm/tdesign-miniprogram/common/shared/date.js
@@ -1,41 +1 @@
export const getDateRect = (date) => {
    const _date = new Date(date);
    return {
        year: _date.getFullYear(),
        month: _date.getMonth(),
        date: _date.getDate(),
        day: _date.getDay(),
        time: _date.getTime(),
    };
};
export const isSameDate = (date1, date2) => {
    if (date1 instanceof Date || typeof date1 === 'number')
        date1 = getDateRect(date1);
    if (date2 instanceof Date || typeof date2 === 'number')
        date2 = getDateRect(date2);
    const keys = ['year', 'month', 'date'];
    return keys.every((key) => date1[key] === date2[key]);
};
export const getMonthDateRect = (date) => {
    const { year, month } = getDateRect(date);
    const firstDay = new Date(year, month, 1);
    const weekdayOfFirstDay = firstDay.getDay();
    const lastDate = new Date(+new Date(year, month + 1, 1) - 24 * 3600 * 1000).getDate();
    return {
        year,
        month,
        weekdayOfFirstDay,
        lastDate,
    };
};
export const isValidDate = (val) => typeof val === 'number' || val instanceof Date;
export const getDate = (...args) => {
    const now = new Date();
    if (args.length === 0)
        return now;
    if (args.length === 1 && args[0] <= 1000) {
        const { year, month, date } = getDateRect(now);
        return new Date(year, month + args[0], date);
    }
    return Date.apply(null, args);
};
export const getDateRect=e=>{const t=new Date(e);return{year:t.getFullYear(),month:t.getMonth(),date:t.getDate(),day:t.getDay(),time:t.getTime()}};export const isSameDate=(e,t)=>{(e instanceof Date||"number"==typeof e)&&(e=getDateRect(e)),(t instanceof Date||"number"==typeof t)&&(t=getDateRect(t));return["year","month","date"].every(a=>e[a]===t[a])};export const getMonthDateRect=e=>{const{year:t,month:a}=getDateRect(e);return{year:t,month:a,weekdayOfFirstDay:new Date(t,a,1).getDay(),lastDate:new Date(+new Date(t,a+1,1)-864e5).getDate()}};export const isValidDate=e=>"number"==typeof e||e instanceof Date;export const getDate=(...e)=>{const t=new Date;if(0===e.length)return t;if(1===e.length&&e[0]<=1e3){const{year:a,month:n,date:r}=getDateRect(t);return new Date(a,n+e[0],r)}return Date.apply(null,e)};