Browse Source

fixing timegm_with_gmtoff()

test-README.md
Volker Birk 2 years ago
parent
commit
72b0f89205
3 changed files with 20 additions and 10 deletions
  1. +4
    -0
      src/etpan_mime.c
  2. +14
    -8
      src/timestamp.c
  3. +2
    -2
      src/timestamp.h

+ 4
- 0
src/etpan_mime.c View File

@ -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;
}


+ 14
- 8
src/timestamp.c View File

@ -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;
}

+ 2
- 2
src/timestamp.h View File

@ -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