martinzink commented on code in PR #1560: URL: https://github.com/apache/nifi-minifi-cpp/pull/1560#discussion_r1169706602
########## libminifi/src/utils/file/FileUtils.cpp: ########## @@ -74,13 +74,23 @@ time_t to_time_t(std::filesystem::file_time_type file_time) { #endif } -std::chrono::time_point<std::chrono::system_clock> to_sys(std::filesystem::file_time_type file_time) { -#if defined(WIN32) || defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 14000 - return std::chrono::time_point_cast<std::chrono::system_clock::duration>(file_time - std::filesystem::file_time_type::clock::now() + std::chrono::system_clock::now()); -#elif defined(_LIBCPP_VERSION) +std::chrono::system_clock::time_point to_sys(std::filesystem::file_time_type file_time) { +#if defined(WIN32) + return std::chrono::clock_cast<std::chrono::system_clock>(file_time); +#elif defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION < 14000) return std::chrono::system_clock::from_time_t(std::chrono::file_clock::to_time_t(file_time)); #else - return std::chrono::file_clock::to_sys(file_time); + return std::chrono::time_point_cast<std::chrono::system_clock::duration>(std::chrono::file_clock::to_sys(file_time)); +#endif +} + +std::filesystem::file_time_type from_sys(std::chrono::system_clock::time_point sys_time) { +#if defined(WIN32) + return std::chrono::clock_cast<std::chrono::file_clock>(sys_time); +#elif defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION < 14000) + return std::chrono::file_clock::from_time_t(std::chrono::system_clock::to_time_t(sys_time)); +#else + return std::chrono::file_clock::from_sys(sys_time); Review Comment: You only need to cast it where it can lose precision otherwise the cast is implicit. So from hours to minutes you dont need duration_cast while you would need in the other direction. Of course we could add the explicit cast to other function aswell, if we expect that on some platfrom system_clock will be more precise than file_clock (or simply to improve readability) What do you think? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org