1 /*
2 * humandate.c - convert an NTP (or the current) time to something readable
3 */
4 #include <config.h>
5 #include <stdio.h>
6
7 #include "ntp_fp.h"
8 #include "ntp_unixtime.h" /* includes <sys/time.h> and <time.h> */
9 #include "ntp_stdlib.h"
10
11
12 /* This is used in msyslog.c; we don't want to clutter up the log with
13 the year and day of the week, etc.; just the minimal date and time. */
14
15 const char *
humanlogtime(void)16 humanlogtime(void)
17 {
18 char * bp;
19 time_t cursec;
20 struct tm * tm;
21
22 cursec = time(NULL);
23 tm = localtime(&cursec);
24 if (!tm)
25 return "-- --- --:--:--";
26
27 LIB_GETBUF(bp);
28
29 snprintf(bp, LIB_BUFLENGTH, "%2d %s %02d:%02d:%02d",
30 tm->tm_mday, months[tm->tm_mon],
31 tm->tm_hour, tm->tm_min, tm->tm_sec);
32
33 return bp;
34 }
35
36
37 /*
38 * humantime() -- like humanlogtime() but without date, and with the
39 * time to display given as an argument.
40 */
41 const char *
humantime(time_t cursec)42 humantime(
43 time_t cursec
44 )
45 {
46 char * bp;
47 struct tm * tm;
48
49 tm = localtime(&cursec);
50 if (!tm)
51 return "--:--:--";
52
53 LIB_GETBUF(bp);
54
55 snprintf(bp, LIB_BUFLENGTH, "%02d:%02d:%02d",
56 tm->tm_hour, tm->tm_min, tm->tm_sec);
57
58 return bp;
59 }
60