diff --git a/modules/alarm/alarm.cpp b/modules/alarm/alarm.cpp index 1f634cb733ae2c0e50fc38bd9b154ada85e41cf0..cb777537ca5d04d81ae473a477709850ac55839d 100644 --- a/modules/alarm/alarm.cpp +++ b/modules/alarm/alarm.cpp @@ -106,6 +106,28 @@ uint32_t Alarm::remainSeconds() const { namespace { //! 获取系统的时区偏移秒数 int GetSystemTimezoneOffsetSeconds() { +#if defined(__MINGW32__) || defined(_MSC_VER) || defined(_WIN32) +#if defined(__MINGW32__) && !__has_include(<_mingw_stat64.h>) + LogErr("can't get timezone offset, not support."); + return 0; +#else + long tm_gmtoff = 0; +#if (defined(_MSC_VER) || defined(_UCRT)) && !defined(__BIONIC__) + { + errno_t errn = _get_timezone(&tm_gmtoff); + if (errn != 0) { + LogErr("_get_timezone() error:%d", errn); + return 0; + } + } +#elif defined(_WIN32) && !defined(__BIONIC__) && !defined(__WINE__) && !defined(__CYGWIN__) + tm_gmtoff = _timezone; +#else + tm_gmtoff = timezone; +#endif + return static_cast(tm_gmtoff); +#endif +#else //! 假设当前0时区的时间是 1970-1-1 12:00,即 utc_ts = 12 * 3600 //! 通过 localtime_r() 获取本地的时间 local_tm。 //! 通过 local_tm 中的 hour, min, sec 可计算出本地的时间戳 local_ts。 @@ -118,6 +140,7 @@ int GetSystemTimezoneOffsetSeconds() { localtime_r(&utc_ts, &local_tm); int local_ts = local_tm.tm_hour * 3600 + local_tm.tm_min * 60 + local_tm.tm_sec; return (local_ts - static_cast(utc_ts)); +#endif } }