#pragma once

namespace DUBBING
{
    uint64_t getCurTime()
    {
        auto now = std::chrono::system_clock::now();
        auto itt = std::chrono::system_clock::to_time_t(now);
        auto ittms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
        // get mill second count
        uint64_t milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(ittms.time_since_epoch()).count();
        return milliseconds;
    }

    std::string wstring2utf8string(const std::wstring& wstrText)
    {
        std::string strConvert;
        try
        {
            static std::wstring_convert<std::codecvt_utf8<wchar_t>> strCnv;
            strConvert = strCnv.to_bytes(wstrText);
        }
        catch (const std::range_error& e)
        {
            std::cout << "catch range_error: " << e.what() << std::endl;
        }
        catch (const std::exception& e)
        {
            std::cout << "catch other exception: " << e.what() << std::endl;
        }
        return strConvert;
    }

    std::wstring utf8string2wstring(const std::string& strUtf8)
    {
        std::wstring strConvert;
        static std::wstring_convert<std::codecvt_utf8<wchar_t>> strCnv;
        try
        {
            strConvert = strCnv.from_bytes(strUtf8);
        }
        catch (const std::range_error& e)
        {
            std::cout << "catch range_error: " << e.what() << std::endl;
        }
        catch (const std::exception& e)
        {
            std::cout << "catch other exception: " << e.what() << std::endl;
        }
        return strConvert;
    }
}

