From e025bb7a725610e327401d7afacedaad7079b989 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Sun, 4 Aug 2002 06:42:18 +0000 Subject: [PATCH] Define macros for handling typmod manipulation for date/time types. Should be more robust than all of that brute-force inline code. Rename macros for masking and typmod manipulation to put TIMESTAMP_ or INTERVAL_ in front of the macro name, to reduce the possibility of name space collisions. --- src/include/utils/timestamp.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h index aea1c17841..b2a7f85b8c 100644 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: timestamp.h,v 1.27 2002/06/20 20:29:53 momjian Exp $ + * $Id: timestamp.h,v 1.28 2002/08/04 06:42:18 thomas Exp $ * *------------------------------------------------------------------------- */ @@ -52,6 +52,10 @@ typedef struct } Interval; +#define MAX_TIMESTAMP_PRECISION 6 +#define MAX_INTERVAL_PRECISION 6 + + /* * Macros for fmgr-callable functions. * @@ -117,10 +121,6 @@ typedef struct #define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j)) - -#define MAX_TIMESTAMP_PRECISION 6 -#define MAX_INTERVAL_PRECISION 6 - #ifdef HAVE_INT64_TIMESTAMP typedef int32 fsec_t; @@ -134,6 +134,18 @@ typedef double fsec_t; #endif +#define TIMESTAMP_MASK(b) (1 << (b)) +#define INTERVAL_MASK(b) (1 << (b)) + +/* Macros to handle packing and unpacking the typmod field for intervals */ +#define INTERVAL_FULL_RANGE (0x7FFF) +#define INTERVAL_RANGE_MASK (0x7FFF) +#define INTERVAL_FULL_PRECISION (0xFFFF) +#define INTERVAL_PRECISION_MASK (0xFFFF) +#define INTERVAL_TYPMOD(p,r) ((((r) & INTERVAL_RANGE_MASK) << 16) | ((p) & INTERVAL_PRECISION_MASK)) +#define INTERVAL_PRECISION(t) ((t) & INTERVAL_PRECISION_MASK) +#define INTERVAL_RANGE(t) (((t) >> 16) & INTERVAL_RANGE_MASK) + /* * timestamp.c prototypes