diff --git a/README.md b/README.md index f6d472e9..44cde351 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The official config loader for [Tableau](https://github.com/tableauio/tableau). - C++17: `cmake -S . -B build` - C++20: `cmake -S . -B build -DCMAKE_CXX_STANDARD=20` - clang: `cmake -S . -B build -DCMAKE_CXX_COMPILER=clang++` -- Build: `cmake --build build --parallel 10` +- Build: `cmake --build build -j16` - Run: `./bin/loader` ### Dev at Windows @@ -36,7 +36,7 @@ The official config loader for [Tableau](https://github.com/tableauio/tableau). - CMake: - C++17: `cmake -S . -B build -G "NMake Makefiles"` - C++20: `cmake -S . -B build -G "NMake Makefiles" -DCMAKE_CXX_STANDARD=20` -- Build: `cmake --build build --parallel 10` +- Build: `cmake --build build` - Run: `.\bin\loader.exe` ### References diff --git a/cmd/protoc-gen-cpp-tableau-loader/embed/logger.pc.cc b/cmd/protoc-gen-cpp-tableau-loader/embed/logger.pc.cc index 4ecc2908..735ebb92 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/logger.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/logger.pc.cc @@ -96,10 +96,22 @@ void DefaultWrite(std::ostream* os, const SourceLocation& loc, const LevelInfo& std::ostream& operator<<(std::ostream& os, const Now&) { auto now = std::chrono::system_clock::now(); - auto now_time_t = std::chrono::system_clock::to_time_t(now); - auto now_us = std::chrono::duration_cast(now.time_since_epoch()) % 1000000; - return os << std::put_time(std::localtime(&now_time_t), "%F %T") << "." << std::setw(6) << std::setfill('0') - << now_us.count(); +#if __cplusplus >= 202002L + auto zt = std::chrono::zoned_time(std::chrono::current_zone(), std::chrono::floor(now)); + return os << std::format("{:%F %T}", zt); +#else + static thread_local std::tm tm; + auto now_t = std::chrono::system_clock::to_time_t(now); +#ifdef _WIN32 + localtime_s(&tm, &now_t); +#else + localtime_r(&now_t, &tm); +#endif + auto duration = now.time_since_epoch(); + auto secs = std::chrono::duration_cast(duration); + auto micros = std::chrono::duration_cast(duration - secs); + return os << std::put_time(&tm, "%F %T") << "." << std::setw(6) << std::setfill('0') << micros.count(); +#endif } } // namespace log diff --git a/init.bat b/init.bat index 6103990c..d97e1ab8 100644 --- a/init.bat +++ b/init.bat @@ -21,6 +21,6 @@ cmake -S . -B build ^ -DCMAKE_POLICY_VERSION_MINIMUM="3.5" REM Compile the code -cmake --build build --parallel 10 +cmake --build build endlocal diff --git a/init.sh b/init.sh index 092096f3..5e78d447 100755 --- a/init.sh +++ b/init.sh @@ -26,4 +26,4 @@ cmake -S . -B build \ -DCMAKE_BUILD_TYPE=Debug # Compile the code -cmake --build build --parallel 10 +cmake --build build -j16 diff --git a/test/cpp-tableau-loader/src/protoconf/logger.pc.cc b/test/cpp-tableau-loader/src/protoconf/logger.pc.cc index 747ce28d..ec80696f 100644 --- a/test/cpp-tableau-loader/src/protoconf/logger.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/logger.pc.cc @@ -101,10 +101,22 @@ void DefaultWrite(std::ostream* os, const SourceLocation& loc, const LevelInfo& std::ostream& operator<<(std::ostream& os, const Now&) { auto now = std::chrono::system_clock::now(); - auto now_time_t = std::chrono::system_clock::to_time_t(now); - auto now_us = std::chrono::duration_cast(now.time_since_epoch()) % 1000000; - return os << std::put_time(std::localtime(&now_time_t), "%F %T") << "." << std::setw(6) << std::setfill('0') - << now_us.count(); +#if __cplusplus >= 202002L + auto zt = std::chrono::zoned_time(std::chrono::current_zone(), std::chrono::floor(now)); + return os << std::format("{:%F %T}", zt); +#else + static thread_local std::tm tm; + auto now_t = std::chrono::system_clock::to_time_t(now); +#ifdef _WIN32 + localtime_s(&tm, &now_t); +#else + localtime_r(&now_t, &tm); +#endif + auto duration = now.time_since_epoch(); + auto secs = std::chrono::duration_cast(duration); + auto micros = std::chrono::duration_cast(duration - secs); + return os << std::put_time(&tm, "%F %T") << "." << std::setw(6) << std::setfill('0') << micros.count(); +#endif } } // namespace log