#ifndef _PGTIME_H
#define _PGTIME_H

#ifdef FRONTEND
/* Don't mess with anything for the frontends */
#include <time.h>

#else
#include "c.h"

/* 
 * Redefine functions and defines we implement, so we cause an
 * error if someone tries to use the "base functions" 
 */
#ifndef NO_REDEFINE_TIMEFUNCS
#define localtime DONOTUSETHIS_localtime
#define gmtime DONOTUSETHIS_gmtime
#define asctime DONOTUSETHIS_asctime
#define ctime DONOTUSETHIS_ctime
#define tzset DONOTUSETHIS_tzset
#define mktime DONOTUSETHIS_mktime
#define tzname DONOTUSETHIS_tzname
#define daylight DONOTUSETHIS_daylight
#define strftime DONOTUSETHIS_strftime
#endif

/* Then pull in default declarations */
#include <time.h>

/*
 * Now define prototype for our own timezone implementation
 * structs and functions.
 */

struct pg_tm {
	int tm_sec;
	int tm_min;
	int tm_hour;
	int tm_mday;
	int tm_mon;
	int tm_year;
	int tm_wday;
	int tm_yday;
	int tm_isdst;
	long int tm_gmtoff;
	const char *tm_zone;
};


struct pg_tm *pg_localtime(const time_t *);
struct pg_tm *pg_gmtime(const time_t *);
char *pg_asctime(const struct pg_tm *);
char *pg_ctime(const time_t *);
time_t pg_mktime(struct pg_tm *);
bool pg_tzset(const char *tzname, bool permanent);
size_t pg_strftime(char *s, size_t max, const char *format, const struct pg_tm *tm);
void pg_timezone_initialize(void);
char *pg_get_current_timezone(void);

extern time_t pg_timezone;
extern char *pg_tzname[2];

#endif /* frontend */


#endif
