154359Sroberto/* 2290001Sglebius * humandate.c - convert an NTP (or the current) time to something readable 354359Sroberto */ 4290001Sglebius#include <config.h> 554359Sroberto#include <stdio.h> 6290001Sglebius 754359Sroberto#include "ntp_fp.h" 882498Sroberto#include "ntp_unixtime.h" /* includes <sys/time.h> and <time.h> */ 954359Sroberto#include "lib_strbuf.h" 1054359Sroberto#include "ntp_stdlib.h" 1154359Sroberto 1254359Sroberto 13290001Sglebius/* This is used in msyslog.c; we don't want to clutter up the log with 14290001Sglebius the year and day of the week, etc.; just the minimal date and time. */ 15290001Sglebius 16290001Sglebiusconst char * 17290001Sglebiushumanlogtime(void) 1854359Sroberto{ 19290001Sglebius char * bp; 20290001Sglebius time_t cursec; 21290001Sglebius struct tm * tm; 22290001Sglebius 23290001Sglebius cursec = time(NULL); 24290001Sglebius tm = localtime(&cursec); 25132451Sroberto if (!tm) 26290001Sglebius return "-- --- --:--:--"; 27132451Sroberto 28132451Sroberto LIB_GETBUF(bp); 29132451Sroberto 30290001Sglebius snprintf(bp, LIB_BUFLENGTH, "%2d %s %02d:%02d:%02d", 31290001Sglebius tm->tm_mday, months[tm->tm_mon], 32290001Sglebius tm->tm_hour, tm->tm_min, tm->tm_sec); 33290001Sglebius 3454359Sroberto return bp; 3554359Sroberto} 3654359Sroberto 3754359Sroberto 38290001Sglebius/* 39290001Sglebius * humantime() -- like humanlogtime() but without date, and with the 40290001Sglebius * time to display given as an argument. 41290001Sglebius */ 42290001Sglebiusconst char * 43290001Sglebiushumantime( 44290001Sglebius time_t cursec 45290001Sglebius ) 4654359Sroberto{ 47290001Sglebius char * bp; 48290001Sglebius struct tm * tm; 4954359Sroberto 50182007Sroberto tm = localtime(&cursec); 51132451Sroberto if (!tm) 52290001Sglebius return "--:--:--"; 53132451Sroberto 5454359Sroberto LIB_GETBUF(bp); 5554359Sroberto 56290001Sglebius snprintf(bp, LIB_BUFLENGTH, "%02d:%02d:%02d", 57290001Sglebius tm->tm_hour, tm->tm_min, tm->tm_sec); 5854359Sroberto 5954359Sroberto return bp; 6054359Sroberto} 61