fixing timegm_with_gmtoff()

ENGINE-780-take2
Volker Birk 3 years ago
parent 534d1957bf
commit 72b0f89205

@ -548,6 +548,10 @@ timestamp * etpantime_to_timestamp(const struct mailimf_date_time *et)
result->tm_mon = et->dt_month - 1;
result->tm_year = et->dt_year - 1900;
result->tm_gmtoff = 36L * (long) et->dt_zone;
time_t t = timegm_with_gmtoff(result);
gmtime_r(&t, result);
return result;
}

@ -10,12 +10,21 @@
#include <assert.h>
DYNAMIC_API time_t timegm_with_gmtoff(timestamp* ts)
DYNAMIC_API time_t timegm_with_gmtoff(const timestamp* ts)
{
const time_t raw_time = timegm(ts);
if (!ts)
return -1;
timestamp *_ts = timestamp_dup(ts);
if (!_ts)
return -1;
const time_t raw_time = timegm(_ts);
if(raw_time==-1)
return -1;
free_timestamp(_ts);
return raw_time - ts->tm_gmtoff;
}
@ -44,11 +53,8 @@ DYNAMIC_API timestamp * timestamp_dup(const timestamp *src)
if (!src)
return NULL;
timestamp *dst = calloc(1, sizeof(timestamp));
assert(dst);
if (!dst)
return NULL;
timestamp *dst = (timestamp *) malloc(sizeof(timestamp));
memcpy(dst, src, sizeof(timestamp));
return dst;
}

@ -34,11 +34,11 @@ typedef struct tm timestamp;
// timegm_with_gmtoff() - convert the broken-out time into time_t, and respect tm_gmtoff
//
// parameters:
// timeptr(inout) broken-out time; members will be "normalized" by this function.
// timeptr(in) broken-out time
//
// return value:
// time_t that holds the usual "seconds since epoch"
DYNAMIC_API time_t timegm_with_gmtoff(timestamp* ts);
DYNAMIC_API time_t timegm_with_gmtoff(const timestamp* ts);
// new_timestamp() - allocate a new timestamp

Loading…
Cancel
Save