1121054Semax/*	$NetBSD: humandate.c,v 1.1.1.2 2012/01/31 21:23:55 kardel Exp $	*/
2121054Semax
3121054Semax/*
4121054Semax * humandate - convert an NTP (or the current) time to something readable
5121054Semax */
6121054Semax#include <stdio.h>
7121054Semax#include "ntp_fp.h"
8121054Semax#include "ntp_unixtime.h"	/* includes <sys/time.h> and <time.h> */
9121054Semax#include "lib_strbuf.h"
10121054Semax#include "ntp_stdlib.h"
11121054Semax
12121054Semaxextern const char *months[];	/* prettydate.c */
13121054Semax
14121054Semax/* This is used in msyslog.c; we don't want to clutter up the log with
15121054Semax   the year and day of the week, etc.; just the minimal date and time.  */
16121054Semax
17121054Semaxconst char *
18121054Semaxhumanlogtime(void)
19121054Semax{
20121054Semax	char *		bp;
21121054Semax	time_t		cursec;
22121054Semax	struct tm *	tm;
23121054Semax
24121054Semax	cursec = time(NULL);
25121054Semax	tm = localtime(&cursec);
26121054Semax	if (!tm)
27121054Semax		return "-- --- --:--:--";
28121054Semax
29121054Semax	LIB_GETBUF(bp);
30121054Semax
31121054Semax	snprintf(bp, LIB_BUFLENGTH, "%2d %s %02d:%02d:%02d",
32121054Semax		 tm->tm_mday, months[tm->tm_mon],
33121054Semax		 tm->tm_hour, tm->tm_min, tm->tm_sec);
34121054Semax
35121054Semax	return bp;
36121054Semax}
37121054Semax