فهرست منبع

Add support for localtime

Sam Jaffe 6 سال پیش
والد
کامیت
82eeffe007
1فایلهای تغییر یافته به همراه6 افزوده شده و 1 حذف شده
  1. 6 1
      src/format.cxx

+ 6 - 1
src/format.cxx

@@ -30,7 +30,12 @@ namespace logging {
   namespace {
     std::string fmt_time(struct timeval round, char const * const fmt) {
       struct tm time;
-      gmtime_r(&round.tv_sec, &time);
+      // Supports localtime when requested, but you can't really test that
+      if (strstr(fmt, "%z") || strstr(fmt, "%Z")) {
+        localtime_r(&round.tv_sec, &time);
+      } else {
+        gmtime_r(&round.tv_sec, &time);
+      }
       char buf[64] = {'\0'};
       std::strftime(buf, sizeof(buf), fmt, &time);
       return buf;