/*
 * date.h --
 *	Date/Time ADT implementation.
 *
 * Identification:
 *	$Header: date.h,v 1.2 89/02/02 16:10:32 aoki Exp $
 *
 * Note:
 * XXX	This code is absolutely unused, anywhere, currently.
 */

#ifndef	DateIncluded	/* Include this file only once */
#define DateIncluded	1

#include <stdio.h>
#include <sys/time.h>
#include <string.h>

/*#define palloc malloc	*/	/*ONLY FOR TESTING, REMOVE IT FOR INTEGRATION*/

#define TM_YEAR_BASE 1900	/* compatible to UNIX time */
#define EPOCH_YEAR 1970		/* compatible to UNIX time */
#define YEAR_MAX 2038		/* otherwise overflow */
#define YEAR_MIN 1902		/* otherwise overflow */
#define DAYS_PER_LYEAR 366
#define DAYS_PER_NYEAR 365
#define HOURS_PER_DAY 24
#define MINS_PER_HOUR 60
#define SECS_PER_MIN 60
#define MAX_LONG 2147483647	 /* 2^31 */

/* absolute time definitions */
#define TIME_NOW_STR   "now"	   /* represents time now */
#define INVALID_ABSTIME 2147483647 /* -2145916801 invalid time representation */
				   /*   Dec 31 23:59:59 1901       */
#define INVALID_ABSTIME_STR "Undefined AbsTime" /*!! CHANGE also NEXT LINE !!*/
#define INVALID_ABSTIME_STR_LEN 17		/* <<<< */
#define INVALID_MONTH 11
#define INVALID_DAY 31
#define INVALID_HOUR 23
#define INVALID_MIN 59
#define INVALID_SEC 59
#define INVALID_YEAR 1901
#define MAX_ABSTIME 2145916800		/* Jan  1 00:00:00 2038 */ 
#define MIN_ABSTIME -2145916800		/* Jan  1 00:00:00 1902 */

/* relative time definitions */
#define MAX_RELTIME 2144448000	   /* about 68 years, compatible to absolute time */
#define INVALID_RELTIME 2147483647 /* invalid reltime representation =MAX_LONG*/
#define INVALID_RELTIME_STR "Undefined RelTime" /*!! CHANGE also NEXT LINE !!*/
#define INVALID_RELTIME_STR_LEN 17		/* <<<< */
#define RELTIME_LABEL '@'
#define RELTIME_PAST "ago"	   /* negative retime indication */
#define DIRMAXLEN 3	/* max length of the direction desc. RELTIME_PAST */

#define InAbsTimeRange(T) \
 	((int32)(T) <= MAX_ABSTIME && (int32)(T) >= MIN_ABSTIME)
#define InRelTimeRange(T) \
	((int32)(T) <= MAX_RELTIME && (int32)(T) >= - MAX_RELTIME)
#define IsCharDigit(C)		((C) >= '0' && (C) <= '9')
#define IsCharA_Z(C)		(((C) >= 'a' && (C) <= 'z') || ((C) >= 'A' && (C) <= 'Z'))
#define IsSpace(C)		((C) == ' ')
#define IsNull(C)		((C) == NULL)

typedef long	t_absolute;
typedef long	t_relative;
typedef	struct 	trange { 
		int   status;	/* flag, how to interpret data */
		long  data[2]; } t_interval;

#define T_INTERVAL_INVAL   0	/* data represents no valid interval */
#define	T_INTERVAL_VALID   1	/* data represents a valid interval */
#define T_INTERVAL_UNCOM   2	/* data represents an uncomplete interval */
#define T_INTERVAL_LEN     47	/* 2+20+1+1+1+20+2 : ['...' '...']  */
#define INVALID_INTERVAL_STR	"Undefined Range"

#endif	/* !defined(DateIncluded) */
