diff --git a/src/ai_platform/mvpt.cpp b/src/ai_platform/mvpt.cpp index a176cb5..7274cb2 100755 --- a/src/ai_platform/mvpt.cpp +++ b/src/ai_platform/mvpt.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "../decoder/interface/DecoderManager.h" #include "../decoder/interface/utiltools.hpp" @@ -615,17 +616,13 @@ bool CMultiSourceProcess::save_obj_pic(ObjectInfo& res_obj) } bool CMultiSourceProcess::CheckTime() { - struct tm* info; - int nYear, nMonth, nDay; - time_t raw; - time(&raw); - info = localtime(&raw); - nYear = info->tm_year + 1900; - nMonth = info->tm_mon + 1; - nDay = info->tm_mday; - if (nYear == 2026 && nMonth <= 3) + + long long deadline_ts = helpers::timer::get_ts_by_day_ms(2026, 4, 1); + long long cur_ts = helpers::timer::get_cur_time_ms(); + + if (cur_ts < deadline_ts) { - return true; + return true; } else { diff --git a/src/helpers/time_helper.hpp b/src/helpers/time_helper.hpp index 8cbea66..aa8b47f 100755 --- a/src/helpers/time_helper.hpp +++ b/src/helpers/time_helper.hpp @@ -17,6 +17,8 @@ #include #include #include +#include + using namespace std; @@ -57,6 +59,31 @@ namespace helpers return std::string(buf); } + static long long get_ts_by_day_ms(int year, int month, int day) + { + // 初始化tm结构体 + std::tm t = {}; + t.tm_year = year - 1900; // 年从1900年开始计数 + t.tm_mon = month - 1; // 月份从0开始计数,3月是第4个月 + t.tm_mday = day; // 日 + t.tm_hour = 0; // 小时 + t.tm_min = 0; // 分钟 + t.tm_sec = 0; // 秒 + + // 使用mktime转换为time_t(如果需要) + std::time_t timestamp = std::mktime(&t); // 或者直接使用下面的chrono方法跳过这一步 + if (timestamp == -1) { + return -1; // 或者抛出异常等错误处理方式 + } + + // 使用chrono转换(如果不需要先转换为time_t) + auto timepoint = std::chrono::system_clock::from_time_t(timestamp); + auto duration = timepoint.time_since_epoch(); + auto ms = std::chrono::duration_cast(duration).count(); + + return ms; + } + } // namespace timer } // namespace helpers diff --git a/src/util/util_tools.cpp b/src/util/util_tools.cpp deleted file mode 100755 index e3d1265..0000000 --- a/src/util/util_tools.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "util_tools.h" - -using namespace std; - -namespace UtilTools{ - long long get_cur_time_ms(){ - chrono::time_point tpMicro - = chrono::time_point_cast(chrono::system_clock::now()); - - return tpMicro.time_since_epoch().count(); - } -} \ No newline at end of file diff --git a/src/util/util_tools.h b/src/util/util_tools.h deleted file mode 100755 index af80ae7..0000000 --- a/src/util/util_tools.h +++ /dev/null @@ -1,6 +0,0 @@ -#include - - -namespace UtilTools{ - long long get_cur_time_ms(); -}