/**
 * @since Last modified: 2023-11-15 13:09:19
 * @function getExpireDate
 * @param {'s'|'m'|'h'|'d'} [type=d] - The date unit that calculates the expiration time.The optional value is 's'(second) | 'm'(minute) | 'h'(hour) | 'd'(day,default).
 * @paran {number | string} [expires=365] - The value of The date unit.The default value is 365.
 * @description Get the expiration time.
 * @returns {string} Return a UTC date(e.g. 'Wed, 15 Nov 2023 02:52:40 GMT').
 * @see {@link https://codepen.io/axui/pen/bGzoYQz|demo @ codepen}
 * @example
 * ax.getExpireDate('h',10);
 * <!-- return true -->
 */
'use strict';
import isDateStr from './isDateStr';
const getExpireDate = (type: 's' | 'm' | 'h' | 'd'  = 'd', expires: number | string = 365): string => {
    let dateExp: any;
    if (isDateStr(expires)) {
        dateExp = new Date(expires).toUTCString();
    } else {
        let now = new Date();
        switch (type) {
            case 's':
                now.setSeconds(now.getSeconds() + ~~expires);
                dateExp = now.toUTCString();
                break;
            case 'm':
                now.setMinutes(now.getMinutes() + ~~expires);
                dateExp = now.toUTCString();
                break;
            case 'h':
                now.setHours(now.getHours() + ~~expires);
                dateExp = now.toUTCString();
                break;
            default:
                now.setDate(now.getDate() + ~~expires);
                dateExp = now.toUTCString();
        }
    }
    return dateExp;
}
export default getExpireDate;
getExpireDate('d', 60);
