mirror of
https://github.com/znc/znc.git
synced 2026-08-07 01:13:25 +02:00
Move TZ-related code to own place.
This commit is contained in:
@@ -155,7 +155,7 @@ public:
|
||||
CString GetCreatedTime(Csock* pSocket) {
|
||||
unsigned long long iStartTime = pSocket->GetStartTime();
|
||||
time_t iTime = iStartTime / 1000;
|
||||
return FormatTime("%Y-%m-%d %H:%M:%S", iTime);
|
||||
return CUtils::FormatTime(iTime, "%Y-%m-%d %H:%M:%S", m_pUser->GetTimezone());
|
||||
}
|
||||
|
||||
CString GetLocalHost(Csock* pSocket, bool bShowHosts) {
|
||||
@@ -241,19 +241,6 @@ public:
|
||||
virtual ~CListSockets() {
|
||||
}
|
||||
|
||||
CString FormatTime(const CString& sFormat, time_t tm = 0) const {
|
||||
char szTimestamp[1024];
|
||||
|
||||
if (tm == 0) {
|
||||
tm = time(NULL);
|
||||
}
|
||||
|
||||
setenv("TZ", m_pUser->GetTimezone().c_str(), 1);
|
||||
strftime(szTimestamp, sizeof(szTimestamp) / sizeof(char),
|
||||
sFormat.c_str(), localtime(&tm));
|
||||
|
||||
return szTimestamp;
|
||||
}
|
||||
};
|
||||
|
||||
MODULEDEFS(CListSockets, "List active sockets")
|
||||
|
||||
+3
-12
@@ -58,21 +58,15 @@ void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/
|
||||
{
|
||||
CString sPath;
|
||||
time_t curtime;
|
||||
tm* timeinfo;
|
||||
char buffer[1024];
|
||||
|
||||
time(&curtime);
|
||||
// Don't forget the user's timezone offset
|
||||
setenv("TZ", m_pUser->GetTimezone().c_str(), 1);
|
||||
timeinfo = localtime(&curtime);
|
||||
|
||||
// Generate file name
|
||||
if (!strftime(buffer, sizeof(buffer), m_sLogPath.c_str(), timeinfo))
|
||||
sPath = CUtils::FormatTime(curtime, m_sLogPath, m_pUser->GetTimezone());
|
||||
if (sPath.empty())
|
||||
{
|
||||
DEBUG("Could not format log path [" << sPath << "]");
|
||||
return;
|
||||
}
|
||||
sPath = buffer;
|
||||
|
||||
// $WINDOW has to be handled last, since it can contain %
|
||||
sPath.Replace("$NETWORK", (m_pNetwork ? m_pNetwork->GetName() : "znc"));
|
||||
@@ -92,10 +86,7 @@ void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/
|
||||
if (!CFile::Exists(sLogDir)) CDir::MakeDir(sLogDir);
|
||||
if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
|
||||
{
|
||||
snprintf(buffer, sizeof(buffer), "[%02d:%02d:%02d] ",
|
||||
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
|
||||
LogFile.Write(buffer + sLine + "\n");
|
||||
LogFile.Write(CUtils::FormatTime(curtime, "[%H:%M:%S] ", m_pUser->GetTimezone()) + sLine + "\n");
|
||||
} else
|
||||
DEBUG("Could not open log file [" << sPath << "]: " << strerror(errno));
|
||||
}
|
||||
|
||||
@@ -189,9 +189,7 @@ private:
|
||||
sReason = SIMPLE_AWAY_DEFAULT_REASON;
|
||||
|
||||
time_t iTime = time(NULL);
|
||||
setenv("TZ", m_pUser->GetTimezone().c_str(), 1);
|
||||
CString sTime = ctime(&iTime);
|
||||
sTime.Trim();
|
||||
CString sTime = CUtils::CTime(iTime, m_pUser->GetTimezone());
|
||||
sReason.Replace("%s", sTime);
|
||||
|
||||
return sReason;
|
||||
|
||||
Reference in New Issue
Block a user