From eca0211bb8da0ae3bff1de4acce7149f96100061 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sun, 9 Oct 2011 16:51:19 +0200 Subject: [PATCH] Use time zone string instead of offset. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is done by setting the TZ variable prior to calling localtime() or ctime(). There are a few calls to ctime()/localtime() which doesn’t adjust for time zone offset. This patch affects the behavior of these since the TZ variable is global. --- modules/extra/listsockets.cpp | 3 +-- modules/log.cpp | 4 ++-- modules/simple_away.cpp | 2 +- src/User.cpp | 6 +++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/extra/listsockets.cpp b/modules/extra/listsockets.cpp index c45c8255..625c6ccd 100644 --- a/modules/extra/listsockets.cpp +++ b/modules/extra/listsockets.cpp @@ -248,8 +248,7 @@ public: tm = time(NULL); } - // offset is in hours - tm += (time_t)(m_pUser->GetTimezoneOffset() * 60 * 60); + setenv("TZ", m_pUser->GetTimezone().c_str(), 1); strftime(szTimestamp, sizeof(szTimestamp) / sizeof(char), sFormat.c_str(), localtime(&tm)); diff --git a/modules/log.cpp b/modules/log.cpp index 20065dde..73061484 100644 --- a/modules/log.cpp +++ b/modules/log.cpp @@ -62,8 +62,8 @@ void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/ char buffer[1024]; time(&curtime); - // Don't forget the user's timezone offset (which is in hours and we want seconds) - curtime += (time_t) (m_pUser->GetTimezoneOffset() * 60 * 60); + // Don't forget the user's timezone offset + setenv("TZ", m_pUser->GetTimezone().c_str(), 1); timeinfo = localtime(&curtime); // Generate file name diff --git a/modules/simple_away.cpp b/modules/simple_away.cpp index bb695c8f..a49447fc 100644 --- a/modules/simple_away.cpp +++ b/modules/simple_away.cpp @@ -189,7 +189,7 @@ private: sReason = SIMPLE_AWAY_DEFAULT_REASON; time_t iTime = time(NULL); - iTime += (time_t)(m_pUser->GetTimezoneOffset() * 60 * 60); // offset is in hours + setenv("TZ", m_pUser->GetTimezone().c_str(), 1); CString sTime = ctime(&iTime); sTime.Trim(); sReason.Replace("%s", sTime); diff --git a/src/User.cpp b/src/User.cpp index 3852db44..e03460f3 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -500,8 +500,8 @@ CString CUser::ExpandString(const CString& sStr) const { } CString& CUser::ExpandString(const CString& sStr, CString& sRet) const { - // offset is in hours, so * 60 * 60 gets us seconds - time_t iUserTime = time(NULL) + (time_t)(m_fTimezoneOffset * 60 * 60); + time_t iUserTime = time(NULL); + setenv("TZ", m_sTimezone.c_str(), 1); char *szTime = ctime(&iUserTime); CString sTime; @@ -543,7 +543,7 @@ CString& CUser::AddTimestamp(const CString& sStr, CString& sRet) const { if (!GetTimestampFormat().empty() && (m_bAppendTimestamp || m_bPrependTimestamp)) { time(&tm); - tm += (time_t)(m_fTimezoneOffset * 60 * 60); // offset is in hours + setenv("TZ", m_sTimezone.c_str(), 1); size_t i = strftime(szTimestamp, sizeof(szTimestamp), GetTimestampFormat().c_str(), localtime(&tm)); // If strftime returns 0, an error occured in format, or result is empty // In both cases just don't prepend/append anything to our string