/**
 * @since Last modified: 2023-12-22 11:10:44
 * @function toLocalTime
 * @description Flat the nested function.Run function from left to right.
 * @param {array} args - The array of functions.
 * @returns  {function} - The flat function(the last function).
 * @see {@link https://codepen.io/axui/pen/vYbMgOb|demo @ codepen}
 * @example
 * ax.pipe(fn1,fn2,fn3)(val);
 * <!--The same as : fn3(fn2(fn1(val)))-->
 * <!--ax.pipe(fn1,fn2,fn3) will return the fn3-->
 */
'use strict';
const toLocalTime = (date, utc) => {
    let dateStr, localDate, flag, loacalTime, localOffset = 0;
    if (date) {
        date = date.trim();
        localDate = new Date(date);
        flag = localDate instanceof Date && !isNaN(localDate.getTime());
        if (!flag) {
            throw new Error('Date format must be "YYYY-MM-DD" or "YYYY/MM/DD"!');
        }
        dateStr = date.replace(/-/g, "/");
        loacalTime = new Date(dateStr).getTime();
        !dateStr.includes(':') ? localOffset = new Date(dateStr).getTimezoneOffset() * 60000 : null;
    }
    else {
        loacalTime = new Date().getTime();
    }
    return utc ? (loacalTime - localOffset) : loacalTime;
};
export default toLocalTime;
