Antropovi commented on code in PR #47017:
URL: https://github.com/apache/arrow/pull/47017#discussion_r2231029520


##########
cpp/src/arrow/flight/sql/odbc/odbcabstraction/calendar_utils.cc:
##########
@@ -39,13 +41,30 @@ int64_t GetTodayTimeFromEpoch() {
 #endif
 }
 
-void GetTimeForSecondsSinceEpoch(tm& date, int64_t value) {
-#if defined(_WIN32)
-  gmtime_s(&date, &value);
-#else
-  time_t time_value = static_cast<time_t>(value);
-  gmtime_r(&time_value, &date);
-#endif
+void GetTimeForSecondsSinceEpoch(std::tm& out_tm, int64_t seconds_since_epoch) 
{
+  try {
+    std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> 
timepoint{
+        std::chrono::seconds{seconds_since_epoch}};
+
+    std::chrono::year_month_day ymd = 
std::chrono::floor<std::chrono::days>(timepoint);
+
+    std::chrono::hh_mm_ss<std::chrono::seconds> timeofday{
+        timepoint - std::chrono::floor<std::chrono::days>(timepoint)};
+
+    std::memset(&out_tm, 0, sizeof(std::tm));
+
+    out_tm.tm_year = static_cast<int>(ymd.year()) - 1900;
+    out_tm.tm_mon = static_cast<unsigned>(ymd.month()) - 1;

Review Comment:
   tm_mon yes, bit ymd.month() has only unsigned operator. I can add here 
static_cast<int>(static_cast<unsigned>(...)) if you want.
    https://en.cppreference.com/w/cpp/chrono/month/operator_unsigned.html



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to