Navigation


Changeset 1225:ce8bc8227ef4 in freeDiameter


Ignore:
Timestamp:
Jul 17, 2013, 2:23:33 AM (11 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

Print times in localtime, not UTC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/dictionary_functions.c

    r1222 r1225  
    3535
    3636#include "fdproto-internal.h"
     37#include <time.h>
    3738
    3839/* This file contains helpers functions to be reused as callbacks in the struct dict_type_data structure.
     
    306307}
    307308
     309static void _format_offs (long offset, char *buf) {
     310    int offs_hours, offs_minutes, sgn = 1;
     311    if (offset < 0) {
     312        offset = -offset;
     313        sgn = 1;
     314    }
     315    offs_hours = (int)(offset/3600);
     316    offs_minutes = (offset%3600)/60;
     317
     318    char* s = buf;
     319
     320    *(s++) = sgn == 1 ? '+' : '-';
     321    *(s++) = (char)(offs_hours/10) + '0';
     322    *(s++) = offs_hours%10 + '0';
     323
     324    if (offs_minutes == 0) {
     325        *(s++) = '\0';
     326    } else {
     327        *(s++) = (char)(offs_minutes/10) + '0';
     328        *(s++) = offs_minutes%10 + '0';
     329        *(s++) = '\0';
     330    }
     331}
     332
    308333DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_Time_dump, union avp_value * avp_value)
    309334{
    310335        time_t val;
    311336        struct tm conv;
     337        char tz_buf[7];
    312338               
    313339        FD_DUMP_HANDLE_OFFSET();
     
    323349        }
    324350       
    325         CHECK_MALLOC_DO ( gmtime_r(&val, &conv), return NULL);
    326         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);
     351        CHECK_MALLOC_DO( localtime_r(&val, &conv), return NULL);
     352        _format_offs(conv.tm_gmtoff, tz_buf);
     353        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);
    327354        return *buf;
    328355}
Note: See TracChangeset for help on using the changeset viewer.