text stringlengths 0 357 |
|---|
(int)wanted_struct.tm_mday, (int)wanted_struct.tm_mon+1, (int)wanted_struct.tm_year+1900, |
(int)wanted_struct.tm_hour, (int)wanted_struct.tm_min, (int)wanted_struct.tm_sec); |
} |
struct mailimap_date_time* dc_timestamp_to_mailimap_date_time(time_t timeval) |
{ |
struct tm gmt; |
struct tm lt; |
int off = 0; |
struct mailimap_date_time* date_time; |
int sign = 0; |
int hour = 0; |
int min = 0; |
gmtime_r(&timeval, &gmt); |
localtime_r(&timeval, <); |
off = (int) ((mkgmtime(<) - mkgmtime(&gmt)) / 60); |
if (off < 0) { |
sign = -1; |
} |
else { |
sign = 1; |
} |
off = off * sign; |
min = off % 60; |
hour = off / 60; |
off = hour * 100 + min; |
off = off * sign; |
date_time = mailimap_date_time_new(lt.tm_mday, lt.tm_mon + 1, |
lt.tm_year + 1900, |
lt.tm_hour, lt.tm_min, lt.tm_sec, |
off); |
return date_time; |
} |
/******************************************************************************* |
* Time smearing |
******************************************************************************/ |
#define DC_MAX_SECONDS_TO_LEND_FROM_FUTURE 5 |
#define SMEAR_LOCK { pthread_mutex_lock(&context->smear_critical); } |
#define SMEAR_UNLOCK { pthread_mutex_unlock(&context->smear_critical); } |
time_t dc_create_smeared_timestamp(dc_context_t* context) |
{ |
time_t now = time(NULL); |
time_t ret = now; |
SMEAR_LOCK |
if (ret <= context->last_smeared_timestamp) { |
ret = context->last_smeared_timestamp+1; |
if ((ret-now) > DC_MAX_SECONDS_TO_LEND_FROM_FUTURE) { |
ret = now + DC_MAX_SECONDS_TO_LEND_FROM_FUTURE; |
} |
} |
context->last_smeared_timestamp = ret; |
SMEAR_UNLOCK |
return ret; |
} |
time_t dc_create_smeared_timestamps(dc_context_t* context, int count) |
{ |
/* get a range to timestamps that can be used uniquely */ |
time_t now = time(NULL); |
time_t start = now + DC_MIN(count, DC_MAX_SECONDS_TO_LEND_FROM_FUTURE) - count; |
SMEAR_LOCK |
start = DC_MAX(context->last_smeared_timestamp+1, start); |
context->last_smeared_timestamp = start+(count-1); |
SMEAR_UNLOCK |
return start; |
} |
time_t dc_smeared_time(dc_context_t* context) |
{ |
/* function returns a corrected time(NULL) */ |
time_t now = time(NULL); |
SMEAR_LOCK |
if (context->last_smeared_timestamp >= now) { |
now = context->last_smeared_timestamp+1; |
} |
SMEAR_UNLOCK |
return now; |
} |
/******************************************************************************* |
* generate Message-IDs |
******************************************************************************/ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.