Commit ec400bfe authored by Mickaël Turnel's avatar Mickaël Turnel Committed by Ghislain MARY

Adapted tm to time_t and time_t to tm conversions for windows

parent b687bf9d
......@@ -27,6 +27,10 @@
#include "linphone/utils/utils.h"
#include "logger/logger.h"
#include "private.h"
// =============================================================================
using namespace std;
......@@ -184,12 +188,42 @@ string Utils::trim (const string &str) {
// -----------------------------------------------------------------------------
tm Utils::getTimeTAsTm (time_t time) {
tm result;
return *gmtime_r(&time, &result);
#ifndef _WIN32
tm result;
return *gmtime_r(&time, &result);
#else
return *gmtime(&time);
#endif
}
time_t Utils::getTmAsTimeT (const tm &time) {
return timegm(&const_cast<tm &>(time));
time_t result;
#if defined(LINPHONE_WINDOWS_UNIVERSAL) || defined(LINPHONE_MSC_VER_GREATER_19)
long adjust_timezone;
#else
time_t adjust_timezone;
#endif
#if TARGET_IPHONE_SIMULATOR
result = timegm(&const_cast<tm &>(time));
adjust_timezone = 0;
#else
result = mktime(&const_cast<tm &>(time));
#if defined(LINPHONE_WINDOWS_UNIVERSAL) || defined(LINPHONE_MSC_VER_GREATER_19)
_get_timezone(&adjust_timezone);
#else
adjust_timezone = timezone;
#endif
#endif
if (result == (time_t)-1) {
lError() << "mktime failed: " << strerror(errno);
return (time_t)-1;
}
return result - (time_t)adjust_timezone;
}
// -----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment