Browse Source

add timegm_with_gmtoff()

test-README.md
Roker 2 years ago
parent
commit
75b70d0094
2 changed files with 22 additions and 0 deletions
  1. +11
    -0
      src/timestamp.c
  2. +11
    -0
      src/timestamp.h

+ 11
- 0
src/timestamp.c View File

@ -9,6 +9,17 @@
#include <string.h>
#include <assert.h>
DYNAMIC_API time_t timegm_with_gmtoff(timestamp* ts)
{
const time_t raw_time = timegm(ts);
if(raw_time==-1)
return -1;
return raw_time - ts->tm_gmtoff;
}
DYNAMIC_API timestamp * new_timestamp(time_t clock)
{
timestamp *ts = calloc(1, sizeof(timestamp));


+ 11
- 0
src/timestamp.h View File

@ -30,6 +30,17 @@ typedef struct _timestamp {
typedef struct tm timestamp;
#endif
// 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.
//
// return value:
// time_t that holds the usual "seconds since epoch"
DYNAMIC_API time_t timegm_with_gmtoff(timestamp* ts);
// new_timestamp() - allocate a new timestamp
//
// parameters:


Loading…
Cancel
Save