154359Sroberto/* 254359Sroberto * uglydate - convert a time stamp to something barely readable 354359Sroberto * The string returned is 37 characters long. 454359Sroberto */ 554359Sroberto#include <stdio.h> 654359Sroberto 754359Sroberto#include "ntp_fp.h" 854359Sroberto#include "ntp_unixtime.h" 954359Sroberto#include "lib_strbuf.h" 1054359Sroberto#include "ntp_stdlib.h" 1154359Sroberto 1282498Sroberto 1354359Srobertochar * 1454359Srobertouglydate( 1554359Sroberto l_fp *ts 1654359Sroberto ) 1754359Sroberto{ 1854359Sroberto char *bp; 1954359Sroberto char *timep; 2054359Sroberto struct tm *tm; 2154359Sroberto time_t sec; 2254359Sroberto long msec; 2354359Sroberto int year; 2454359Sroberto 2554359Sroberto timep = ulfptoa(ts, 6); /* returns max 17 characters */ 2654359Sroberto LIB_GETBUF(bp); 2754359Sroberto sec = ts->l_ui - JAN_1970; 2854359Sroberto msec = ts->l_uf / 4294967; /* fract / (2**32/1000) */ 2954359Sroberto tm = gmtime(&sec); 3054359Sroberto if (ts->l_ui == 0) { 3154359Sroberto /* 3254359Sroberto * Probably not a real good thing to do. Oh, well. 3354359Sroberto */ 3454359Sroberto year = 0; 3554359Sroberto tm->tm_yday = 0; 3654359Sroberto tm->tm_hour = 0; 3754359Sroberto tm->tm_min = 0; 3854359Sroberto tm->tm_sec = 0; 3954359Sroberto } else { 4054359Sroberto year = tm->tm_year; 4154359Sroberto while (year >= 100) 4254359Sroberto year -= 100; 4354359Sroberto } 4454359Sroberto (void) sprintf(bp, "%17s %02d:%03d:%02d:%02d:%02d.%03ld", 4554359Sroberto timep, year, tm->tm_yday, tm->tm_hour, tm->tm_min, 4654359Sroberto tm->tm_sec, msec); 4754359Sroberto return bp; 4854359Sroberto} 49