diff --git a/src/include/replication/walprotocol.h b/src/include/replication/walprotocol.h index 9414667..cdba21b 100644 --- a/src/include/replication/walprotocol.h +++ b/src/include/replication/walprotocol.h @@ -13,7 +13,7 @@ #define _WALPROTOCOL_H #include "access/xlogdefs.h" -#include "utils/timestamp.h" +#include "utils/timestamp_defs.h" /* diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h index 9e51b58..1a5ea0d 100644 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -19,86 +19,7 @@ #include "fmgr.h" #include "pgtime.h" -#ifdef HAVE_INT64_TIMESTAMP -#include "utils/int8.h" -#endif - -/* - * Timestamp represents absolute time. - * - * Interval represents delta time. Keep track of months (and years), days, - * and hours/minutes/seconds separately since the elapsed time spanned is - * unknown until instantiated relative to an absolute time. - * - * Note that Postgres uses "time interval" to mean a bounded interval, - * consisting of a beginning and ending time, not a time span - thomas 97/03/20 - * - * We have two implementations, one that uses int64 values with units of - * microseconds, and one that uses double values with units of seconds. - * - * TimeOffset and fsec_t are convenience typedefs for temporary variables - * that are of different types in the two cases. Do not use fsec_t in values - * stored on-disk, since it is not the same size in both implementations. - * Also, fsec_t is only meant for *fractional* seconds; beware of overflow - * if the value you need to store could be many seconds. - */ - -#ifdef HAVE_INT64_TIMESTAMP - -typedef int64 Timestamp; -typedef int64 TimestampTz; -typedef int64 TimeOffset; -typedef int32 fsec_t; /* fractional seconds (in microseconds) */ -#else - -typedef double Timestamp; -typedef double TimestampTz; -typedef double TimeOffset; -typedef double fsec_t; /* fractional seconds (in seconds) */ -#endif - -typedef struct -{ - TimeOffset time; /* all time units other than days, months and - * years */ - int32 day; /* days, after time for alignment */ - int32 month; /* months and years, after time for alignment */ -} Interval; - - -#define MAX_TIMESTAMP_PRECISION 6 -#define MAX_INTERVAL_PRECISION 6 - -/* in both timestamp.h and ecpg/dt.h */ -#define DAYS_PER_YEAR 365.25 /* assumes leap year every four years */ -#define MONTHS_PER_YEAR 12 -/* - * DAYS_PER_MONTH is very imprecise. The more accurate value is - * 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only - * return an integral number of days, but someday perhaps we should - * also return a 'time' value to be used as well. ISO 8601 suggests - * 30 days. - */ -#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */ -#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */ - -/* - * This doesn't adjust for uneven daylight savings time intervals or leap - * seconds, and it crudely estimates leap years. A more accurate value - * for days per years is 365.2422. - */ -#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */ -#define SECS_PER_DAY 86400 -#define SECS_PER_HOUR 3600 -#define SECS_PER_MINUTE 60 -#define MINS_PER_HOUR 60 - -#ifdef HAVE_INT64_TIMESTAMP -#define USECS_PER_DAY INT64CONST(86400000000) -#define USECS_PER_HOUR INT64CONST(3600000000) -#define USECS_PER_MINUTE INT64CONST(60000000) -#define USECS_PER_SEC INT64CONST(1000000) -#endif +#include "timestamp_type.h" /* * Macros for fmgr-callable functions. diff --git a/src/include/utils/timestamp_type.h b/src/include/utils/timestamp_type.h new file mode 100644 index 0000000..377b7f2 --- /dev/null +++ b/src/include/utils/timestamp_type.h @@ -0,0 +1,94 @@ +/*------------------------------------------------------------------------- + * + * timestamp_type.h + * Definitions for the timestamp datatype (separate from timestamp.h so + * they can be used from frontends) + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/timestamp_type.h + * + *------------------------------------------------------------------------- + */ +#ifndef TIMESTAMP_TYPE_H +#define TIMESTAMP_TYPE_H + +/* + * Timestamp represents absolute time. + * + * Interval represents delta time. Keep track of months (and years), days, + * and hours/minutes/seconds separately since the elapsed time spanned is + * unknown until instantiated relative to an absolute time. + * + * Note that Postgres uses "time interval" to mean a bounded interval, + * consisting of a beginning and ending time, not a time span - thomas 97/03/20 + * + * We have two implementations, one that uses int64 values with units of + * microseconds, and one that uses double values with units of seconds. + * + * TimeOffset and fsec_t are convenience typedefs for temporary variables + * that are of different types in the two cases. Do not use fsec_t in values + * stored on-disk, since it is not the same size in both implementations. + * Also, fsec_t is only meant for *fractional* seconds; beware of overflow + * if the value you need to store could be many seconds. + */ + +#ifdef HAVE_INT64_TIMESTAMP + +typedef int64 Timestamp; +typedef int64 TimestampTz; +typedef int64 TimeOffset; +typedef int32 fsec_t; /* fractional seconds (in microseconds) */ +#else + +typedef double Timestamp; +typedef double TimestampTz; +typedef double TimeOffset; +typedef double fsec_t; /* fractional seconds (in seconds) */ +#endif + +typedef struct +{ + TimeOffset time; /* all time units other than days, months and + * years */ + int32 day; /* days, after time for alignment */ + int32 month; /* months and years, after time for alignment */ +} Interval; + + +#define MAX_TIMESTAMP_PRECISION 6 +#define MAX_INTERVAL_PRECISION 6 + +/* in both timestamp.h and ecpg/dt.h */ +#define DAYS_PER_YEAR 365.25 /* assumes leap year every four years */ +#define MONTHS_PER_YEAR 12 +/* + * DAYS_PER_MONTH is very imprecise. The more accurate value is + * 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only + * return an integral number of days, but someday perhaps we should + * also return a 'time' value to be used as well. ISO 8601 suggests + * 30 days. + */ +#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */ +#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */ + +/* + * This doesn't adjust for uneven daylight savings time intervals or leap + * seconds, and it crudely estimates leap years. A more accurate value + * for days per years is 365.2422. + */ +#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */ +#define SECS_PER_DAY 86400 +#define SECS_PER_HOUR 3600 +#define SECS_PER_MINUTE 60 +#define MINS_PER_HOUR 60 + +#ifdef HAVE_INT64_TIMESTAMP +#define USECS_PER_DAY INT64CONST(86400000000) +#define USECS_PER_HOUR INT64CONST(3600000000) +#define USECS_PER_MINUTE INT64CONST(60000000) +#define USECS_PER_SEC INT64CONST(1000000) +#endif + +#endif /* TIMESTAMP_TYPE */