Obfuscate RCS ID matching so that CVS doesn't expand it.
[netbsd-mini2440.git] / dist / ntp / libntp / humandate.c
blobc07e576fc626afd369ce6a08ef1682561ec32535
1 /* $NetBSD: humandate.c,v 1.2 2003/12/04 16:23:36 drochner Exp $ */
3 /*
4 * humandate - convert an NTP (or the current) time to something readable
5 */
6 #include <stdio.h>
7 #include "ntp_fp.h"
8 #include "ntp_unixtime.h" /* includes <sys/time.h> and <time.h> */
9 #include "lib_strbuf.h"
10 #include "ntp_stdlib.h"
12 static const char *months[] = {
13 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
14 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
16 static const char *days[] = {
17 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
20 char *
21 humandate(
22 u_long ntptime
25 char *bp;
26 struct tm *tm;
28 tm = ntp2unix_tm(ntptime, 1);
30 if (!tm)
31 return "--- --- -- ---- --:--:--";
33 LIB_GETBUF(bp);
35 (void) sprintf(bp, "%s, %s %2d %4d %2d:%02d:%02d",
36 days[tm->tm_wday], months[tm->tm_mon], tm->tm_mday,
37 1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec);
39 return bp;
43 /* This is used in msyslog.c; we don't want to clutter up the log with
44 the year and day of the week, etc.; just the minimal date and time. */
46 char *
47 humanlogtime(void)
49 char *bp;
50 time_t cursec = time((time_t *) 0);
51 struct tm *tm;
53 tm = localtime(&cursec);
54 if (!tm)
55 return "-- --- --:--:--";
57 LIB_GETBUF(bp);
59 (void) sprintf(bp, "%2d %s %02d:%02d:%02d",
60 tm->tm_mday, months[tm->tm_mon],
61 tm->tm_hour, tm->tm_min, tm->tm_sec);
63 return bp;