/**
 * @since Last modified: 2024-09-10 09:46:00
 * @function toLocalTime
 * @description Datetime string are converted to local timestamp for easy comparison..
 * @param {string} date - The date string,e.g. 2022-2-23,2023/2,2022,2023/5/12 12:23.
 * @returns  {function} - The timestamp.
 * @see {@link https://codepen.io/axui/pen/vYPYyzN|demo @ codepen}
 * @example
 * ax.toLocalTime('2021-1-12');
 * <!--Return 1610380800000-->
 */
'use strict';
const toLocalTime = (date) => {
    let dateStr, localDate, flag, loacalTime;
    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();
    }
    else {
        loacalTime = Date.now();
    }
    return loacalTime;
};
export default toLocalTime;
