diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-01-11 10:48:05 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-01-11 12:08:01 -0500 |
commit | b5af456685b502462385b5f1b7f22f4374822fe1 (patch) | |
tree | 109aaf6977d92f21bb5a8bb93dfb2ddb8e033c94 /src/common | |
parent | c5b58df77588fd1307d248e75d360eb27023033c (diff) | |
download | tor-b5af456685b502462385b5f1b7f22f4374822fe1.tar.gz tor-b5af456685b502462385b5f1b7f22f4374822fe1.zip |
Use spaceless ISO8601 time format, not sec,usec.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 20 | ||||
-rw-r--r-- | src/common/util.h | 3 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index c44a4aa3b1..e7059a5bd9 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1430,6 +1430,26 @@ format_iso_time(char *buf, time_t t) strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_gmtime_r(&t, &tm)); } +/** As format_iso_time, but use the yyyy-mm-ddThh:mm:ss format to avoid + * embedding an internal space. */ +void +format_iso_time_nospace(char *buf, time_t t) +{ + format_iso_time(buf, t); + buf[10] = 'T'; +} + +/** 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. */ +void +format_iso_time_nospace_usec(char *buf, const struct timeval *tv) +{ + tor_assert(tv); + format_iso_time_nospace(buf, tv->tv_sec); + tor_snprintf(buf+ISO_TIME_LEN, 8, ".%06d", (int)tv->tv_usec); +} + /** Given an ISO-formatted UTC time value (after the epoch) in <b>cp</b>, * parse it and store its value in *<b>t</b>. Return 0 on success, -1 on * failure. Ignore extraneous stuff in <b>cp</b> separated by whitespace from diff --git a/src/common/util.h b/src/common/util.h index 77ed1ca5ee..bd471e3816 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -242,8 +242,11 @@ time_t tor_timegm(struct tm *tm); void format_rfc1123_time(char *buf, time_t t); int parse_rfc1123_time(const char *buf, time_t *t); #define ISO_TIME_LEN 19 +#define ISO_TIME_USEC_LEN (ISO_TIME_LEN+7) void format_local_iso_time(char *buf, time_t t); void format_iso_time(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 *buf, 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); |