static char rcsid[] = "@(#)$Id: date.c,v 1.16 2006/04/09 07:37:17 hurtta Exp $";

/******************************************************************************
 *  The Elm (ME+) Mail System  -  $Revision: 1.16 $   $State: Exp $
 *
 *  Modified by: Kari Hurtta <hurtta+elm@posti.FMI.FI> (was hurtta+elm@ozone.FMI.FI)
 ******************************************************************************
 *  The Elm Mail System 
 *
 * 			Copyright (c) 1988-1992 USENET Community Trust
 * 			Copyright (c) 1986,1987 Dave Taylor
 *****************************************************************************/

/** return the current date and time in a readable format! **/
/** also returns an ARPA RFC-822 format date...            **/


#include "def_elm.h"

#ifdef BSD_TYPE
#  include <sys/timeb.h>
#endif

#ifndef	_POSIX_SOURCE
extern struct tm *localtime();
extern struct tm *gmtime();
extern time_t	  time();
#endif

#define MONTHS_IN_YEAR	11	/* 0-11 equals 12 months! */
#define FEB		 1	/* 0 = January 		  */
#define DAYS_IN_LEAP_FEB 29	/* leap year only 	  */

#define ampm(n)		(n > 12? n - 12 : n)
#define am_or_pm(n)	(n > 11? (n > 23? "am" : "pm") : "am")

int  days_in_month[] = { 31,    28,    31,    30,    31,     30, 
		  31,     31,    30,   31,    30,     31,  -1};

void days_ahead(days, buffer, size)
     int days;
     char *buffer;
     int size;
{
	/** return in buffer the date (Day, Mon Day, Year) of the date
	    'days' days after today.  
	**/

	struct tm *the_time;		/* Time structure, see CTIME(3C) */
	time_t	   junk;		/* time in seconds....		 */

	junk = time((time_t *) 0);

	junk += days * 24 * 60 *60;
	the_time = localtime(&junk);


	elm_sfprintf(buffer, size,
		    FRM("%s, %d %s %d"),
		    arpa_dayname[the_time->tm_wday],
		    the_time->tm_mday,
		    arpa_monname[the_time->tm_mon],
		    1900+the_time->tm_year);
}


char *
elm_date_str(buf, seconds, size)
     char *buf;
     time_t seconds;
     int size;
{
	struct tm *tmbuf;

	tmbuf = gmtime(&seconds);

	elm_sfprintf(buf, size,
		     FRM("%s %d, %d %02d:%02d:%02d %s"),
		     arpa_monname[tmbuf->tm_mon],
		     tmbuf->tm_mday,
		     tmbuf->tm_year+1900,
		     ampm(tmbuf->tm_hour),
		     tmbuf->tm_min,
		     tmbuf->tm_sec,
		     am_or_pm(tmbuf->tm_hour));

	return(buf);
}

void make_menu_date(entry)
     struct header_rec *entry;
{
	struct tm *tmbuf;
	time_t seconds;

	seconds = entry->time_sent + entry->tz_offset;
	tmbuf = gmtime(&seconds);
	elm_sfprintf(entry->time_menu, sizeof entry->time_menu,
		     FRM("%3.3s %-2d"),
		     arpa_monname[tmbuf->tm_mon], tmbuf->tm_mday);
}

/*
 * Local Variables:
 *  mode:c
 *  c-basic-offset:4
 *  buffer-file-coding-system: iso-8859-1
 * End:
 */


syntax highlighted by Code2HTML, v. 0.9.1