119055Sdist /*
236929Sbostic * Copyright (c) 1985 The Regents of the University of California.
336929Sbostic * All rights reserved.
436929Sbostic *
5*42669Sbostic * %sccs.include.redist.c%
619055Sdist */
719055Sdist
817923Sralph #ifndef lint
9*42669Sbostic static char sccsid[] = "@(#)get_date.c 5.4 (Berkeley) 06/01/90";
1036929Sbostic #endif /* not lint */
1117923Sralph
1217923Sralph #include <stdio.h>
1317923Sralph #include <sys/time.h>
1417923Sralph
1517923Sralph static char *days[] = {
1617923Sralph "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"
1717923Sralph };
1817923Sralph
1917923Sralph static char *months[] = {
2017923Sralph "Jan", "Feb", "Mar", "Apr", "May", "June",
2117923Sralph "July", "Aug", "Sept", "Oct", "Nov", "Dec"
2217923Sralph };
2317923Sralph
2417923Sralph #define AM "am"
2517923Sralph #define PM "pm"
2617923Sralph
get_date(datebuffer)2717923Sralph get_date(datebuffer)
2817923Sralph char *datebuffer;
2917923Sralph {
3017923Sralph struct tm *localtime(), *tmp;
3117923Sralph struct timeval tv;
3217923Sralph int realhour;
3317923Sralph char *zone;
3417923Sralph
3517923Sralph gettimeofday(&tv, 0);
3617923Sralph tmp = localtime(&tv.tv_sec);
3717923Sralph
3817923Sralph realhour = tmp->tm_hour;
3917923Sralph zone = AM; /* default to morning */
4017923Sralph if (tmp->tm_hour == 0)
4117923Sralph realhour = 12; /* midnight */
4217923Sralph else if (tmp->tm_hour == 12)
4317923Sralph zone = PM; /* noon */
4417923Sralph else if (tmp->tm_hour >= 13 && tmp->tm_hour <= 23) { /* afternoon */
4517923Sralph realhour = realhour - 12;
4617923Sralph zone = PM;
4717923Sralph }
4817923Sralph
4917923Sralph /* format is '8:10pm on Sunday, 16 Sept 1973' */
5017923Sralph
5132462Sbostic (void)sprintf(datebuffer, "%d:%02d%s on %s, %d %s %d",
5217923Sralph realhour,
5317923Sralph tmp->tm_min,
5417923Sralph zone,
5517923Sralph days[tmp->tm_wday],
5617923Sralph tmp->tm_mday,
5717923Sralph months[tmp->tm_mon],
5817923Sralph 1900 + tmp->tm_year);
5917923Sralph }
60