Tor  0.4.7.0-alpha-dev
Macros | Functions
time_fmt.h File Reference

Header for time_fmt.c. More...

#include "orconfig.h"

Go to the source code of this file.

Macros

#define RFC1123_TIME_LEN   29
 
#define ISO_TIME_LEN   19
 
#define ISO_TIME_USEC_LEN   (ISO_TIME_LEN+7)
 

Functions

struct tm * tor_localtime_r (const time_t *timep, struct tm *result)
 
struct tm * tor_gmtime_r (const time_t *timep, struct tm *result)
 
int tor_timegm (const struct tm *tm, time_t *time_out)
 
void format_rfc1123_time (char *buf, time_t t)
 
int parse_rfc1123_time (const char *buf, time_t *t)
 
void format_local_iso_time (char *buf, time_t t)
 
void format_iso_time (char *buf, time_t t)
 
void format_local_iso_time_nospace (char *buf, time_t t)
 
void format_iso_time_nospace (char *buf, time_t t)
 
void format_iso_time_nospace_usec (char *buf, const struct timeval *tv)
 
int parse_iso_time_ (const char *cp, time_t *t, int strict, int nospace)
 
int parse_iso_time (const char *buf, time_t *t)
 
int parse_iso_time_nospace (const char *cp, time_t *t)
 
int parse_http_time (const char *buf, struct tm *tm)
 
int format_time_interval (char *out, size_t out_len, long interval)
 

Detailed Description

Header for time_fmt.c.

Definition in file time_fmt.h.

Function Documentation

◆ format_iso_time()

void format_iso_time ( char *  buf,
time_t  t 
)

Set buf to the ISO8601 encoding of the GMT value of t. The buffer must be at least ISO_TIME_LEN+1 bytes long.

Definition at line 295 of file time_fmt.c.

Referenced by format_iso_time_nospace().

◆ format_iso_time_nospace()

void format_iso_time_nospace ( char *  buf,
time_t  t 
)

As format_iso_time, but use the yyyy-mm-ddThh:mm:ss format to avoid embedding an internal space.

Definition at line 313 of file time_fmt.c.

Referenced by format_iso_time_nospace_usec().

◆ format_iso_time_nospace_usec()

void format_iso_time_nospace_usec ( char *  buf,
const struct timeval tv 
)

As format_iso_time_nospace, but include microseconds in decimal fixed-point format. Requires that buf be at least ISO_TIME_USEC_LEN+1 bytes long.

Definition at line 323 of file time_fmt.c.

◆ format_local_iso_time()

void format_local_iso_time ( char *  buf,
time_t  t 
)

Set buf to the ISO8601 encoding of the local value of t. The buffer must be at least ISO_TIME_LEN+1 bytes long.

(ISO8601 format is 2006-10-29 10:57:20)

Definition at line 285 of file time_fmt.c.

Referenced by format_local_iso_time_nospace().

◆ format_local_iso_time_nospace()

void format_local_iso_time_nospace ( char *  buf,
time_t  t 
)

As format_local_iso_time, but use the yyyy-mm-ddThh:mm:ss format to avoid embedding an internal space.

Definition at line 304 of file time_fmt.c.

◆ format_rfc1123_time()

void format_rfc1123_time ( char *  buf,
time_t  t 
)

Set buf to the RFC1123 encoding of the UTC value of t. The buffer must be at least RFC1123_TIME_LEN+1 bytes long.

(RFC1123 format is "Fri, 29 Sep 2006 15:54:20 GMT". Note the "GMT" rather than "UTC".)

Definition at line 182 of file time_fmt.c.

◆ format_time_interval()

int format_time_interval ( char *  out,
size_t  out_len,
long  interval 
)

Given an interval in seconds, try to write it to the out_len-byte buffer in out in a human-readable form. Returns a non-negative integer on success, -1 on failure.

Definition at line 481 of file time_fmt.c.

Referenced by clock_skew_warning().

◆ parse_http_time()

int parse_http_time ( const char *  date,
struct tm *  tm 
)

Given a date in one of the three formats allowed by HTTP (ugh), parse it into tm. Return 0 on success, negative on failure.

Definition at line 409 of file time_fmt.c.

◆ parse_iso_time()

int parse_iso_time ( const char *  cp,
time_t *  t 
)

Given an ISO-formatted UTC time value (after the epoch) in cp, parse it and store its value in *t. Return 0 on success, -1 on failure. Reject the string if any characters are present after the time.

Definition at line 392 of file time_fmt.c.

◆ parse_iso_time_()

int parse_iso_time_ ( const char *  cp,
time_t *  t,
int  strict,
int  nospace 
)

Given an ISO-formatted UTC time value (after the epoch) in cp, parse it and store its value in *t. Return 0 on success, -1 on failure. Ignore extraneous stuff in cp after the end of the time string, unless strict is set. If nospace is set, expect the YYYY-MM-DDTHH:MM:SS format.

Definition at line 336 of file time_fmt.c.

Referenced by parse_iso_time(), and parse_iso_time_nospace().

◆ parse_iso_time_nospace()

int parse_iso_time_nospace ( const char *  cp,
time_t *  t 
)

As parse_iso_time, but parses a time encoded by format_iso_time_nospace().

Definition at line 401 of file time_fmt.c.

◆ parse_rfc1123_time()

int parse_rfc1123_time ( const char *  buf,
time_t *  t 
)

Parse the (a subset of) the RFC1123 encoding of some time (in UTC) from buf, and store the result in *t.

Note that we only accept the subset generated by format_rfc1123_time above, not the full range of formats suggested by RFC 1123.

Return 0 on success, -1 on failure.

Definition at line 206 of file time_fmt.c.

◆ tor_gmtime_r()

struct tm* tor_gmtime_r ( const time_t *  timep,
struct tm *  result 
)

As gmtime_r, but defined for platforms that don't have it:

Convert *timep to a struct tm in UTC, and store the value in *result. Return the result on success, or NULL on failure.

Treat malformatted inputs or gmtime outputs as a BUG.

Definition at line 65 of file time_fmt.c.

Referenced by format_rfc1123_time(), and voting_sched_get_start_of_interval_after().

◆ tor_localtime_r()

struct tm* tor_localtime_r ( const time_t *  timep,
struct tm *  result 
)

As localtime_r, but defined for platforms that don't have it:

Convert *timep to a struct tm in local time, and store the value in *result. Return the result on success, or NULL on failure.

Treat malformatted inputs localtime outputs as a BUG.

Definition at line 46 of file time_fmt.c.

Referenced by edge_of_accounting_period_containing().

◆ tor_timegm()

int tor_timegm ( const struct tm *  tm,
time_t *  time_out 
)

Compute a time_t given a struct tm. The result is given in UTC, and does not account for leap seconds. Return 0 on success, -1 on failure.

Definition at line 96 of file time_fmt.c.

Referenced by voting_sched_get_start_of_interval_after().