154359Sroberto/*
254359Sroberto * humandate - convert an NTP (or the current) time to something readable
354359Sroberto */
454359Sroberto#include <stdio.h>
554359Sroberto#include "ntp_fp.h"
682498Sroberto#include "ntp_unixtime.h"	/* includes <sys/time.h> and <time.h> */
754359Sroberto#include "lib_strbuf.h"
854359Sroberto#include "ntp_stdlib.h"
954359Sroberto
1054359Srobertostatic const char *months[] = {
1154359Sroberto	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
1254359Sroberto	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
1354359Sroberto};
1454359Srobertostatic const char *days[] = {
1554359Sroberto	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
1654359Sroberto};
1754359Sroberto
1854359Srobertochar *
1954359Srobertohumandate(
2054359Sroberto	u_long ntptime
2154359Sroberto	)
2254359Sroberto{
2354359Sroberto	char *bp;
2454359Sroberto	struct tm *tm;
2554359Sroberto
26182007Sroberto	tm = ntp2unix_tm(ntptime, 1);
2754359Sroberto
28132451Sroberto	if (!tm)
29132451Sroberto		return "--- --- -- ---- --:--:--";
30132451Sroberto
31132451Sroberto	LIB_GETBUF(bp);
32132451Sroberto
3354359Sroberto	(void) sprintf(bp, "%s, %s %2d %4d %2d:%02d:%02d",
3454359Sroberto		       days[tm->tm_wday], months[tm->tm_mon], tm->tm_mday,
3554359Sroberto		       1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec);
3654359Sroberto
3754359Sroberto	return bp;
3854359Sroberto}
3954359Sroberto
4054359Sroberto
4154359Sroberto/* This is used in msyslog.c; we don't want to clutter up the log with
4254359Sroberto   the year and day of the week, etc.; just the minimal date and time.  */
4354359Sroberto
4454359Srobertochar *
4554359Srobertohumanlogtime(void)
4654359Sroberto{
4754359Sroberto	char *bp;
4854359Sroberto	time_t cursec = time((time_t *) 0);
49182007Sroberto	struct tm *tm;
5054359Sroberto
51182007Sroberto	tm = localtime(&cursec);
52132451Sroberto	if (!tm)
53132451Sroberto		return "-- --- --:--:--";
54132451Sroberto
5554359Sroberto	LIB_GETBUF(bp);
5654359Sroberto
5754359Sroberto	(void) sprintf(bp, "%2d %s %02d:%02d:%02d",
5854359Sroberto		       tm->tm_mday, months[tm->tm_mon],
5954359Sroberto		       tm->tm_hour, tm->tm_min, tm->tm_sec);
6054359Sroberto
6154359Sroberto	return bp;
6254359Sroberto}
63