Mercurial > hg > freeDiameter
changeset 1225:ce8bc8227ef4
Print times in localtime, not UTC.
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Tue, 16 Jul 2013 19:23:33 +0200 |
parents | 7769172b877c |
children | e59d76289e18 |
files | libfdproto/dictionary_functions.c |
diffstat | 1 files changed, 29 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libfdproto/dictionary_functions.c Tue Jul 16 16:14:14 2013 +0200 +++ b/libfdproto/dictionary_functions.c Tue Jul 16 19:23:33 2013 +0200 @@ -34,6 +34,7 @@ *********************************************************************************************************/ #include "fdproto-internal.h" +#include <time.h> /* This file contains helpers functions to be reused as callbacks in the struct dict_type_data structure. There are three callbacks there: @@ -305,10 +306,35 @@ return diameter_string_to_time_t((const char *)avp_value->os.data, avp_value->os.len, interpreted); } +static void _format_offs (long offset, char *buf) { + int offs_hours, offs_minutes, sgn = 1; + if (offset < 0) { + offset = -offset; + sgn = 1; + } + offs_hours = (int)(offset/3600); + offs_minutes = (offset%3600)/60; + + char* s = buf; + + *(s++) = sgn == 1 ? '+' : '-'; + *(s++) = (char)(offs_hours/10) + '0'; + *(s++) = offs_hours%10 + '0'; + + if (offs_minutes == 0) { + *(s++) = '\0'; + } else { + *(s++) = (char)(offs_minutes/10) + '0'; + *(s++) = offs_minutes%10 + '0'; + *(s++) = '\0'; + } +} + DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_Time_dump, union avp_value * avp_value) { time_t val; struct tm conv; + char tz_buf[7]; FD_DUMP_HANDLE_OFFSET(); @@ -322,8 +348,9 @@ return *buf; } - CHECK_MALLOC_DO ( gmtime_r(&val, &conv), return NULL); - CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "%d%02d%02dT%02d%02d%02d+00", conv.tm_year+1900, conv.tm_mon+1, conv.tm_mday, conv.tm_hour, conv.tm_min, conv.tm_sec), return NULL); + CHECK_MALLOC_DO( localtime_r(&val, &conv), return NULL); + _format_offs(conv.tm_gmtoff, tz_buf); + CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "%d%02d%02dT%02d%02d%02d%s", conv.tm_year+1900, conv.tm_mon+1, conv.tm_mday, conv.tm_hour, conv.tm_min, conv.tm_sec, tz_buf), return NULL); return *buf; }