mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-02 11:19:30 +00:00
Adapted tm to time_t and time_t to tm conversions for windows
This commit is contained in:
parent
b687bf9d68
commit
ec400bfe4a
1 changed files with 37 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue