Date/Time updates from Thomas...
This commit is contained in:
parent
71fd8d4a4b
commit
53d8be3bbf
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.5 1996/11/10 02:58:53 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.6 1997/03/14 23:17:41 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -15,7 +15,7 @@
|
|||
#include <postgres.h>
|
||||
|
||||
#include <utils/builtins.h>
|
||||
#include <utils/geo-decls.h>
|
||||
#include <utils/geo_decls.h>
|
||||
#ifndef HAVE_MEMMOVE
|
||||
# include <regex/utils.h>
|
||||
#else
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.11 1997/01/10 09:47:28 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.12 1997/03/14 23:17:46 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@
|
|||
#include <storage/lmgr.h>
|
||||
#include <access/rtree.h>
|
||||
#include <storage/bufmgr.h>
|
||||
#include <utils/geo-decls.h>
|
||||
#include <utils/geo_decls.h>
|
||||
#include <executor/executor.h>
|
||||
#include <access/heapam.h>
|
||||
#include <fmgr.h>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.7 1997/03/12 20:41:14 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.8 1997/03/14 23:18:16 scrappy Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
|
@ -171,7 +171,14 @@ TransactionState CurrentTransactionState =
|
|||
&CurrentTransactionStateData;
|
||||
|
||||
/* ----------------
|
||||
* info returned when the system is desabled
|
||||
* info returned when the system is disabled
|
||||
*
|
||||
* Apparently a lot of this code is inherited from other prototype systems.
|
||||
* For DisabledStartTime, use a symbolic value to make the relationships clearer.
|
||||
* The old value of 1073741823 corresponds to a date in y2004, which is coming closer
|
||||
* every day. It appears that if we return a value guaranteed larger than
|
||||
* any real time associated with a transaction then comparisons in other
|
||||
* modules will still be correct. Let's use BIG_ABSTIME for this. tgl 2/14/97
|
||||
*
|
||||
* Note: I have no idea what the significance of the
|
||||
* 1073741823 in DisabledStartTime.. I just carried
|
||||
|
@ -183,7 +190,7 @@ TransactionId DisabledTransactionId = (TransactionId)-1;
|
|||
|
||||
CommandId DisabledCommandId = (CommandId) -1;
|
||||
|
||||
AbsoluteTime DisabledStartTime = (AbsoluteTime) 1073741823;
|
||||
AbsoluteTime DisabledStartTime = (AbsoluteTime) BIG_ABSTIME; /* 1073741823; */
|
||||
|
||||
/* ----------------
|
||||
* overflow flag
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.16 1997/03/12 20:57:33 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.17 1997/03/14 23:18:32 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -89,7 +89,7 @@
|
|||
|
||||
#include "catalog/catname.h"
|
||||
|
||||
#include "utils/geo-decls.h"
|
||||
#include "utils/geo_decls.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
#include "catalog/index.h"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# Makefile for utils/adt
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.6 1997/03/12 21:27:03 scrappy Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.7 1997/03/14 23:19:50 scrappy Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
|
@ -20,8 +20,9 @@ CFLAGS+=$(INCLUDE_OPT)
|
|||
OBJS = acl.o arrayfuncs.o arrayutils.o bool.o char.o chunk.o date.o \
|
||||
datum.o dt.o filename.o float.o geo_ops.o geo_selfuncs.o int.o \
|
||||
misc.o nabstime.o name.o not_in.o numutils.o oid.o \
|
||||
oidname.o oidint2.o oidint4.o oracle_compat.o regexp.o regproc.o selfuncs.o \
|
||||
tid.o varchar.o varlena.o sets.o datetimes.o like.o timestamp.o
|
||||
oidname.o oidint2.o oidint4.o oracle_compat.o regexp.o regproc.o \
|
||||
selfuncs.o \
|
||||
tid.o varchar.o varlena.o sets.o datetime.o like.o timestamp.o
|
||||
|
||||
all: SUBSYS.o
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.2 1996/11/03 06:53:03 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.3 1997/03/14 23:19:52 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -24,12 +24,12 @@
|
|||
/*
|
||||
* boolin - converts "t" or "f" to 1 or 0
|
||||
*/
|
||||
int32
|
||||
bool
|
||||
boolin(char *b)
|
||||
{
|
||||
if (b == NULL)
|
||||
elog(WARN, "Bad input string for type bool");
|
||||
return((int32) (*b == 't') || (*b == 'T'));
|
||||
return((bool) (*b == 't') || (*b == 'T'));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -49,13 +49,13 @@ boolout(long b)
|
|||
* PUBLIC ROUTINES *
|
||||
*****************************************************************************/
|
||||
|
||||
int32
|
||||
bool
|
||||
booleq(int8 arg1, int8 arg2)
|
||||
{
|
||||
return(arg1 == arg2);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
boolne(int8 arg1, int8 arg2)
|
||||
{
|
||||
return(arg1 != arg2);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.2 1996/09/10 06:41:34 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.3 1997/03/14 23:19:54 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -127,25 +127,25 @@ char *char16out(char *s)
|
|||
* PUBLIC ROUTINES *
|
||||
*****************************************************************************/
|
||||
|
||||
int32 chareq(int8 arg1, int8 arg2) { return(arg1 == arg2); }
|
||||
int32 charne(int8 arg1, int8 arg2) { return(arg1 != arg2); }
|
||||
bool chareq(int8 arg1, int8 arg2) { return(arg1 == arg2); }
|
||||
bool charne(int8 arg1, int8 arg2) { return(arg1 != arg2); }
|
||||
#ifdef UNSIGNED_CHAR_TEXT
|
||||
int32 charlt(int8 arg1, int8 arg2) { return((uint8)arg1 < (uint8)arg2); }
|
||||
int32 charle(int8 arg1, int8 arg2) { return((uint8)arg1 <= (uint8)arg2); }
|
||||
int32 chargt(int8 arg1, int8 arg2) { return((uint8)arg1 > (uint8)arg2); }
|
||||
int32 charge(int8 arg1, int8 arg2) { return((uint8)arg1 >= (uint8)arg2); }
|
||||
bool charlt(int8 arg1, int8 arg2) { return((uint8)arg1 < (uint8)arg2); }
|
||||
bool charle(int8 arg1, int8 arg2) { return((uint8)arg1 <= (uint8)arg2); }
|
||||
bool chargt(int8 arg1, int8 arg2) { return((uint8)arg1 > (uint8)arg2); }
|
||||
bool charge(int8 arg1, int8 arg2) { return((uint8)arg1 >= (uint8)arg2); }
|
||||
#else
|
||||
int32 charlt(int8 arg1, int8 arg2) { return(arg1 < arg2); }
|
||||
int32 charle(int8 arg1, int8 arg2) { return(arg1 <= arg2); }
|
||||
int32 chargt(int8 arg1, int8 arg2) { return(arg1 > arg2); }
|
||||
int32 charge(int8 arg1, int8 arg2) { return(arg1 >= arg2); }
|
||||
bool charlt(int8 arg1, int8 arg2) { return(arg1 < arg2); }
|
||||
bool charle(int8 arg1, int8 arg2) { return(arg1 <= arg2); }
|
||||
bool chargt(int8 arg1, int8 arg2) { return(arg1 > arg2); }
|
||||
bool charge(int8 arg1, int8 arg2) { return(arg1 >= arg2); }
|
||||
#endif
|
||||
int8 charpl(int8 arg1, int8 arg2) { return(arg1 + arg2); }
|
||||
int8 charmi(int8 arg1, int8 arg2) { return(arg1 - arg2); }
|
||||
int8 charmul(int8 arg1, int8 arg2) { return(arg1 * arg2); }
|
||||
int8 chardiv(int8 arg1, int8 arg2) { return(arg1 / arg2); }
|
||||
|
||||
int32 cideq(int8 arg1, int8 arg2) { return(arg1 == arg2); }
|
||||
bool cideq(int8 arg1, int8 arg2) { return(arg1 == arg2); }
|
||||
|
||||
/*
|
||||
* char16eq - returns 1 iff arguments are equal
|
||||
|
@ -161,48 +161,48 @@ int32 cideq(int8 arg1, int8 arg2) { return(arg1 == arg2); }
|
|||
* char16ge - returns 1 iff a <= b
|
||||
*
|
||||
*/
|
||||
int32 char16eq(char *arg1, char *arg2)
|
||||
bool char16eq(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
return(strncmp(arg1, arg2, 16) == 0);
|
||||
}
|
||||
|
||||
int32 char16ne(char *arg1, char *arg2)
|
||||
bool char16ne(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
return(strncmp(arg1, arg2, 16) != 0);
|
||||
}
|
||||
|
||||
int32 char16lt(char *arg1, char *arg2)
|
||||
bool char16lt(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((int32) (strncmp(arg1, arg2, 16) < 0));
|
||||
return((bool) 0);
|
||||
return((bool) (strncmp(arg1, arg2, 16) < 0));
|
||||
}
|
||||
|
||||
int32 char16le(char *arg1, char *arg2)
|
||||
bool char16le(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((int32) (strncmp(arg1, arg2, 16) <= 0));
|
||||
return((bool) 0);
|
||||
return((bool) (strncmp(arg1, arg2, 16) <= 0));
|
||||
}
|
||||
|
||||
int32 char16gt(char *arg1, char *arg2)
|
||||
bool char16gt(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
|
||||
return((int32) (strncmp(arg1, arg2, 16) > 0));
|
||||
return((bool) (strncmp(arg1, arg2, 16) > 0));
|
||||
}
|
||||
|
||||
int32 char16ge(char *arg1, char *arg2)
|
||||
bool char16ge(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
|
||||
return((int32) (strncmp(arg1, arg2, 16) >= 0));
|
||||
return((bool) (strncmp(arg1, arg2, 16) >= 0));
|
||||
}
|
||||
|
||||
|
||||
|
@ -229,32 +229,32 @@ char *char2out(uint16 s)
|
|||
return(result);
|
||||
}
|
||||
|
||||
int32 char2eq(uint16 a, uint16 b)
|
||||
bool char2eq(uint16 a, uint16 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 2) == 0);
|
||||
}
|
||||
|
||||
int32 char2ne(uint16 a, uint16 b)
|
||||
bool char2ne(uint16 a, uint16 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 2) != 0);
|
||||
}
|
||||
|
||||
int32 char2lt(uint16 a, uint16 b)
|
||||
bool char2lt(uint16 a, uint16 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 2) < 0);
|
||||
}
|
||||
|
||||
int32 char2le(uint16 a, uint16 b)
|
||||
bool char2le(uint16 a, uint16 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 2) <= 0);
|
||||
}
|
||||
|
||||
int32 char2gt(uint16 a, uint16 b)
|
||||
bool char2gt(uint16 a, uint16 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 2) > 0);
|
||||
}
|
||||
|
||||
int32 char2ge(uint16 a, uint16 b)
|
||||
bool char2ge(uint16 a, uint16 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 2) >= 0);
|
||||
}
|
||||
|
@ -289,32 +289,32 @@ char *char4out(s)
|
|||
return(result);
|
||||
}
|
||||
|
||||
int32 char4eq(uint32 a, uint32 b)
|
||||
bool char4eq(uint32 a, uint32 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 4) == 0);
|
||||
}
|
||||
|
||||
int32 char4ne(uint32 a, uint32 b)
|
||||
bool char4ne(uint32 a, uint32 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 4) != 0);
|
||||
}
|
||||
|
||||
int32 char4lt(uint32 a, uint32 b)
|
||||
bool char4lt(uint32 a, uint32 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 4) < 0);
|
||||
}
|
||||
|
||||
int32 char4le(uint32 a, uint32 b)
|
||||
bool char4le(uint32 a, uint32 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 4) <= 0);
|
||||
}
|
||||
|
||||
int32 char4gt(uint32 a, uint32 b)
|
||||
bool char4gt(uint32 a, uint32 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 4) > 0);
|
||||
}
|
||||
|
||||
int32 char4ge(uint32 a, uint32 b)
|
||||
bool char4ge(uint32 a, uint32 b)
|
||||
{
|
||||
return(strncmp((char *) &a, (char *) &b, 4) >= 0);
|
||||
}
|
||||
|
@ -351,46 +351,46 @@ char *char8out(char *s)
|
|||
return(result);
|
||||
}
|
||||
|
||||
int32 char8eq(char *arg1, char *arg2)
|
||||
bool char8eq(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return(strncmp(arg1, arg2, 8) == 0);
|
||||
return((bool) 0);
|
||||
return((bool) strncmp(arg1, arg2, 8) == 0);
|
||||
}
|
||||
|
||||
int32 char8ne(char *arg1, char *arg2)
|
||||
bool char8ne(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return(strncmp(arg1, arg2, 8) != 0);
|
||||
return((bool) 0);
|
||||
return((bool) strncmp(arg1, arg2, 8) != 0);
|
||||
}
|
||||
|
||||
int32 char8lt(char *arg1, char *arg2)
|
||||
bool char8lt(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return(strncmp(arg1, arg2, 8) < 0);
|
||||
return((bool) 0);
|
||||
return((bool) strncmp(arg1, arg2, 8) < 0);
|
||||
}
|
||||
|
||||
int32 char8le(char *arg1, char *arg2)
|
||||
bool char8le(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return(strncmp(arg1, arg2, 8) <= 0);
|
||||
return((bool) 0);
|
||||
return((bool) strncmp(arg1, arg2, 8) <= 0);
|
||||
}
|
||||
|
||||
int32 char8gt(char *arg1, char *arg2)
|
||||
bool char8gt(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return(strncmp(arg1, arg2, 8) > 0);
|
||||
return((bool) 0);
|
||||
return((bool) strncmp(arg1, arg2, 8) > 0);
|
||||
}
|
||||
|
||||
int32 char8ge(char *arg1, char *arg2)
|
||||
bool char8ge(char *arg1, char *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return(strncmp(arg1, arg2, 8) >= 0);
|
||||
return((bool) 0);
|
||||
return((bool) strncmp(arg1, arg2, 8) >= 0);
|
||||
}
|
||||
|
||||
int32 char8cmp(char *arg1, char *arg2)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* date.c--
|
||||
* Functions for the built-in type "AbsoluteTime".
|
||||
* Utilities for the built-in type "AbsoluteTime" (defined in nabstime).
|
||||
* Functions for the built-in type "RelativeTime".
|
||||
* Functions for the built-in type "TimeInterval".
|
||||
*
|
||||
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.5 1997/02/14 04:17:35 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.6 1997/03/14 23:19:57 scrappy Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This code is actually (almost) unused.
|
||||
|
@ -35,25 +35,11 @@
|
|||
#include "access/xact.h"
|
||||
#include "utils/builtins.h" /* where function declarations go */
|
||||
#include "utils/palloc.h"
|
||||
#include "utils/dt.h"
|
||||
|
||||
#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 TIME_EPOCH_STR "epoch" /* Jan 1 00:00:00 1970 GMT */
|
||||
#define TIME_EPOCH_STR_LEN (sizeof(TIME_EPOCH_STR)-1)
|
||||
|
||||
#define INVALID_ABSTIME_STR "Undefined AbsTime"
|
||||
#define INVALID_ABSTIME_STR_LEN (sizeof(INVALID_ABSTIME_STR)-1)
|
||||
#ifndef USE_NEW_TIME_CODE
|
||||
#define USE_NEW_TIME_CODE 1
|
||||
#endif
|
||||
|
||||
#define INVALID_RELTIME_STR "Undefined RelTime"
|
||||
#define INVALID_RELTIME_STR_LEN (sizeof(INVALID_RELTIME_STR)-1)
|
||||
|
@ -66,10 +52,7 @@
|
|||
* sixty-eight years on either side of that.
|
||||
*/
|
||||
|
||||
#define IsCharDigit(C) isdigit(C)
|
||||
#define IsCharA_Z(C) isalpha(C)
|
||||
#define IsSpace(C) ((C) == ' ')
|
||||
#define IsNull(C) ((C) == NULL)
|
||||
|
||||
#define T_INTERVAL_INVAL 0 /* data represents no valid interval */
|
||||
#define T_INTERVAL_VALID 1 /* data represents a valid interval */
|
||||
|
@ -101,20 +84,13 @@ static int sec_tab[] = {
|
|||
3600, 3600, 86400, 86400, 604800, 604800,
|
||||
2592000, 2592000, 31536000, 31536000 };
|
||||
|
||||
/* maximal values (in seconds) per unit which can be represented */
|
||||
static int unit_max_quantity[] = {
|
||||
2144448000, 2144448000, 35740800, 35740800,
|
||||
595680, 595680, 24820, 24820, 3545, 3545,
|
||||
827, 827, 68, 68 };
|
||||
|
||||
|
||||
struct timeb *TimeDifferenceFromGMT = NULL;
|
||||
|
||||
/*
|
||||
* Function prototypes -- internal to this file only
|
||||
*/
|
||||
|
||||
static int correct_unit(char unit[], int *unptr);
|
||||
static int correct_dir(char direction[], int *signptr);
|
||||
|
||||
static int istinterval(char *i_string,
|
||||
AbsoluteTime *i_start,
|
||||
AbsoluteTime *i_end);
|
||||
|
@ -126,41 +102,45 @@ static int istinterval(char *i_string,
|
|||
/*
|
||||
* reltimein - converts a reltime string in an internal format
|
||||
*/
|
||||
int32 /* RelativeTime */
|
||||
reltimein(char *timestring)
|
||||
RelativeTime
|
||||
reltimein(char *str)
|
||||
{
|
||||
int error;
|
||||
int32 /* RelativeTime */ timeinsec;
|
||||
int sign, unitnr;
|
||||
long quantity;
|
||||
RelativeTime result;
|
||||
|
||||
error = isreltime(timestring, &sign, &quantity, &unitnr);
|
||||
struct tm tt, *tm = &tt;
|
||||
double fsec;
|
||||
int dtype;
|
||||
char *field[MAXDATEFIELDS];
|
||||
int nf, ftype[MAXDATEFIELDS];
|
||||
char lowstr[MAXDATELEN+1];
|
||||
|
||||
if (!PointerIsValid(str))
|
||||
elog(WARN,"Bad (null) date external representation",NULL);
|
||||
|
||||
if (strlen(str) > MAXDATELEN)
|
||||
elog( WARN, "Bad (length) reltime external representation '%s'",str);
|
||||
|
||||
if ((ParseDateTime( str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|
||||
|| (DecodeDateDelta( field, ftype, nf, &dtype, tm, &fsec) != 0))
|
||||
elog(WARN,"Bad reltime external representation '%s'",str);
|
||||
|
||||
#ifdef DATEDEBUG
|
||||
elog(DEBUG, "reltimein: isreltime(%s) returns error=%d, %d, %d, %d",
|
||||
timestring, error, sign, quantity, unitnr);
|
||||
#endif /* !DATEDEBUG */
|
||||
printf( "reltimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE);
|
||||
#endif
|
||||
|
||||
if (error != 1) {
|
||||
timeinsec = INVALID_RELTIME; /*invalid time representation */
|
||||
} else {
|
||||
/* this check is necessary, while no control on overflow */
|
||||
if (quantity > unit_max_quantity[unitnr] || quantity < 0) {
|
||||
#ifdef DATEDEBUG
|
||||
elog(DEBUG, "reltimein: illegal quantity %d (< %d)",
|
||||
quantity, unit_max_quantity[unitnr]);
|
||||
#endif /* DATEDEBUG */
|
||||
timeinsec = INVALID_RELTIME; /* illegal quantity */
|
||||
} else {
|
||||
timeinsec = sign * quantity * sec_tab[unitnr];
|
||||
#ifdef DATEDEBUG
|
||||
elog(DEBUG, "reltimein: computed timeinsec %d",
|
||||
timeinsec);
|
||||
#endif /* DATEDEBUG */
|
||||
}
|
||||
}
|
||||
return(timeinsec);
|
||||
}
|
||||
switch (dtype) {
|
||||
case DTK_DELTA:
|
||||
result = ((((tm->tm_hour*60)+tm->tm_min)*60)+tm->tm_sec);
|
||||
result += (((tm->tm_year*365)+(tm->tm_mon*30)+tm->tm_mday)*(24*60*60));
|
||||
return(result);
|
||||
|
||||
default:
|
||||
return(INVALID_RELTIME);
|
||||
};
|
||||
|
||||
elog(WARN,"Bad reltime (internal coding error) '%s'",str);
|
||||
return(INVALID_RELTIME);
|
||||
} /* reltimein() */
|
||||
|
||||
|
||||
/*
|
||||
|
@ -379,42 +359,42 @@ AbsoluteTime timenow()
|
|||
* reltimele - returns 1, iff t1 less than or equal to t2
|
||||
* reltimege - returns 1, iff t1 greater than or equal to t2
|
||||
*/
|
||||
int32 reltimeeq(RelativeTime t1, RelativeTime t2)
|
||||
bool reltimeeq(RelativeTime t1, RelativeTime t2)
|
||||
{
|
||||
if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME)
|
||||
return 0;
|
||||
return(t1 == t2);
|
||||
}
|
||||
|
||||
int32 reltimene(RelativeTime t1, RelativeTime t2)
|
||||
bool reltimene(RelativeTime t1, RelativeTime t2)
|
||||
{
|
||||
if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME)
|
||||
return 0;
|
||||
return(t1 != t2);
|
||||
}
|
||||
|
||||
int32 reltimelt(RelativeTime t1, RelativeTime t2)
|
||||
bool reltimelt(RelativeTime t1, RelativeTime t2)
|
||||
{
|
||||
if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME)
|
||||
return 0;
|
||||
return(t1 < t2);
|
||||
}
|
||||
|
||||
int32 reltimegt(RelativeTime t1, RelativeTime t2)
|
||||
bool reltimegt(RelativeTime t1, RelativeTime t2)
|
||||
{
|
||||
if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME)
|
||||
return 0;
|
||||
return(t1 > t2);
|
||||
}
|
||||
|
||||
int32 reltimele(RelativeTime t1, RelativeTime t2)
|
||||
bool reltimele(RelativeTime t1, RelativeTime t2)
|
||||
{
|
||||
if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME)
|
||||
return 0;
|
||||
return(t1 <= t2);
|
||||
}
|
||||
|
||||
int32 reltimege(RelativeTime t1, RelativeTime t2)
|
||||
bool reltimege(RelativeTime t1, RelativeTime t2)
|
||||
{
|
||||
if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME)
|
||||
return 0;
|
||||
|
@ -425,7 +405,7 @@ int32 reltimege(RelativeTime t1, RelativeTime t2)
|
|||
/*
|
||||
* intervaleq - returns 1, iff interval i1 is equal to interval i2
|
||||
*/
|
||||
int32 intervaleq(TimeInterval i1, TimeInterval i2)
|
||||
bool intervaleq(TimeInterval i1, TimeInterval i2)
|
||||
{
|
||||
if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)
|
||||
return(0); /* invalid interval */
|
||||
|
@ -437,7 +417,7 @@ int32 intervaleq(TimeInterval i1, TimeInterval i2)
|
|||
* intervalleneq - returns 1, iff length of interval i is equal to
|
||||
* reltime t
|
||||
*/
|
||||
int32 intervalleneq(TimeInterval i, RelativeTime t)
|
||||
bool intervalleneq(TimeInterval i, RelativeTime t)
|
||||
{
|
||||
RelativeTime rt;
|
||||
|
||||
|
@ -451,7 +431,7 @@ int32 intervalleneq(TimeInterval i, RelativeTime t)
|
|||
* intervallenne - returns 1, iff length of interval i is not equal
|
||||
* to reltime t
|
||||
*/
|
||||
int32 intervallenne(TimeInterval i, RelativeTime t)
|
||||
bool intervallenne(TimeInterval i, RelativeTime t)
|
||||
{
|
||||
RelativeTime rt;
|
||||
|
||||
|
@ -465,7 +445,7 @@ int32 intervallenne(TimeInterval i, RelativeTime t)
|
|||
* intervallenlt - returns 1, iff length of interval i is less than
|
||||
* reltime t
|
||||
*/
|
||||
int32 intervallenlt(TimeInterval i, RelativeTime t)
|
||||
bool intervallenlt(TimeInterval i, RelativeTime t)
|
||||
{
|
||||
RelativeTime rt;
|
||||
|
||||
|
@ -479,7 +459,7 @@ int32 intervallenlt(TimeInterval i, RelativeTime t)
|
|||
* intervallengt - returns 1, iff length of interval i is greater than
|
||||
* reltime t
|
||||
*/
|
||||
int32 intervallengt(TimeInterval i, RelativeTime t)
|
||||
bool intervallengt(TimeInterval i, RelativeTime t)
|
||||
{
|
||||
RelativeTime rt;
|
||||
|
||||
|
@ -493,7 +473,7 @@ int32 intervallengt(TimeInterval i, RelativeTime t)
|
|||
* intervallenle - returns 1, iff length of interval i is less or equal
|
||||
* than reltime t
|
||||
*/
|
||||
int32 intervallenle(TimeInterval i, RelativeTime t)
|
||||
bool intervallenle(TimeInterval i, RelativeTime t)
|
||||
{
|
||||
RelativeTime rt;
|
||||
|
||||
|
@ -507,7 +487,7 @@ int32 intervallenle(TimeInterval i, RelativeTime t)
|
|||
* intervallenge - returns 1, iff length of interval i is greater or
|
||||
* equal than reltime t
|
||||
*/
|
||||
int32 intervallenge(TimeInterval i, RelativeTime t)
|
||||
bool intervallenge(TimeInterval i, RelativeTime t)
|
||||
{
|
||||
RelativeTime rt;
|
||||
|
||||
|
@ -520,7 +500,7 @@ int32 intervallenge(TimeInterval i, RelativeTime t)
|
|||
/*
|
||||
* intervalct - returns 1, iff interval i1 contains interval i2
|
||||
*/
|
||||
int32 intervalct(TimeInterval i1, TimeInterval i2)
|
||||
bool intervalct(TimeInterval i1, TimeInterval i2)
|
||||
{
|
||||
if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)
|
||||
return(0);
|
||||
|
@ -531,7 +511,7 @@ int32 intervalct(TimeInterval i1, TimeInterval i2)
|
|||
/*
|
||||
* intervalov - returns 1, iff interval i1 (partially) overlaps i2
|
||||
*/
|
||||
int32 intervalov(TimeInterval i1, TimeInterval i2)
|
||||
bool intervalov(TimeInterval i1, TimeInterval i2)
|
||||
{
|
||||
if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)
|
||||
return(0);
|
||||
|
@ -736,7 +716,6 @@ static int correct_dir(char direction[], int *signptr)
|
|||
return (0); /* invalid direction descriptor */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* istinterval - returns 1, iff i_string is a valid interval descr.
|
||||
* 0, iff i_string is NOT a valid interval desc.
|
||||
|
|
|
@ -0,0 +1,743 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* datetime.c--
|
||||
* implements DATE and TIME data types specified in SQL-92 standard
|
||||
*
|
||||
* Copyright (c) 1994-5, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.1 1997/03/14 23:20:01 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include <stdio.h> /* for sprintf() */
|
||||
#include <string.h>
|
||||
|
||||
#include <postgres.h>
|
||||
#include <miscadmin.h>
|
||||
#include <utils/builtins.h>
|
||||
#include <utils/nabstime.h>
|
||||
#include <utils/datetime.h>
|
||||
|
||||
static int day_tab[2][12] = {
|
||||
{31,28,31,30,31,30,31,31,30,31,30,31},
|
||||
{31,29,31,30,31,30,31,31,30,31,30,31} };
|
||||
|
||||
#define isleap(y) (((y % 4) == 0 && (y % 100) != 0) || (y % 400) == 0)
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Date ADT
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
/* date_in()
|
||||
* Given date text string, convert to internal date format.
|
||||
*/
|
||||
#if USE_NEW_DATE
|
||||
|
||||
DateADT
|
||||
date_in(char *str)
|
||||
{
|
||||
DateADT date;
|
||||
|
||||
#else
|
||||
|
||||
int4
|
||||
date_in(char *str)
|
||||
{
|
||||
int4 result;
|
||||
DateADT *date = (DateADT *)&result;
|
||||
|
||||
#endif
|
||||
|
||||
double fsec;
|
||||
struct tm tt, *tm = &tt;
|
||||
int tzp;
|
||||
int dtype;
|
||||
int nf;
|
||||
char *field[MAXDATEFIELDS];
|
||||
int ftype[MAXDATEFIELDS];
|
||||
char lowstr[MAXDATELEN+1];
|
||||
|
||||
if (!PointerIsValid(str))
|
||||
elog(WARN,"Bad (null) date external representation",NULL);
|
||||
|
||||
#ifdef DATEDEBUG
|
||||
printf( "date_in- input string is %s\n", str);
|
||||
#endif
|
||||
if ((ParseDateTime( str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|
||||
|| (DecodeDateTime( field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0))
|
||||
elog(WARN,"Bad date external representation %s",str);
|
||||
|
||||
switch (dtype) {
|
||||
#if FALSE
|
||||
case DTK_DATE:
|
||||
date = date2j(tm->tm_year,tm->tm_mon,tm->tm_mday);
|
||||
time = time2j(tm->tm_hour,tm->tm_min,(double)tm->tm_sec);
|
||||
if (tzp != 0) {
|
||||
j2local(&date, &time, -(tzp*60));
|
||||
} else {
|
||||
j2local(&date, &time, -timezone);
|
||||
};
|
||||
break;
|
||||
#endif
|
||||
|
||||
case DTK_EPOCH:
|
||||
tm->tm_year = 1970;
|
||||
tm->tm_mon = 1;
|
||||
tm->tm_mday = 1;
|
||||
case DTK_DATE:
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(WARN,"Unrecognized date external representation %s",str);
|
||||
};
|
||||
|
||||
#if FALSE
|
||||
if (tm->tm_year < 70)
|
||||
tm->tm_year += 2000;
|
||||
else if (tm->tm_year < 100)
|
||||
tm->tm_year += 1900;
|
||||
#endif
|
||||
|
||||
if (tm->tm_year < 0 || tm->tm_year > 32767)
|
||||
elog(WARN, "date_in: year must be limited to values 0 through 32767 in '%s'", str);
|
||||
if (tm->tm_mon < 1 || tm->tm_mon > 12)
|
||||
elog(WARN, "date_in: month must be limited to values 1 through 12 in '%s'", str);
|
||||
if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon-1])
|
||||
elog(WARN, "date_in: day must be limited to values 1 through %d in '%s'",
|
||||
day_tab[isleap(tm->tm_year)][tm->tm_mon-1], str);
|
||||
|
||||
#if USE_NEW_DATE
|
||||
|
||||
date = (date2j(tm->tm_year,tm->tm_mon,tm->tm_mday) - date2j(2000,1,1));
|
||||
|
||||
return(date);
|
||||
|
||||
#else
|
||||
|
||||
date->day = tm->tm_mday;
|
||||
date->month = tm->tm_mon;
|
||||
date->year = tm->tm_year;
|
||||
|
||||
return(result);
|
||||
|
||||
#endif
|
||||
} /* date_in() */
|
||||
|
||||
/* date_out()
|
||||
* Given internal format date, convert to text string.
|
||||
*/
|
||||
#if USE_NEW_DATE
|
||||
|
||||
char *
|
||||
date_out(DateADT date)
|
||||
{
|
||||
|
||||
#else
|
||||
|
||||
char *
|
||||
date_out(int4 dateVal)
|
||||
{
|
||||
DateADT *date = (DateADT *)&dateVal;
|
||||
|
||||
#endif
|
||||
char *result;
|
||||
char buf[MAXDATELEN+1];
|
||||
int year, month, day;
|
||||
|
||||
#if USE_NEW_DATE
|
||||
|
||||
j2date( (((int) date) + date2j(2000,1,1)), &year, &month, &day);
|
||||
|
||||
#else
|
||||
|
||||
day = date->day;
|
||||
month = date->month;
|
||||
year = date->year;
|
||||
|
||||
#endif
|
||||
|
||||
if (EuroDates == 1) /* Output European-format dates */
|
||||
sprintf(buf, "%02d-%02d-%04d", day, month, year);
|
||||
else
|
||||
sprintf(buf, "%02d-%02d-%04d", month, day, year);
|
||||
|
||||
if (!PointerIsValid(result = PALLOC(strlen(buf)+1)))
|
||||
elog(WARN,"Memory allocation failed, can't output date",NULL);
|
||||
|
||||
strcpy( result, buf);
|
||||
|
||||
return(result);
|
||||
} /* date_out() */
|
||||
|
||||
#if USE_NEW_DATE
|
||||
|
||||
bool
|
||||
date_eq(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(dateVal1 == dateVal2);
|
||||
}
|
||||
|
||||
bool
|
||||
date_ne(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(dateVal1 != dateVal2);
|
||||
}
|
||||
|
||||
bool
|
||||
date_lt(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(dateVal1 < dateVal2);
|
||||
} /* date_lt() */
|
||||
|
||||
bool
|
||||
date_le(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(dateVal1 <= dateVal2);
|
||||
} /* date_le() */
|
||||
|
||||
bool
|
||||
date_gt(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(dateVal1 > dateVal2);
|
||||
} /* date_gt() */
|
||||
|
||||
bool
|
||||
date_ge(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(dateVal1 >= dateVal2);
|
||||
} /* date_ge() */
|
||||
|
||||
int
|
||||
date_cmp(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
if (dateVal1 < dateVal2) {
|
||||
return -1;
|
||||
} else if (dateVal1 > dateVal2) {
|
||||
return 1;
|
||||
};
|
||||
return 0;
|
||||
} /* date_cmp() */
|
||||
|
||||
DateADT
|
||||
date_larger(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(date_gt(dateVal1, dateVal2) ? dateVal1 : dateVal2);
|
||||
} /* date_larger() */
|
||||
|
||||
DateADT
|
||||
date_smaller(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(date_lt(dateVal1, dateVal2) ? dateVal1 : dateVal2);
|
||||
} /* date_smaller() */
|
||||
|
||||
/* Compute difference between two dates in days. */
|
||||
int4
|
||||
date_mi(DateADT dateVal1, DateADT dateVal2)
|
||||
{
|
||||
return(dateVal1-dateVal2);
|
||||
} /* date_mi() */
|
||||
|
||||
/* Add a number of days to a date, giving a new date.
|
||||
Must handle both positive and negative numbers of days. */
|
||||
DateADT
|
||||
date_pli(DateADT dateVal, int4 days)
|
||||
{
|
||||
return(dateVal+days);
|
||||
} /* date_pli() */
|
||||
|
||||
/* Subtract a number of days from a date, giving a new date. */
|
||||
DateADT
|
||||
date_mii(DateADT dateVal, int4 days)
|
||||
{
|
||||
return(date_pli(dateVal, -days));
|
||||
} /* date_mii() */
|
||||
|
||||
#else
|
||||
|
||||
bool
|
||||
date_eq(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
return (date1->day==date2->day &&
|
||||
date1->month==date2->month &&
|
||||
date1->year==date2->year);
|
||||
}
|
||||
|
||||
bool
|
||||
date_ne(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
return (date1->day!=date2->day || date1->month!=date2->month ||
|
||||
date1->year!=date2->year);
|
||||
}
|
||||
|
||||
bool
|
||||
date_lt(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return (date1->year<date2->year);
|
||||
if (date1->month!=date2->month)
|
||||
return (date1->month<date2->month);
|
||||
return (date1->day<date2->day);
|
||||
}
|
||||
|
||||
bool
|
||||
date_le(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return (date1->year<=date2->year);
|
||||
if (date1->month!=date2->month)
|
||||
return (date1->month<=date2->month);
|
||||
return (date1->day<=date2->day);
|
||||
}
|
||||
|
||||
bool
|
||||
date_gt(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return (date1->year>date2->year);
|
||||
if (date1->month!=date2->month)
|
||||
return (date1->month>date2->month);
|
||||
return (date1->day>date2->day);
|
||||
}
|
||||
|
||||
bool
|
||||
date_ge(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return (date1->year>=date2->year);
|
||||
if (date1->month!=date2->month)
|
||||
return (date1->month>=date2->month);
|
||||
return (date1->day>=date2->day);
|
||||
}
|
||||
|
||||
int
|
||||
date_cmp(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return ((date1->year<date2->year) ? -1 : 1);
|
||||
if (date1->month!=date2->month)
|
||||
return ((date1->month<date2->month) ? -1 : 1);
|
||||
if (date1->day!=date2->day)
|
||||
return ((date1->day<date2->day) ? -1 : 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int4
|
||||
date_larger(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
return (date_gt (dateVal1, dateVal2) ? dateVal1 : dateVal2);
|
||||
}
|
||||
|
||||
int4
|
||||
date_smaller(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
return (date_lt (dateVal1, dateVal2) ? dateVal1 : dateVal2);
|
||||
}
|
||||
|
||||
/* Compute difference between two dates in days. */
|
||||
int32
|
||||
date_mi(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
#if USE_NEW_TIME_CODE
|
||||
|
||||
DateADT *date1, *date2;
|
||||
int days;
|
||||
date1 = (DateADT *) &dateVal1;
|
||||
date2 = (DateADT *) &dateVal2;
|
||||
|
||||
days = (date2j(date1->year, date1->month, date1->day)
|
||||
- date2j(date2->year, date2->month, date2->day));
|
||||
|
||||
#else
|
||||
|
||||
DateADT dv1, dv2;
|
||||
DateADT *date1, *date2;
|
||||
int32 days = 0;
|
||||
int i;
|
||||
|
||||
/* This circumlocution allows us to assume that date1 is always
|
||||
before date2. */
|
||||
dv1 = date_smaller (dateVal1, dateVal2);
|
||||
dv2 = date_larger (dateVal1, dateVal2);
|
||||
date1 = (DateADT *) &dv1;
|
||||
date2 = (DateADT *) &dv2;
|
||||
|
||||
/* Sum number of days in each full year between date1 and date2. */
|
||||
for (i = date1->year + 1; i < date2->year; ++i)
|
||||
days += isleap(i) ? 366 : 365;
|
||||
|
||||
if (days)
|
||||
{
|
||||
/* We need to wrap around the year. Add in number of days in each
|
||||
full month from date1 to end of year. */
|
||||
for (i = date1->month + 1; i <= 12; ++i)
|
||||
days += day_tab[isleap(date1->year)][i - 1];
|
||||
|
||||
/* Add in number of days in each full month from start of year to
|
||||
date2. */
|
||||
for (i = 1; i < date2->month; ++i)
|
||||
days += day_tab[isleap(date2->year)][i - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add in number of days in each full month from date1 to date2. */
|
||||
for (i = date1->month + 1; i < date2->month; ++i)
|
||||
days += day_tab[isleap(date1->year)][i - 1];
|
||||
}
|
||||
|
||||
if (days || date1->month != date2->month)
|
||||
{
|
||||
/* Add in number of days left in month for date1. */
|
||||
days += day_tab[isleap(date1->year)][date1->month - 1] - date1->day;
|
||||
|
||||
/* Add in day of month of date2. */
|
||||
days += date2->day;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Everything's in the same month, so just subtract the days! */
|
||||
days = date2->day - date1->day;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return (days);
|
||||
}
|
||||
|
||||
/* Add a number of days to a date, giving a new date.
|
||||
Must handle both positive and negative numbers of days. */
|
||||
int4
|
||||
date_pli(int4 dateVal, int32 days)
|
||||
{
|
||||
#if USE_NEW_TIME_CODE
|
||||
|
||||
DateADT *date1 = (DateADT *) &dateVal;
|
||||
int date, year, month, day;
|
||||
|
||||
date = (date2j(date1->year, date1->month, date1->day) + days);
|
||||
j2date( date, &year, &month, &day);
|
||||
date1->year = year;
|
||||
date1->month = month;
|
||||
date1->day = day;
|
||||
|
||||
#else
|
||||
|
||||
DateADT *date1 = (DateADT *) &dateVal;
|
||||
/* Use separate day variable because date1->day is a narrow type. */
|
||||
int32 day = date1->day + days;
|
||||
|
||||
if (days > 0) {
|
||||
/* Loop as long as day has wrapped around end of month. */
|
||||
while (day > day_tab[isleap(date1->year)][date1->month - 1]) {
|
||||
day -= day_tab[isleap(date1->year)][date1->month - 1];
|
||||
if (++date1->month > 12) {
|
||||
/* Month wrapped around. */
|
||||
date1->month = 1;
|
||||
++date1->year;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Loop as long as day has wrapped around beginning of month. */
|
||||
while (day < 1) {
|
||||
/* Decrement month first, because a negative day number
|
||||
should be held as relative to the previous month's end. */
|
||||
if (--date1->month < 1) {
|
||||
/* Month wrapped around. */
|
||||
date1->month = 12;
|
||||
--date1->year;
|
||||
}
|
||||
|
||||
day += day_tab[isleap(date1->year)][date1->month - 1];
|
||||
}
|
||||
}
|
||||
date1->day = day;
|
||||
|
||||
#endif
|
||||
|
||||
return (dateVal);
|
||||
} /* date_pli() */
|
||||
|
||||
/* Subtract a number of days from a date, giving a new date. */
|
||||
int4
|
||||
date_mii(int4 dateVal, int32 days)
|
||||
{
|
||||
return (date_pli(dateVal, -days));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* Time ADT
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
TimeADT *
|
||||
time_in(char *str)
|
||||
{
|
||||
TimeADT *time;
|
||||
|
||||
double fsec;
|
||||
struct tm tt, *tm = &tt;
|
||||
|
||||
int nf;
|
||||
char lowstr[MAXDATELEN+1];
|
||||
char *field[MAXDATEFIELDS];
|
||||
int dtype;
|
||||
int ftype[MAXDATEFIELDS];
|
||||
|
||||
if (!PointerIsValid(str))
|
||||
elog(WARN,"Bad (null) time external representation",NULL);
|
||||
|
||||
if ((ParseDateTime( str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|
||||
|| (DecodeTimeOnly( field, ftype, nf, &dtype, tm, &fsec) != 0))
|
||||
elog(WARN,"Bad time external representation '%s'",str);
|
||||
|
||||
if ((tm->tm_hour < 0) || (tm->tm_hour > 23))
|
||||
elog(WARN,"Hour must be limited to values 0 through 23 in '%s'",str);
|
||||
if ((tm->tm_min < 0) || (tm->tm_min > 59))
|
||||
elog(WARN,"Minute must be limited to values 0 through 59 in '%s'",str);
|
||||
if ((tm->tm_sec < 0) || ((tm->tm_sec + fsec) >= 60))
|
||||
elog(WARN,"Second must be limited to values 0 through < 60 in '%s'",str);
|
||||
|
||||
if (!PointerIsValid(time = PALLOCTYPE(TimeADT)))
|
||||
elog(WARN,"Memory allocation failed, can't input time '%s'",str);
|
||||
|
||||
#if USE_NEW_TIME
|
||||
|
||||
*time = ((((tm->tm_hour*60)+tm->tm_min)*60)+tm->tm_sec+fsec);
|
||||
|
||||
#else
|
||||
|
||||
time->hr = tm->tm_hour;
|
||||
time->min = tm->tm_min;
|
||||
time->sec = (tm->tm_sec + fsec);
|
||||
|
||||
#endif
|
||||
|
||||
return(time);
|
||||
} /* time_in() */
|
||||
|
||||
|
||||
char *
|
||||
time_out(TimeADT *time)
|
||||
{
|
||||
char *result;
|
||||
char buf[32];
|
||||
|
||||
if (!PointerIsValid(time))
|
||||
return NULL;
|
||||
|
||||
if (time->sec == 0.0) {
|
||||
sprintf(buf, "%02d:%02d",
|
||||
(int)time->hr, (int)time->min);
|
||||
} else {
|
||||
if (((int) time->sec) == time->sec) {
|
||||
sprintf(buf, "%02d:%02d:%02d",
|
||||
(int)time->hr, (int)time->min, (int)time->sec);
|
||||
} else {
|
||||
sprintf(buf, "%02d:%02d:%09.6f",
|
||||
(int)time->hr, (int)time->min, time->sec);
|
||||
};
|
||||
};
|
||||
|
||||
if (!PointerIsValid(result = PALLOC(strlen(buf)+1)))
|
||||
elog(WARN,"Memory allocation failed, can't output time",NULL);
|
||||
|
||||
strcpy( result, buf);
|
||||
|
||||
return(result);
|
||||
} /* time_out() */
|
||||
|
||||
|
||||
#if USE_NEW_TIME
|
||||
|
||||
bool
|
||||
time_eq(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
||||
return(FALSE);
|
||||
|
||||
return(*time1 == *time2);
|
||||
} /* time_eq() */
|
||||
|
||||
bool
|
||||
time_ne(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
||||
return(FALSE);
|
||||
|
||||
return(*time1 != *time2);
|
||||
} /* time_eq() */
|
||||
|
||||
bool
|
||||
time_lt(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
||||
return(FALSE);
|
||||
|
||||
return(*time1 < *time2);
|
||||
} /* time_eq() */
|
||||
|
||||
bool
|
||||
time_le(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
||||
return(FALSE);
|
||||
|
||||
return(*time1 <= *time2);
|
||||
} /* time_eq() */
|
||||
|
||||
bool
|
||||
time_gt(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
||||
return(FALSE);
|
||||
|
||||
return(*time1 > *time2);
|
||||
} /* time_eq() */
|
||||
|
||||
bool
|
||||
time_ge(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
||||
return(FALSE);
|
||||
|
||||
return(*time1 >= *time2);
|
||||
} /* time_eq() */
|
||||
|
||||
int
|
||||
time_cmp(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
return((*time1 < *time2)? -1: (((*time1 < *time2)? 1: 0)));
|
||||
} /* time_cmp() */
|
||||
|
||||
#else
|
||||
|
||||
bool
|
||||
time_eq(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
return (time1->sec==time2->sec && time1->min==time2->min &&
|
||||
time1->hr==time2->hr);
|
||||
}
|
||||
|
||||
bool
|
||||
time_ne(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
return (time1->sec!=time2->sec || time1->min!=time2->min ||
|
||||
time1->hr!=time2->hr);
|
||||
}
|
||||
|
||||
bool
|
||||
time_lt(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return (time1->hr<time2->hr);
|
||||
if (time1->min!=time2->min)
|
||||
return (time1->min<time2->min);
|
||||
return (time1->sec<time2->sec);
|
||||
}
|
||||
|
||||
bool
|
||||
time_le(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return (time1->hr<=time2->hr);
|
||||
if (time1->min!=time2->min)
|
||||
return (time1->min<=time2->min);
|
||||
return (time1->sec<=time2->sec);
|
||||
}
|
||||
|
||||
bool
|
||||
time_gt(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return (time1->hr>time2->hr);
|
||||
if (time1->min!=time2->min)
|
||||
return (time1->min>time2->min);
|
||||
return (time1->sec>time2->sec);
|
||||
}
|
||||
|
||||
bool
|
||||
time_ge(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return (time1->hr>=time2->hr);
|
||||
if (time1->min!=time2->min)
|
||||
return (time1->min>=time2->min);
|
||||
return (time1->sec>=time2->sec);
|
||||
}
|
||||
|
||||
int
|
||||
time_cmp(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return ((time1->hr<time2->hr) ? -1 : 1);
|
||||
if (time1->min!=time2->min)
|
||||
return ((time1->min<time2->min) ? -1 : 1);
|
||||
if (time1->sec!=time2->sec)
|
||||
return ((time1->sec<time2->sec) ? -1 : 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int32 /* RelativeTime */
|
||||
int42reltime(int32 timevalue)
|
||||
{
|
||||
return(timevalue);
|
||||
}
|
|
@ -1,476 +0,0 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* datetimes.c--
|
||||
* implements DATE and TIME data types specified in SQL-92 standard
|
||||
*
|
||||
* Copyright (c) 1994-5, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.9 1997/03/02 02:05:33 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include <stdio.h> /* for sprintf() */
|
||||
#include <string.h>
|
||||
|
||||
#include <postgres.h>
|
||||
#include <miscadmin.h>
|
||||
#include <utils/builtins.h>
|
||||
#include <utils/datetime.h>
|
||||
|
||||
static int day_tab[2][12] = {
|
||||
{31,28,31,30,31,30,31,31,30,31,30,31},
|
||||
{31,29,31,30,31,30,31,31,30,31,30,31} };
|
||||
|
||||
static int
|
||||
isleap(int year)
|
||||
{
|
||||
return
|
||||
(((year % 4) == 0 && (year % 100) != 0) || (year % 400) == 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Date ADT
|
||||
*****************************************************************************/
|
||||
|
||||
int4
|
||||
date_in(char *datestr)
|
||||
{
|
||||
int d, m, y;
|
||||
int4 result;
|
||||
DateADT *date = (DateADT*)&result;
|
||||
|
||||
#if 0
|
||||
# ifdef USE_SHORT_YEAR
|
||||
# define CHECK_DATE_LEN(datestr) (strlen(datestr) >= 8)
|
||||
# else
|
||||
# define CHECK_DATE_LEN(datestr) (strlen(datestr) == 10)
|
||||
# endif /* USE_SHORT_YEAR */
|
||||
#else
|
||||
# define CHECK_DATE_LEN(datestr) 1
|
||||
#endif
|
||||
|
||||
if (EuroDates == 1) { /* Expect european format dates */
|
||||
if (!CHECK_DATE_LEN(datestr) ||
|
||||
sscanf(datestr, "%d%*c%d%*c%d", &d, &m, &y) != 3) {
|
||||
elog(WARN, "date_in: date \"%s\" not of the form dd-mm-yyyy",
|
||||
datestr);
|
||||
}
|
||||
} else {
|
||||
if (!CHECK_DATE_LEN(datestr) ||
|
||||
sscanf(datestr, "%d%*c%d%*c%d", &m, &d, &y) != 3) {
|
||||
elog(WARN, "date_in: date \"%s\" not of the form mm-dd-yyyy",
|
||||
datestr);
|
||||
}
|
||||
}
|
||||
if (y < 0 || y > 32767)
|
||||
elog(WARN, "date_in: year must be limited to values 0 through 32767 in \"%s\"", datestr);
|
||||
if (m < 1 || m > 12)
|
||||
elog(WARN, "date_in: month must be limited to values 1 through 12 in \"%s\"", datestr);
|
||||
if (d < 1 || d > day_tab[isleap(y)][m-1])
|
||||
elog(WARN, "date_in: day must be limited to values 1 through %d in \"%s\"",
|
||||
day_tab[isleap(y)][m-1], datestr);
|
||||
|
||||
#ifdef USE_SHORT_YEAR
|
||||
if (y < 100)
|
||||
y += 1900; /* hack! */
|
||||
#endif /* USE_SHORT_YEAR */
|
||||
|
||||
date->day = d;
|
||||
date->month = m;
|
||||
date->year = y;
|
||||
return result;
|
||||
}
|
||||
|
||||
char *
|
||||
date_out(int4 dateVal)
|
||||
{
|
||||
char *datestr = palloc(11);
|
||||
int4 dateStore;
|
||||
DateADT *date;
|
||||
|
||||
/* DateADT is a structure that happens to be four bytes long,
|
||||
trust me on this.... */
|
||||
date = (DateADT*)&dateStore;
|
||||
dateStore = dateVal;
|
||||
|
||||
if (EuroDates == 1) /* Output european format dates */
|
||||
sprintf(datestr, "%02d-%02d-%04d",
|
||||
(int)date->day, (int)date->month, (int)date->year);
|
||||
else
|
||||
sprintf(datestr, "%02d-%02d-%04d",
|
||||
(int)date->month, (int)date->day, (int)date->year);
|
||||
|
||||
return datestr;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
date_eq(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
return (date1->day==date2->day &&
|
||||
date1->month==date2->month &&
|
||||
date1->year==date2->year);
|
||||
}
|
||||
|
||||
int
|
||||
date_ne(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
return (date1->day!=date2->day || date1->month!=date2->month ||
|
||||
date1->year!=date2->year);
|
||||
}
|
||||
|
||||
int
|
||||
date_lt(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return (date1->year<date2->year);
|
||||
if (date1->month!=date2->month)
|
||||
return (date1->month<date2->month);
|
||||
return (date1->day<date2->day);
|
||||
}
|
||||
|
||||
int
|
||||
date_le(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return (date1->year<=date2->year);
|
||||
if (date1->month!=date2->month)
|
||||
return (date1->month<=date2->month);
|
||||
return (date1->day<=date2->day);
|
||||
}
|
||||
|
||||
int
|
||||
date_gt(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return (date1->year>date2->year);
|
||||
if (date1->month!=date2->month)
|
||||
return (date1->month>date2->month);
|
||||
return (date1->day>date2->day);
|
||||
}
|
||||
|
||||
int
|
||||
date_ge(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return (date1->year>=date2->year);
|
||||
if (date1->month!=date2->month)
|
||||
return (date1->month>=date2->month);
|
||||
return (date1->day>=date2->day);
|
||||
}
|
||||
|
||||
int
|
||||
date_cmp(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dateStore1 = dateVal1;
|
||||
int4 dateStore2 = dateVal2;
|
||||
DateADT *date1, *date2;
|
||||
|
||||
date1 = (DateADT*)&dateStore1;
|
||||
date2 = (DateADT*)&dateStore2;
|
||||
|
||||
if (date1->year!=date2->year)
|
||||
return ((date1->year<date2->year) ? -1 : 1);
|
||||
if (date1->month!=date2->month)
|
||||
return ((date1->month<date2->month) ? -1 : 1);
|
||||
if (date1->day!=date2->day)
|
||||
return ((date1->day<date2->day) ? -1 : 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int4
|
||||
date_larger(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
return (date_gt (dateVal1, dateVal2) ? dateVal1 : dateVal2);
|
||||
}
|
||||
|
||||
int4
|
||||
date_smaller(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
return (date_lt (dateVal1, dateVal2) ? dateVal1 : dateVal2);
|
||||
}
|
||||
|
||||
/* Compute difference between two dates in days. */
|
||||
int32
|
||||
date_mi(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
int4 dv1, dv2;
|
||||
DateADT *date1, *date2;
|
||||
int32 days = 0;
|
||||
int i;
|
||||
|
||||
/* This circumlocution allows us to assume that date1 is always
|
||||
before date2. */
|
||||
dv1 = date_smaller (dateVal1, dateVal2);
|
||||
dv2 = date_larger (dateVal1, dateVal2);
|
||||
date1 = (DateADT *) &dv1;
|
||||
date2 = (DateADT *) &dv2;
|
||||
|
||||
/* Sum number of days in each full year between date1 and date2. */
|
||||
for (i = date1->year + 1; i < date2->year; ++i)
|
||||
days += isleap (i) ? 366 : 365;
|
||||
|
||||
if (days)
|
||||
{
|
||||
/* We need to wrap around the year. Add in number of days in each
|
||||
full month from date1 to end of year. */
|
||||
for (i = date1->month + 1; i <= 12; ++i)
|
||||
days += day_tab[isleap (date1->year)][i - 1];
|
||||
|
||||
/* Add in number of days in each full month from start of year to
|
||||
date2. */
|
||||
for (i = 1; i < date2->month; ++i)
|
||||
days += day_tab[isleap (date2->year)][i - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add in number of days in each full month from date1 to date2. */
|
||||
for (i = date1->month + 1; i < date2->month; ++i)
|
||||
days += day_tab[isleap (date1->year)][i - 1];
|
||||
}
|
||||
|
||||
if (days || date1->month != date2->month)
|
||||
{
|
||||
/* Add in number of days left in month for date1. */
|
||||
days += day_tab[isleap (date1->year)][date1->month - 1] - date1->day;
|
||||
|
||||
/* Add in day of month of date2. */
|
||||
days += date2->day;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Everything's in the same month, so just subtract the days! */
|
||||
days = date2->day - date1->day;
|
||||
}
|
||||
|
||||
return (days);
|
||||
}
|
||||
|
||||
/* Add a number of days to a date, giving a new date.
|
||||
Must handle both positive and negative numbers of days. */
|
||||
int4
|
||||
date_pli(int4 dateVal, int32 days)
|
||||
{
|
||||
DateADT *date1 = (DateADT *) &dateVal;
|
||||
/* Use separate day variable because date1->day is a narrow type. */
|
||||
int32 day = date1->day + days;
|
||||
|
||||
if (days > 0)
|
||||
{
|
||||
/* Loop as long as day has wrapped around end of month. */
|
||||
while (day > day_tab[isleap (date1->year)][date1->month - 1])
|
||||
{
|
||||
day -= day_tab[isleap (date1->year)][date1->month - 1];
|
||||
if (++date1->month > 12)
|
||||
{
|
||||
/* Month wrapped around. */
|
||||
date1->month = 1;
|
||||
++date1->year;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Loop as long as day has wrapped around beginning of month. */
|
||||
while (day < 1)
|
||||
{
|
||||
/* Decrement month first, because a negative day number
|
||||
should be held as relative to the previous month's end. */
|
||||
if (--date1->month < 1)
|
||||
{
|
||||
/* Month wrapped around. */
|
||||
date1->month = 12;
|
||||
--date1->year;
|
||||
}
|
||||
|
||||
day += day_tab[isleap (date1->year)][date1->month - 1];
|
||||
}
|
||||
}
|
||||
date1->day = day;
|
||||
|
||||
return (dateVal);
|
||||
}
|
||||
|
||||
/* Subtract a number of days from a date, giving a new date. */
|
||||
int4
|
||||
date_mii(int4 dateVal, int32 days)
|
||||
{
|
||||
return (date_pli (dateVal, -days));
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Time ADT
|
||||
*****************************************************************************/
|
||||
|
||||
char *
|
||||
time_in(char *timestr)
|
||||
{
|
||||
int h, m;
|
||||
float sec;
|
||||
TimeADT *time;
|
||||
|
||||
if (sscanf(timestr, "%d%*c%d%*c%f", &h, &m, &sec) != 3) {
|
||||
sec = 0.0;
|
||||
if (sscanf(timestr, "%d%*c%d", &h, &m) != 2) {
|
||||
elog(WARN, "time_in: time \"%s\" not of the form hh:mm:ss",
|
||||
timestr);
|
||||
}
|
||||
}
|
||||
|
||||
if (h < 0 || h > 23)
|
||||
elog(WARN, "time_in: hour must be limited to values 0 through 23 in \"%s\"", timestr);
|
||||
if (m < 0 || m > 59)
|
||||
elog(WARN, "time_in: minute must be limited to values 0 through 59 in \"%s\"", timestr);
|
||||
if (sec < 0 || sec >= 60.0)
|
||||
elog(WARN, "time_in: second must be limited to values 0 through 59.999 in \"%s\"", timestr);
|
||||
|
||||
time = (TimeADT*)palloc(sizeof(TimeADT));
|
||||
time->hr = h;
|
||||
time->min = m;
|
||||
time->sec = sec;
|
||||
return (char*)time;
|
||||
}
|
||||
|
||||
char *
|
||||
time_out(TimeADT *time)
|
||||
{
|
||||
char *timestr = palloc(32);
|
||||
int n;
|
||||
float f;
|
||||
|
||||
if (time->sec == 0.0) {
|
||||
sprintf(timestr, "%02d:%02d",
|
||||
(int)time->hr, (int)time->min);
|
||||
} else {
|
||||
n = (int)time->sec;
|
||||
f = (float)n;
|
||||
if (f == time->sec) {
|
||||
sprintf(timestr, "%02d:%02d:%02d",
|
||||
(int)time->hr, (int)time->min, n);
|
||||
} else {
|
||||
sprintf(timestr, "%02d:%02d:%09.6f",
|
||||
(int)time->hr, (int)time->min, time->sec);
|
||||
}
|
||||
}
|
||||
|
||||
return timestr;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
time_eq(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
return (time1->sec==time2->sec && time1->min==time2->min &&
|
||||
time1->hr==time2->hr);
|
||||
}
|
||||
|
||||
int
|
||||
time_ne(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
return (time1->sec!=time2->sec || time1->min!=time2->min ||
|
||||
time1->hr!=time2->hr);
|
||||
}
|
||||
|
||||
int
|
||||
time_lt(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return (time1->hr<time2->hr);
|
||||
if (time1->min!=time2->min)
|
||||
return (time1->min<time2->min);
|
||||
return (time1->sec<time2->sec);
|
||||
}
|
||||
|
||||
int
|
||||
time_le(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return (time1->hr<=time2->hr);
|
||||
if (time1->min!=time2->min)
|
||||
return (time1->min<=time2->min);
|
||||
return (time1->sec<=time2->sec);
|
||||
}
|
||||
|
||||
int
|
||||
time_gt(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return (time1->hr>time2->hr);
|
||||
if (time1->min!=time2->min)
|
||||
return (time1->min>time2->min);
|
||||
return (time1->sec>time2->sec);
|
||||
}
|
||||
|
||||
int
|
||||
time_ge(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return (time1->hr>=time2->hr);
|
||||
if (time1->min!=time2->min)
|
||||
return (time1->min>=time2->min);
|
||||
return (time1->sec>=time2->sec);
|
||||
}
|
||||
|
||||
int
|
||||
time_cmp(TimeADT *time1, TimeADT *time2)
|
||||
{
|
||||
if (time1->hr!=time2->hr)
|
||||
return ((time1->hr<time2->hr) ? -1 : 1);
|
||||
if (time1->min!=time2->min)
|
||||
return ((time1->min<time2->min) ? -1 : 1);
|
||||
if (time1->sec!=time2->sec)
|
||||
return ((time1->sec<time2->sec) ? -1 : 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 /* RelativeTime */
|
||||
int42reltime(int32 timevalue)
|
||||
{
|
||||
return(timevalue);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.1 1997/03/09 20:40:55 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.2 1997/03/14 23:20:15 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/geo-decls.h"
|
||||
#include "utils/geo_decls.h"
|
||||
#include "utils/palloc.h"
|
||||
|
||||
#define LDELIM '('
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_selfuncs.c,v 1.1 1997/03/09 20:40:57 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_selfuncs.c,v 1.2 1997/03/14 23:20:20 scrappy Exp $
|
||||
*
|
||||
* XXX These are totally bogus.
|
||||
*
|
||||
|
@ -17,7 +17,7 @@
|
|||
#include "postgres.h"
|
||||
|
||||
#include "access/attnum.h"
|
||||
#include "utils/geo-decls.h" /* where function declarations go */
|
||||
#include "utils/geo_decls.h" /* where function declarations go */
|
||||
#include "utils/palloc.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.3 1996/11/06 10:30:55 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.4 1997/03/14 23:20:26 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -225,36 +225,36 @@ int16 i4toi2(int32 arg1)
|
|||
* intgt - returns 1 iff arg1 > arg2
|
||||
* intge - returns 1 iff arg1 >= arg2
|
||||
*/
|
||||
int32 int4eq(int32 arg1, int32 arg2) { return(arg1 == arg2); }
|
||||
int32 int4ne(int32 arg1, int32 arg2) { return(arg1 != arg2); }
|
||||
int32 int4lt(int32 arg1, int32 arg2) { return(arg1 < arg2); }
|
||||
int32 int4le(int32 arg1, int32 arg2) { return(arg1 <= arg2); }
|
||||
int32 int4gt(int32 arg1, int32 arg2) { return(arg1 > arg2); }
|
||||
int32 int4ge(int32 arg1, int32 arg2) { return(arg1 >= arg2); }
|
||||
bool int4eq(int32 arg1, int32 arg2) { return(arg1 == arg2); }
|
||||
bool int4ne(int32 arg1, int32 arg2) { return(arg1 != arg2); }
|
||||
bool int4lt(int32 arg1, int32 arg2) { return(arg1 < arg2); }
|
||||
bool int4le(int32 arg1, int32 arg2) { return(arg1 <= arg2); }
|
||||
bool int4gt(int32 arg1, int32 arg2) { return(arg1 > arg2); }
|
||||
bool int4ge(int32 arg1, int32 arg2) { return(arg1 >= arg2); }
|
||||
|
||||
int32 int2eq(int16 arg1, int16 arg2) { return(arg1 == arg2); }
|
||||
int32 int2ne(int16 arg1, int16 arg2) { return(arg1 != arg2); }
|
||||
int32 int2lt(int16 arg1, int16 arg2) { return(arg1 < arg2); }
|
||||
int32 int2le(int16 arg1, int16 arg2) { return(arg1 <= arg2); }
|
||||
int32 int2gt(int16 arg1, int16 arg2) { return(arg1 > arg2); }
|
||||
int32 int2ge(int16 arg1, int16 arg2) { return(arg1 >= arg2); }
|
||||
bool int2eq(int16 arg1, int16 arg2) { return(arg1 == arg2); }
|
||||
bool int2ne(int16 arg1, int16 arg2) { return(arg1 != arg2); }
|
||||
bool int2lt(int16 arg1, int16 arg2) { return(arg1 < arg2); }
|
||||
bool int2le(int16 arg1, int16 arg2) { return(arg1 <= arg2); }
|
||||
bool int2gt(int16 arg1, int16 arg2) { return(arg1 > arg2); }
|
||||
bool int2ge(int16 arg1, int16 arg2) { return(arg1 >= arg2); }
|
||||
|
||||
int32 int24eq(int32 arg1, int32 arg2) { return(arg1 == arg2); }
|
||||
int32 int24ne(int32 arg1, int32 arg2) { return(arg1 != arg2); }
|
||||
int32 int24lt(int32 arg1, int32 arg2) { return(arg1 < arg2); }
|
||||
int32 int24le(int32 arg1, int32 arg2) { return(arg1 <= arg2); }
|
||||
int32 int24gt(int32 arg1, int32 arg2) { return(arg1 > arg2); }
|
||||
int32 int24ge(int32 arg1, int32 arg2) { return(arg1 >= arg2); }
|
||||
bool int24eq(int32 arg1, int32 arg2) { return(arg1 == arg2); }
|
||||
bool int24ne(int32 arg1, int32 arg2) { return(arg1 != arg2); }
|
||||
bool int24lt(int32 arg1, int32 arg2) { return(arg1 < arg2); }
|
||||
bool int24le(int32 arg1, int32 arg2) { return(arg1 <= arg2); }
|
||||
bool int24gt(int32 arg1, int32 arg2) { return(arg1 > arg2); }
|
||||
bool int24ge(int32 arg1, int32 arg2) { return(arg1 >= arg2); }
|
||||
|
||||
int32 int42eq(int32 arg1, int32 arg2) { return(arg1 == arg2); }
|
||||
int32 int42ne(int32 arg1, int32 arg2) { return(arg1 != arg2); }
|
||||
int32 int42lt(int32 arg1, int32 arg2) { return(arg1 < arg2); }
|
||||
int32 int42le(int32 arg1, int32 arg2) { return(arg1 <= arg2); }
|
||||
int32 int42gt(int32 arg1, int32 arg2) { return(arg1 > arg2); }
|
||||
int32 int42ge(int32 arg1, int32 arg2) { return(arg1 >= arg2); }
|
||||
bool int42eq(int32 arg1, int32 arg2) { return(arg1 == arg2); }
|
||||
bool int42ne(int32 arg1, int32 arg2) { return(arg1 != arg2); }
|
||||
bool int42lt(int32 arg1, int32 arg2) { return(arg1 < arg2); }
|
||||
bool int42le(int32 arg1, int32 arg2) { return(arg1 <= arg2); }
|
||||
bool int42gt(int32 arg1, int32 arg2) { return(arg1 > arg2); }
|
||||
bool int42ge(int32 arg1, int32 arg2) { return(arg1 >= arg2); }
|
||||
|
||||
|
||||
int32 keyfirsteq(int16 *arg1, int16 arg2) { return(*arg1 == arg2); }
|
||||
bool keyfirsteq(int16 *arg1, int16 arg2) { return(*arg1 == arg2); }
|
||||
|
||||
/*
|
||||
* int[24]pl - returns arg1 + arg2
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.13 1997/01/27 01:51:21 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.14 1997/03/14 23:20:31 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -22,494 +22,174 @@
|
|||
#endif
|
||||
#include "access/xact.h"
|
||||
|
||||
#if USE_EURODATES
|
||||
extern int EuroDates;
|
||||
#endif
|
||||
|
||||
#if FALSE
|
||||
#define MAXDATELEN 47
|
||||
#define MAXDATEFIELDS 25
|
||||
#endif
|
||||
|
||||
#define ISSPACE(c) ((c) == ' ' || (c) == '\n' || (c) == '\t')
|
||||
|
||||
/* this is fast but dirty. note the return's in the middle. */
|
||||
#define GOBBLE_NUM(cp, c, x, ip) \
|
||||
(c) = *(cp)++; \
|
||||
if ((c) < '0' || (c) > '9') \
|
||||
return -1; /* missing digit */ \
|
||||
(x) = (c) - '0'; \
|
||||
(c) = *(cp)++; \
|
||||
if ((c) >= '0' && (c) <= '9') { \
|
||||
(x) = 10*(x) + (c) - '0'; \
|
||||
(c) = *(cp)++; \
|
||||
} \
|
||||
if ((c) != ':' && (c) != '\0' && !ISSPACE(c)) \
|
||||
return -1; /* missing colon */ \
|
||||
*(ip) = (x) /* N.B.: no semi-colon here */
|
||||
|
||||
#define EPOCH 1970
|
||||
#define DAYS_PER_400YRS (time_t)146097
|
||||
#define DAYS_PER_4YRS (time_t)1461
|
||||
#define SECS_PER_DAY 86400
|
||||
#define SECS_PER_HOUR 3600
|
||||
#define DIVBY4(n) ((n) >> 2)
|
||||
#define YRNUM(c, y) (DIVBY4(DAYS_PER_400YRS*(c)) + DIVBY4(DAYS_PER_4YRS*(y)))
|
||||
#define DAYNUM(c,y,mon,d) (YRNUM((c), (y)) + mdays[mon] + (d))
|
||||
#define EPOCH_DAYNUM DAYNUM(19, 69, 10, 1) /* really January 1, 1970 */
|
||||
#define MIN_DAYNUM -24856 /* December 13, 1901 */
|
||||
#define MAX_DAYNUM 24854 /* January 18, 2038 */
|
||||
|
||||
/* definitions for squeezing values into "value" */
|
||||
#define ABS_SIGNBIT 0200
|
||||
#define VALMASK 0177
|
||||
#define NEG(n) ((n)|ABS_SIGNBIT)
|
||||
#define SIGNEDCHAR(c) ((c)&ABS_SIGNBIT? -((c)&VALMASK): (c))
|
||||
#define FROMVAL(tp) (-SIGNEDCHAR((tp)->value) * 10) /* uncompress */
|
||||
#define TOVAL(tp, v) ((tp)->value = ((v) < 0? NEG((-(v))/10): (v)/10))
|
||||
#define IsLeapYear(yr) ((yr%4) == 0)
|
||||
|
||||
char nmdays[] = {
|
||||
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
};
|
||||
/* days since start of year. mdays[0] is March, mdays[11] is February */
|
||||
static short mdays[] = {
|
||||
0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337
|
||||
};
|
||||
|
||||
/* exports */
|
||||
static int dtok_numparsed;
|
||||
|
||||
/*
|
||||
* to keep this table reasonably small, we divide the lexval for TZ and DTZ
|
||||
* entries by 10 and truncate the text field at MAXTOKLEN characters.
|
||||
* the text field is not guaranteed to be NUL-terminated.
|
||||
*/
|
||||
static datetkn datetktbl[] = {
|
||||
/* text token lexval */
|
||||
{ "acsst", DTZ, 63}, /* Cent. Australia */
|
||||
{ "acst", TZ, 57}, /* Cent. Australia */
|
||||
{ "adt", DTZ, NEG(18)}, /* Atlantic Daylight Time */
|
||||
{ "aesst", DTZ, 66}, /* E. Australia */
|
||||
{ "aest", TZ, 60}, /* Australia Eastern Std Time */
|
||||
{ "ahst", TZ, 60}, /* Alaska-Hawaii Std Time */
|
||||
{ "am", AMPM, AM},
|
||||
{ "apr", MONTH, 4},
|
||||
{ "april", MONTH, 4},
|
||||
{ "ast", TZ, NEG(24)}, /* Atlantic Std Time (Canada) */
|
||||
{ "at", PG_IGNORE, 0}, /* "at" (throwaway) */
|
||||
{ "aug", MONTH, 8},
|
||||
{ "august", MONTH, 8},
|
||||
{ "awsst", DTZ, 54}, /* W. Australia */
|
||||
{ "awst", TZ, 48}, /* W. Australia */
|
||||
{ "bst", TZ, 6}, /* British Summer Time */
|
||||
{ "bt", TZ, 18}, /* Baghdad Time */
|
||||
{ "cadt", DTZ, 63}, /* Central Australian DST */
|
||||
{ "cast", TZ, 57}, /* Central Australian ST */
|
||||
{ "cat", TZ, NEG(60)}, /* Central Alaska Time */
|
||||
{ "cct", TZ, 48}, /* China Coast */
|
||||
{ "cdt", DTZ, NEG(30)}, /* Central Daylight Time */
|
||||
{ "cet", TZ, 6}, /* Central European Time */
|
||||
{ "cetdst", DTZ, 12}, /* Central European Dayl.Time */
|
||||
{ "cst", TZ, NEG(36)}, /* Central Standard Time */
|
||||
{ "dec", MONTH, 12},
|
||||
{ "decemb", MONTH, 12},
|
||||
{ "dnt", TZ, 6}, /* Dansk Normal Tid */
|
||||
{ "dst", PG_IGNORE, 0},
|
||||
{ "east", TZ, NEG(60)}, /* East Australian Std Time */
|
||||
{ "edt", DTZ, NEG(24)}, /* Eastern Daylight Time */
|
||||
{ "eet", TZ, 12}, /* East. Europe, USSR Zone 1 */
|
||||
{ "eetdst", DTZ, 18}, /* Eastern Europe */
|
||||
{ "est", TZ, NEG(30)}, /* Eastern Standard Time */
|
||||
{ "feb", MONTH, 2},
|
||||
{ "februa", MONTH, 2},
|
||||
{ "fri", PG_IGNORE, 5},
|
||||
{ "friday", PG_IGNORE, 5},
|
||||
{ "fst", TZ, 6}, /* French Summer Time */
|
||||
{ "fwt", DTZ, 12}, /* French Winter Time */
|
||||
{ "gmt", TZ, 0}, /* Greenwish Mean Time */
|
||||
{ "gst", TZ, 60}, /* Guam Std Time, USSR Zone 9 */
|
||||
{ "hdt", DTZ, NEG(54)}, /* Hawaii/Alaska */
|
||||
{ "hmt", DTZ, 18}, /* Hellas ? ? */
|
||||
{ "hst", TZ, NEG(60)}, /* Hawaii Std Time */
|
||||
{ "idle", TZ, 72}, /* Intl. Date Line, East */
|
||||
{ "idlw", TZ, NEG(72)}, /* Intl. Date Line, West */
|
||||
{ "ist", TZ, 12}, /* Israel */
|
||||
{ "it", TZ, 22}, /* Iran Time */
|
||||
{ "jan", MONTH, 1},
|
||||
{ "januar", MONTH, 1},
|
||||
{ "jst", TZ, 54}, /* Japan Std Time,USSR Zone 8 */
|
||||
{ "jt", TZ, 45}, /* Java Time */
|
||||
{ "jul", MONTH, 7},
|
||||
{ "july", MONTH, 7},
|
||||
{ "jun", MONTH, 6},
|
||||
{ "june", MONTH, 6},
|
||||
{ "kst", TZ, 54}, /* Korea Standard Time */
|
||||
{ "ligt", TZ, 60}, /* From Melbourne, Australia */
|
||||
{ "mar", MONTH, 3},
|
||||
{ "march", MONTH, 3},
|
||||
{ "may", MONTH, 5},
|
||||
{ "mdt", DTZ, NEG(36)}, /* Mountain Daylight Time */
|
||||
{ "mest", DTZ, 12}, /* Middle Europe Summer Time */
|
||||
{ "met", TZ, 6}, /* Middle Europe Time */
|
||||
{ "metdst", DTZ, 12}, /* Middle Europe Daylight Time*/
|
||||
{ "mewt", TZ, 6}, /* Middle Europe Winter Time */
|
||||
{ "mez", TZ, 6}, /* Middle Europe Zone */
|
||||
{ "mon", PG_IGNORE, 1},
|
||||
{ "monday", PG_IGNORE, 1},
|
||||
{ "mst", TZ, NEG(42)}, /* Mountain Standard Time */
|
||||
{ "mt", TZ, 51}, /* Moluccas Time */
|
||||
{ "ndt", DTZ, NEG(15)}, /* Nfld. Daylight Time */
|
||||
{ "nft", TZ, NEG(21)}, /* Newfoundland Standard Time */
|
||||
{ "nor", TZ, 6}, /* Norway Standard Time */
|
||||
{ "nov", MONTH, 11},
|
||||
{ "novemb", MONTH, 11},
|
||||
{ "nst", TZ, NEG(21)}, /* Nfld. Standard Time */
|
||||
{ "nt", TZ, NEG(66)}, /* Nome Time */
|
||||
{ "nzdt", DTZ, 78}, /* New Zealand Daylight Time */
|
||||
{ "nzst", TZ, 72}, /* New Zealand Standard Time */
|
||||
{ "nzt", TZ, 72}, /* New Zealand Time */
|
||||
{ "oct", MONTH, 10},
|
||||
{ "octobe", MONTH, 10},
|
||||
{ "on", PG_IGNORE, 0}, /* "on" (throwaway) */
|
||||
{ "pdt", DTZ, NEG(42)}, /* Pacific Daylight Time */
|
||||
{ "pm", AMPM, PM},
|
||||
{ "pst", TZ, NEG(48)}, /* Pacific Standard Time */
|
||||
{ "sadt", DTZ, 63}, /* S. Australian Dayl. Time */
|
||||
{ "sast", TZ, 57}, /* South Australian Std Time */
|
||||
{ "sat", PG_IGNORE, 6},
|
||||
{ "saturd", PG_IGNORE, 6},
|
||||
{ "sep", MONTH, 9},
|
||||
{ "sept", MONTH, 9},
|
||||
{ "septem", MONTH, 9},
|
||||
{ "set", TZ, NEG(6)}, /* Seychelles Time ?? */
|
||||
{ "sst", DTZ, 12}, /* Swedish Summer Time */
|
||||
{ "sun", PG_IGNORE, 0},
|
||||
{ "sunday", PG_IGNORE, 0},
|
||||
{ "swt", TZ, 6}, /* Swedish Winter Time */
|
||||
{ "thu", PG_IGNORE, 4},
|
||||
{ "thur", PG_IGNORE, 4},
|
||||
{ "thurs", PG_IGNORE, 4},
|
||||
{ "thursd", PG_IGNORE, 4},
|
||||
{ "tue", PG_IGNORE, 2},
|
||||
{ "tues", PG_IGNORE, 2},
|
||||
{ "tuesda", PG_IGNORE, 2},
|
||||
{ "ut", TZ, 0},
|
||||
{ "utc", TZ, 0},
|
||||
{ "wadt", DTZ, 48}, /* West Australian DST */
|
||||
{ "wast", TZ, 42}, /* West Australian Std Time */
|
||||
{ "wat", TZ, NEG(6)}, /* West Africa Time */
|
||||
{ "wdt", DTZ, 54}, /* West Australian DST */
|
||||
{ "wed", PG_IGNORE, 3},
|
||||
{ "wednes", PG_IGNORE, 3},
|
||||
{ "weds", PG_IGNORE, 3},
|
||||
{ "wet", TZ, 0}, /* Western Europe */
|
||||
{ "wetdst", DTZ, 6}, /* Western Europe */
|
||||
{ "wst", TZ, 48}, /* West Australian Std Time */
|
||||
{ "ydt", DTZ, NEG(48)}, /* Yukon Daylight Time */
|
||||
{ "yst", TZ, NEG(54)}, /* Yukon Standard Time */
|
||||
{ "zp4", TZ, NEG(24)}, /* GMT +4 hours. */
|
||||
{ "zp5", TZ, NEG(30)}, /* GMT +5 hours. */
|
||||
{ "zp6", TZ, NEG(36)}, /* GMT +6 hours. */
|
||||
};
|
||||
|
||||
static unsigned int szdatetktbl = sizeof datetktbl / sizeof datetktbl[0];
|
||||
|
||||
/*
|
||||
* parse and convert absolute date in timestr (the normal interface)
|
||||
*
|
||||
* Returns the number of seconds since epoch (January 1 1970 GMT)
|
||||
*/
|
||||
AbsoluteTime
|
||||
nabstimein(char* timestr)
|
||||
{
|
||||
int tz = 0;
|
||||
struct tm date;
|
||||
|
||||
if (!timestr)
|
||||
return INVALID_ABSTIME;
|
||||
while (ISSPACE(*timestr))
|
||||
++timestr;
|
||||
|
||||
if (!strcasecmp(timestr, "epoch"))
|
||||
return EPOCH_ABSTIME;
|
||||
if (!strcasecmp(timestr, "now"))
|
||||
return GetCurrentTransactionStartTime();
|
||||
if (!strcasecmp(timestr, "current"))
|
||||
return CURRENT_ABSTIME;
|
||||
if (!strcasecmp(timestr, "infinity"))
|
||||
return NOEND_ABSTIME;
|
||||
if (!strcasecmp(timestr, "-infinity"))
|
||||
return NOSTART_ABSTIME;
|
||||
if (prsabsdate(timestr, &date, &tz) < 0)
|
||||
return INVALID_ABSTIME;
|
||||
return dateconv(&date, tz);
|
||||
}
|
||||
|
||||
/*
|
||||
* just parse the absolute date in timestr and get back a broken-out date.
|
||||
*/
|
||||
int
|
||||
prsabsdate(char *timestr,
|
||||
struct tm *tm,
|
||||
int *tzp) /* - minutes west */
|
||||
{
|
||||
register int nf;
|
||||
char *fields[MAXDATEFIELDS];
|
||||
static char delims[] = "- \t\n/,";
|
||||
|
||||
nf = split(timestr, fields, MAXDATEFIELDS, delims+1);
|
||||
if (nf > MAXDATEFIELDS)
|
||||
return -1;
|
||||
if (tryabsdate(fields, nf, tm, tzp) < 0) {
|
||||
register char *p = timestr;
|
||||
|
||||
/*
|
||||
* could be a DEC-date; glue it all back together, split it
|
||||
* with dash as a delimiter and try again. Yes, this is a
|
||||
* hack, but so are DEC-dates.
|
||||
*/
|
||||
while (--nf > 0) {
|
||||
while (*p++ != '\0')
|
||||
;
|
||||
p[-1] = ' ';
|
||||
}
|
||||
nf = split(timestr, fields, MAXDATEFIELDS, delims);
|
||||
if (nf > MAXDATEFIELDS)
|
||||
return -1;
|
||||
if (tryabsdate(fields, nf, tm, tzp) < 0)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* try to parse pre-split timestr as an absolute date
|
||||
*/
|
||||
int
|
||||
tryabsdate(char *fields[], int nf, struct tm *tm, int *tzp)
|
||||
{
|
||||
register int i;
|
||||
register datetkn *tp;
|
||||
register long flg = 0, ty;
|
||||
int mer = HR24, bigval = -1;
|
||||
#ifndef USE_POSIX_TIME
|
||||
struct timeb now; /* the old V7-ism */
|
||||
long int timezone;
|
||||
long int daylight;
|
||||
#endif
|
||||
|
||||
AbsoluteTime
|
||||
GetCurrentAbsoluteTime(void)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
#ifdef USE_POSIX_TIME
|
||||
now = time(NULL);
|
||||
|
||||
(void) ftime(&now);
|
||||
*tzp = now.timezone;
|
||||
#else /* USE_POSIX_TIME */
|
||||
#if defined(HAVE_TZSET) && defined(HAVE_INT_TIMEZONE)
|
||||
tzset();
|
||||
#ifndef win32
|
||||
*tzp = timezone / 60; /* this is an X/Open-ism */
|
||||
#else
|
||||
*tzp = _timezone / 60; /* this is an X/Open-ism */
|
||||
#endif /* win32 */
|
||||
#else /* !HAVE_TZSET */
|
||||
time_t now = time((time_t *) NULL);
|
||||
struct tm *tmnow = localtime(&now);
|
||||
|
||||
*tzp = - tmnow->tm_gmtoff / 60; /* tm_gmtoff is Sun/DEC-ism */
|
||||
#endif
|
||||
timezone = - tmnow->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
|
||||
daylight = (tmnow->tm_isdst > 0);
|
||||
#endif
|
||||
|
||||
tm->tm_mday = tm->tm_mon = tm->tm_year = -1; /* mandatory */
|
||||
tm->tm_hour = tm->tm_min = tm->tm_sec = 0;
|
||||
tm->tm_isdst = -1; /* assume we don't know. */
|
||||
dtok_numparsed = 0;
|
||||
#else /* ! USE_POSIX_TIME */
|
||||
struct timeb tbnow; /* the old V7-ism */
|
||||
|
||||
for (i = 0; i < nf; i++) {
|
||||
if (fields[i][0] == '\0')
|
||||
continue;
|
||||
tp = datetoktype(fields[i], &bigval);
|
||||
ty = (1L << tp->type) & ~(1L << PG_IGNORE);
|
||||
if (flg&ty)
|
||||
return -1; /* repeated type */
|
||||
flg |= ty;
|
||||
switch (tp->type) {
|
||||
case YEAR:
|
||||
tm->tm_year = bigval;
|
||||
break;
|
||||
case DAY:
|
||||
tm->tm_mday = bigval;
|
||||
break;
|
||||
case MONTH:
|
||||
tm->tm_mon = tp->value;
|
||||
break;
|
||||
case TIME:
|
||||
if (parsetime(fields[i], tm) < 0)
|
||||
return -1;
|
||||
break;
|
||||
case DTZ:
|
||||
tm->tm_isdst++;
|
||||
/* FALLTHROUGH */
|
||||
case TZ:
|
||||
*tzp = FROMVAL(tp);
|
||||
break;
|
||||
case PG_IGNORE:
|
||||
break;
|
||||
case AMPM:
|
||||
mer = tp->value;
|
||||
break;
|
||||
default:
|
||||
return -1; /* bad token type: CANTHAPPEN */
|
||||
}
|
||||
}
|
||||
if (tm->tm_year == -1 || tm->tm_mon == -1 || tm->tm_mday == -1)
|
||||
return -1; /* missing component */
|
||||
if (mer == PM)
|
||||
tm->tm_hour += 12;
|
||||
return 0;
|
||||
}
|
||||
(void) ftime(&tbnow);
|
||||
now = tbnow.time;
|
||||
timezone = tbnow.timezone * 60;
|
||||
daylight = (tbnow.dstflag != 0);
|
||||
#endif
|
||||
|
||||
return((AbsoluteTime) now);
|
||||
} /* GetCurrentAbsoluteTime() */
|
||||
|
||||
|
||||
/* return -1 on failure */
|
||||
int
|
||||
parsetime(char *time, struct tm *tm)
|
||||
void
|
||||
GetCurrentTime(struct tm *tm)
|
||||
{
|
||||
register char c;
|
||||
register int x;
|
||||
time_t now;
|
||||
struct tm *tt;
|
||||
|
||||
tm->tm_sec = 0;
|
||||
GOBBLE_NUM(time, c, x, &tm->tm_hour);
|
||||
if (c != ':')
|
||||
return -1; /* only hour; too short */
|
||||
GOBBLE_NUM(time, c, x, &tm->tm_min);
|
||||
if (c != ':')
|
||||
return 0; /* no seconds; okay */
|
||||
GOBBLE_NUM(time, c, x, &tm->tm_sec);
|
||||
/* this may be considered too strict. garbage at end of time? */
|
||||
return (c == '\0' || ISSPACE(c)? 0: -1);
|
||||
}
|
||||
now = GetCurrentTransactionStartTime();
|
||||
tt = gmtime( &now);
|
||||
|
||||
tm->tm_year = tt->tm_year+1900;
|
||||
tm->tm_mon = tt->tm_mon+1;
|
||||
tm->tm_mday = tt->tm_mday;
|
||||
tm->tm_hour = tt->tm_hour;
|
||||
tm->tm_min = tt->tm_min;
|
||||
tm->tm_sec = tt->tm_sec;
|
||||
tm->tm_isdst = tt->tm_isdst;
|
||||
|
||||
return;
|
||||
} /* GetCurrentTime() */
|
||||
|
||||
|
||||
/*
|
||||
* split - divide a string into fields, like awk split()
|
||||
/* nabstimein()
|
||||
* Decode date/time string and return abstime.
|
||||
*/
|
||||
int /* number of fields, including overflow */
|
||||
split(char *string,
|
||||
char *fields[], /* list is not NULL-terminated */
|
||||
int nfields, /* number of entries available in fields[] */
|
||||
char *sep) /* "" white, "c" single char, "ab" [ab]+ */
|
||||
AbsoluteTime
|
||||
nabstimein(char* str)
|
||||
{
|
||||
register char *p = string;
|
||||
register char c; /* latest character */
|
||||
register char sepc = sep[0];
|
||||
register char sepc2;
|
||||
register int fn;
|
||||
register char **fp = fields;
|
||||
register char *sepp;
|
||||
register int trimtrail;
|
||||
int sec;
|
||||
double fsec;
|
||||
int day, tz = 0;
|
||||
struct tm date, *tm = &date;
|
||||
|
||||
/* white space */
|
||||
if (sepc == '\0') {
|
||||
while ((c = *p++) == ' ' || c == '\t')
|
||||
continue;
|
||||
p--;
|
||||
trimtrail = 1;
|
||||
sep = " \t"; /* note, code below knows this is 2 long */
|
||||
sepc = ' ';
|
||||
} else
|
||||
trimtrail = 0;
|
||||
sepc2 = sep[1]; /* now we can safely pick this up */
|
||||
char *field[MAXDATEFIELDS];
|
||||
char lowstr[MAXDATELEN+1];
|
||||
int dtype;
|
||||
int nf, ftype[MAXDATEFIELDS];
|
||||
|
||||
/* catch empties */
|
||||
if (*p == '\0')
|
||||
return(0);
|
||||
if (!PointerIsValid(str))
|
||||
elog(WARN,"Bad (null) abstime external representation",NULL);
|
||||
|
||||
/* single separator */
|
||||
if (sepc2 == '\0') {
|
||||
fn = nfields;
|
||||
for (;;) {
|
||||
*fp++ = p;
|
||||
fn--;
|
||||
if (fn == 0)
|
||||
break;
|
||||
while ((c = *p++) != sepc)
|
||||
if (c == '\0')
|
||||
return(nfields - fn);
|
||||
*(p-1) = '\0';
|
||||
}
|
||||
/* we have overflowed the fields vector -- just count them */
|
||||
fn = nfields;
|
||||
for (;;) {
|
||||
while ((c = *p++) != sepc)
|
||||
if (c == '\0')
|
||||
return(fn);
|
||||
fn++;
|
||||
}
|
||||
/* not reached */
|
||||
}
|
||||
if (strlen(str) > MAXDATELEN)
|
||||
elog( WARN, "Bad (length) abstime external representation '%s'",str);
|
||||
|
||||
/* two separators */
|
||||
if (sep[2] == '\0') {
|
||||
fn = nfields;
|
||||
for (;;) {
|
||||
*fp++ = p;
|
||||
fn--;
|
||||
while ((c = *p++) != sepc && c != sepc2)
|
||||
if (c == '\0') {
|
||||
if (trimtrail && **(fp-1) == '\0')
|
||||
fn++;
|
||||
return(nfields - fn);
|
||||
}
|
||||
if (fn == 0)
|
||||
break;
|
||||
*(p-1) = '\0';
|
||||
while ((c = *p++) == sepc || c == sepc2)
|
||||
continue;
|
||||
p--;
|
||||
}
|
||||
/* we have overflowed the fields vector -- just count them */
|
||||
fn = nfields;
|
||||
while (c != '\0') {
|
||||
while ((c = *p++) == sepc || c == sepc2)
|
||||
continue;
|
||||
p--;
|
||||
fn++;
|
||||
while ((c = *p++) != '\0' && c != sepc && c != sepc2)
|
||||
continue;
|
||||
}
|
||||
/* might have to trim trailing white space */
|
||||
if (trimtrail) {
|
||||
p--;
|
||||
while ((c = *--p) == sepc || c == sepc2)
|
||||
continue;
|
||||
p++;
|
||||
if (*p != '\0') {
|
||||
if (fn == nfields+1)
|
||||
*p = '\0';
|
||||
fn--;
|
||||
}
|
||||
}
|
||||
return(fn);
|
||||
}
|
||||
if ((ParseDateTime( str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|
||||
|| (DecodeDateTime( field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
|
||||
elog( WARN, "Bad abstime external representation '%s'",str);
|
||||
|
||||
/* n separators */
|
||||
fn = 0;
|
||||
for (;;) {
|
||||
if (fn < nfields)
|
||||
*fp++ = p;
|
||||
fn++;
|
||||
for (;;) {
|
||||
c = *p++;
|
||||
if (c == '\0')
|
||||
return(fn);
|
||||
sepp = sep;
|
||||
while ((sepc = *sepp++) != '\0' && sepc != c)
|
||||
continue;
|
||||
if (sepc != '\0') /* it was a separator */
|
||||
break;
|
||||
}
|
||||
if (fn < nfields)
|
||||
*(p-1) = '\0';
|
||||
for (;;) {
|
||||
c = *p++;
|
||||
sepp = sep;
|
||||
while ((sepc = *sepp++) != '\0' && sepc != c)
|
||||
continue;
|
||||
if (sepc == '\0') /* it wasn't a separator */
|
||||
break;
|
||||
}
|
||||
p--;
|
||||
}
|
||||
#ifdef DATEDEBUG
|
||||
printf( "nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE);
|
||||
#endif
|
||||
|
||||
switch (dtype) {
|
||||
case DTK_DATE:
|
||||
#if FALSE
|
||||
return(dateconv( &date, tz));
|
||||
#endif
|
||||
/* validate, before going out of range on some members */
|
||||
if (tm->tm_year < 1901 || tm->tm_year > 2038
|
||||
|| tm->tm_mon < 1 || tm->tm_mon > 12
|
||||
|| tm->tm_mday < 1 || tm->tm_mday > 31
|
||||
|| tm->tm_hour < 0 || tm->tm_hour >= 24
|
||||
|| tm->tm_min < 0 || tm->tm_min > 59
|
||||
|| tm->tm_sec < 0 || tm->tm_sec > 59)
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
day = (date2j( tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j( 1970, 1, 1));
|
||||
|
||||
/* check for time out of range */
|
||||
if ((day < MIN_DAYNUM) || (day > MAX_DAYNUM))
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
/* convert to seconds */
|
||||
sec = tm->tm_sec + tz + (tm->tm_min +(day*24 + tm->tm_hour)*60)*60;
|
||||
|
||||
/* check for overflow */
|
||||
if ((day == MAX_DAYNUM && sec < 0) ||
|
||||
(day == MIN_DAYNUM && sec > 0))
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
/* daylight correction */
|
||||
if (tm->tm_isdst < 0) { /* unknown; find out */
|
||||
tm->tm_isdst = (daylight > 0);
|
||||
};
|
||||
if (tm->tm_isdst > 0)
|
||||
sec -= 60*60;
|
||||
|
||||
/* check for reserved values (e.g. "current" on edge of usual range */
|
||||
if (!AbsoluteTimeIsReal(sec))
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
return sec;
|
||||
|
||||
case DTK_EPOCH:
|
||||
return EPOCH_ABSTIME;
|
||||
|
||||
case DTK_CURRENT:
|
||||
return CURRENT_ABSTIME;
|
||||
|
||||
case DTK_LATE:
|
||||
return NOEND_ABSTIME;
|
||||
|
||||
case DTK_EARLY:
|
||||
return NOSTART_ABSTIME;
|
||||
|
||||
case DTK_INVALID:
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
default:
|
||||
};
|
||||
|
||||
elog(WARN,"Bad abstime (internal coding error) '%s'",str);
|
||||
return INVALID_ABSTIME;
|
||||
} /* nabstimein() */
|
||||
|
||||
/* not reached */
|
||||
}
|
||||
|
||||
/*
|
||||
* Given an AbsoluteTime return the English text version of the date
|
||||
|
@ -529,11 +209,11 @@ nabstimeout(AbsoluteTime time)
|
|||
char* result;
|
||||
|
||||
switch (time) {
|
||||
case EPOCH_ABSTIME: (void) strcpy(buf, "epoch"); break;
|
||||
case INVALID_ABSTIME: (void) strcpy(buf, "Invalid Abstime"); break;
|
||||
case CURRENT_ABSTIME: (void) strcpy(buf, "current"); break;
|
||||
case NOEND_ABSTIME: (void) strcpy(buf, "infinity"); break;
|
||||
case NOSTART_ABSTIME: (void) strcpy(buf, "-infinity"); break;
|
||||
case EPOCH_ABSTIME: (void) strcpy(buf, EPOCH); break;
|
||||
case INVALID_ABSTIME: (void) strcpy(buf, INVALID); break;
|
||||
case CURRENT_ABSTIME: (void) strcpy(buf, DCURRENT); break;
|
||||
case NOEND_ABSTIME: (void) strcpy(buf, LATE); break;
|
||||
case NOSTART_ABSTIME: (void) strcpy(buf, EARLY); break;
|
||||
default:
|
||||
/* hack -- localtime happens to work for negative times */
|
||||
(void) strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z",
|
||||
|
@ -545,24 +225,35 @@ nabstimeout(AbsoluteTime time)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* turn a (struct tm) and a few variables into a time_t, with range checking */
|
||||
AbsoluteTime
|
||||
dateconv(register struct tm *tm, int zone)
|
||||
{
|
||||
tm->tm_wday = tm->tm_yday = 0;
|
||||
|
||||
#if FALSE
|
||||
if (tm->tm_year < 70) {
|
||||
tm->tm_year += 2000;
|
||||
} else if (tm->tm_year < 1000) {
|
||||
tm->tm_year += 1900;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* validate, before going out of range on some members */
|
||||
if (tm->tm_year < 0 || tm->tm_mon < 1 || tm->tm_mon > 12 ||
|
||||
tm->tm_mday < 1 || tm->tm_hour < 0 || tm->tm_hour >= 24 ||
|
||||
tm->tm_min < 0 || tm->tm_min > 59 ||
|
||||
tm->tm_sec < 0 || tm->tm_sec > 59)
|
||||
return -1;
|
||||
if (tm->tm_year < 1901 || tm->tm_year > 2038
|
||||
|| tm->tm_mon < 1 || tm->tm_mon > 12
|
||||
|| tm->tm_mday < 1 || tm->tm_mday > 31
|
||||
|| tm->tm_hour < 0 || tm->tm_hour >= 24
|
||||
|| tm->tm_min < 0 || tm->tm_min > 59
|
||||
|| tm->tm_sec < 0 || tm->tm_sec > 59)
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
/*
|
||||
* zone should really be -zone, and tz should be set to tp->value, not
|
||||
* -tp->value. Or the table could be fixed.
|
||||
*/
|
||||
tm->tm_min += zone; /* mktime lets it be out of range */
|
||||
tm->tm_sec += zone; /* mktime lets it be out of range */
|
||||
|
||||
/* convert to seconds */
|
||||
return qmktime(tm);
|
||||
|
@ -575,182 +266,62 @@ dateconv(register struct tm *tm, int zone)
|
|||
* and tm_yday.
|
||||
*/
|
||||
time_t
|
||||
qmktime(struct tm *tp)
|
||||
qmktime(struct tm *tm)
|
||||
{
|
||||
register int mon = tp->tm_mon;
|
||||
register int day = tp->tm_mday, year = tp->tm_year;
|
||||
register time_t daynum;
|
||||
time_t secondnum;
|
||||
register int century;
|
||||
time_t sec;
|
||||
|
||||
int day;
|
||||
|
||||
#if FALSE
|
||||
/* If it was a 2 digit year */
|
||||
if (year < 100)
|
||||
year += 1900;
|
||||
if (tm->tm_year < 100)
|
||||
tm->tm_year += 1900;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* validate day against days-per-month table, with leap-year
|
||||
* correction
|
||||
*/
|
||||
if (day > nmdays[mon])
|
||||
if (mon != 2 ||
|
||||
(year % 4 == 0 &&
|
||||
((year % 100 != 0 || year % 400 == 0)) && day > 29))
|
||||
return -1; /* day too large for month */
|
||||
|
||||
/* split year into century and year-of-century */
|
||||
century = year / 100;
|
||||
year %= 100;
|
||||
/*
|
||||
* We calculate the day number exactly, assuming the calendar has
|
||||
* always had the current leap year rules. (The leap year rules are
|
||||
* to compensate for the fact that the Earth's revolution around the
|
||||
* Sun takes 365.2425 days). We first need to rotate months so March
|
||||
* is 0, since we want the last month to have the reduced number of
|
||||
* days.
|
||||
*/
|
||||
if (mon > 2)
|
||||
mon -= 3;
|
||||
else {
|
||||
mon += 9;
|
||||
if (year == 0) {
|
||||
century--;
|
||||
year = 99;
|
||||
} else
|
||||
--year;
|
||||
}
|
||||
daynum = -EPOCH_DAYNUM + DAYNUM(century, year, mon, day);
|
||||
day = (date2j( tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j( 1970, 1, 1));
|
||||
|
||||
/* check for time out of range */
|
||||
if (daynum < MIN_DAYNUM || daynum > MAX_DAYNUM)
|
||||
if ((day < MIN_DAYNUM) || (day > MAX_DAYNUM))
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
/* convert to seconds */
|
||||
secondnum =
|
||||
tp->tm_sec + (tp->tm_min +(daynum*24 + tp->tm_hour)*60)*60;
|
||||
sec = tm->tm_sec + (tm->tm_min +(day*24 + tm->tm_hour)*60)*60;
|
||||
|
||||
/* check for overflow */
|
||||
if ((daynum == MAX_DAYNUM && secondnum < 0) ||
|
||||
(daynum == MIN_DAYNUM && secondnum > 0))
|
||||
if ((day == MAX_DAYNUM && sec < 0) ||
|
||||
(day == MIN_DAYNUM && sec > 0))
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
/* check for "current", "infinity", "-infinity" */
|
||||
if (!AbsoluteTimeIsReal(secondnum))
|
||||
/* check for reserved values (e.g. "current" on edge of usual range */
|
||||
if (!AbsoluteTimeIsReal(sec))
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
/* daylight correction */
|
||||
if (tp->tm_isdst < 0) /* unknown; find out */
|
||||
{
|
||||
struct tm *result;
|
||||
if (tm->tm_isdst < 0) { /* unknown; find out */
|
||||
tm->tm_isdst = (daylight > 0);
|
||||
};
|
||||
if (tm->tm_isdst > 0)
|
||||
sec -= 60*60;
|
||||
|
||||
/* NT returns NULL for any time before 1/1/70 */
|
||||
result = localtime(&secondnum);
|
||||
if (result == NULL)
|
||||
return INVALID_ABSTIME;
|
||||
else
|
||||
tp->tm_isdst = result->tm_isdst;
|
||||
}
|
||||
if (tp->tm_isdst > 0)
|
||||
secondnum -= 60*60;
|
||||
|
||||
return secondnum;
|
||||
}
|
||||
|
||||
datetkn *
|
||||
datetoktype(char *s, int *bigvalp)
|
||||
{
|
||||
register char *cp = s;
|
||||
register char c = *cp;
|
||||
static datetkn t;
|
||||
register datetkn *tp = &t;
|
||||
|
||||
if (isascii(c) && isdigit(c)) {
|
||||
register int len = strlen(cp);
|
||||
|
||||
if (len > 3 && (cp[1] == ':' || cp[2] == ':'))
|
||||
tp->type = TIME;
|
||||
else {
|
||||
if (bigvalp != NULL)
|
||||
/* won't fit in tp->value */
|
||||
*bigvalp = atoi(cp);
|
||||
if (len == 4)
|
||||
tp->type = YEAR;
|
||||
else if (++dtok_numparsed == 1)
|
||||
tp->type = DAY;
|
||||
else
|
||||
tp->type = YEAR;
|
||||
}
|
||||
} else if (c == '-' || c == '+') {
|
||||
register int val = atoi(cp + 1);
|
||||
register int hr = val / 100;
|
||||
register int min = val % 100;
|
||||
|
||||
val = hr*60 + min;
|
||||
if (c == '-')
|
||||
val = -val;
|
||||
tp->type = TZ;
|
||||
TOVAL(tp, val);
|
||||
} else {
|
||||
char lowtoken[TOKMAXLEN+1];
|
||||
register char *ltp = lowtoken, *endltp = lowtoken+TOKMAXLEN;
|
||||
|
||||
/* copy to lowtoken to avoid modifying s */
|
||||
while ((c = *cp++) != '\0' && ltp < endltp)
|
||||
*ltp++ = (isascii(c) && isupper(c)? tolower(c): c);
|
||||
*ltp = '\0';
|
||||
tp = datebsearch(lowtoken, datetktbl, szdatetktbl);
|
||||
if (tp == NULL) {
|
||||
tp = &t;
|
||||
tp->type = PG_IGNORE;
|
||||
}
|
||||
}
|
||||
return tp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Binary search -- from Knuth (6.2.1) Algorithm B. Special case like this
|
||||
* is WAY faster than the generic bsearch().
|
||||
*/
|
||||
datetkn *
|
||||
datebsearch(char *key, datetkn *base, unsigned int nel)
|
||||
{
|
||||
register datetkn *last = base + nel - 1, *position;
|
||||
register int result;
|
||||
|
||||
while (last >= base) {
|
||||
position = base + ((last - base) >> 1);
|
||||
result = key[0] - position->token[0];
|
||||
if (result == 0) {
|
||||
result = strncmp(key, position->token, TOKMAXLEN);
|
||||
if (result == 0)
|
||||
return position;
|
||||
}
|
||||
if (result < 0)
|
||||
last = position - 1;
|
||||
else
|
||||
base = position + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return sec;
|
||||
} /* qmktime() */
|
||||
|
||||
|
||||
/*
|
||||
* AbsoluteTimeIsBefore -- true iff time1 is before time2.
|
||||
* AbsoluteTimeIsBefore -- true iff time1 is after time2.
|
||||
*/
|
||||
|
||||
bool
|
||||
AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2)
|
||||
{
|
||||
AbsoluteTime tm = GetCurrentTransactionStartTime();
|
||||
|
||||
Assert(AbsoluteTimeIsValid(time1));
|
||||
Assert(AbsoluteTimeIsValid(time2));
|
||||
|
||||
if ((time1 == CURRENT_ABSTIME) || (time2 == CURRENT_ABSTIME))
|
||||
return false;
|
||||
if (time1 == CURRENT_ABSTIME)
|
||||
return (tm < time2);
|
||||
time1 = GetCurrentTransactionStartTime();
|
||||
|
||||
if (time2 == CURRENT_ABSTIME)
|
||||
return (time1 < tm);
|
||||
time2 = GetCurrentTransactionStartTime();
|
||||
|
||||
return (time1 < time2);
|
||||
}
|
||||
|
@ -758,17 +329,14 @@ AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2)
|
|||
bool
|
||||
AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2)
|
||||
{
|
||||
AbsoluteTime tm = GetCurrentTransactionStartTime();
|
||||
|
||||
Assert(AbsoluteTimeIsValid(time1));
|
||||
Assert(AbsoluteTimeIsValid(time2));
|
||||
|
||||
if ((time1 == CURRENT_ABSTIME) || (time2 == CURRENT_ABSTIME))
|
||||
return false;
|
||||
if (time1 == CURRENT_ABSTIME)
|
||||
return (tm > time2);
|
||||
time1 = GetCurrentTransactionStartTime();
|
||||
|
||||
if (time2 == CURRENT_ABSTIME)
|
||||
return (time1 > tm);
|
||||
time2 = GetCurrentTransactionStartTime();
|
||||
|
||||
return (time1 > time2);
|
||||
}
|
||||
|
@ -781,9 +349,8 @@ AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2)
|
|||
* abstimegt - returns 1, iff t1 greater than t2
|
||||
* abstimele - returns 1, iff t1 less than or equal to t2
|
||||
* abstimege - returns 1, iff t1 greater than or equal to t2
|
||||
*
|
||||
*/
|
||||
int32
|
||||
bool
|
||||
abstimeeq(AbsoluteTime t1, AbsoluteTime t2)
|
||||
{
|
||||
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
||||
|
@ -796,7 +363,7 @@ abstimeeq(AbsoluteTime t1, AbsoluteTime t2)
|
|||
return(t1 == t2);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
abstimene(AbsoluteTime t1, AbsoluteTime t2)
|
||||
{
|
||||
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
||||
|
@ -809,7 +376,7 @@ abstimene(AbsoluteTime t1, AbsoluteTime t2)
|
|||
return(t1 != t2);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
abstimelt(AbsoluteTime t1, AbsoluteTime t2)
|
||||
{
|
||||
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
||||
|
@ -822,7 +389,7 @@ abstimelt(AbsoluteTime t1, AbsoluteTime t2)
|
|||
return(t1 < t2);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
abstimegt(AbsoluteTime t1, AbsoluteTime t2)
|
||||
{
|
||||
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
||||
|
@ -835,7 +402,7 @@ abstimegt(AbsoluteTime t1, AbsoluteTime t2)
|
|||
return(t1 > t2);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
abstimele(AbsoluteTime t1, AbsoluteTime t2)
|
||||
{
|
||||
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
||||
|
@ -848,7 +415,7 @@ abstimele(AbsoluteTime t1, AbsoluteTime t2)
|
|||
return(t1 <= t2);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
abstimege(AbsoluteTime t1, AbsoluteTime t2)
|
||||
{
|
||||
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
||||
|
@ -860,5 +427,3 @@ abstimege(AbsoluteTime t1, AbsoluteTime t2)
|
|||
|
||||
return(t1 >= t2);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.1.1.1 1996/07/09 06:22:04 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.2 1997/03/14 23:20:43 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -74,49 +74,49 @@ char *nameout(NameData *s)
|
|||
* namege - returns 1 iff a <= b
|
||||
*
|
||||
*/
|
||||
int32 nameeq(NameData *arg1, NameData *arg2)
|
||||
bool nameeq(NameData *arg1, NameData *arg2)
|
||||
{
|
||||
if (!arg1 || !arg2)
|
||||
return 0;
|
||||
else
|
||||
return (strncmp(arg1->data, arg2->data, NAMEDATALEN) == 0);
|
||||
return ((bool) strncmp(arg1->data, arg2->data, NAMEDATALEN) == 0);
|
||||
}
|
||||
|
||||
int32 namene(NameData *arg1, NameData *arg2)
|
||||
bool namene(NameData *arg1, NameData *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return(strncmp(arg1->data, arg2->data, NAMEDATALEN) != 0);
|
||||
return((bool) 0);
|
||||
return((bool) (strncmp(arg1->data, arg2->data, NAMEDATALEN) != 0));
|
||||
}
|
||||
|
||||
int32 namelt(NameData *arg1, NameData *arg2)
|
||||
bool namelt(NameData *arg1, NameData *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((int32) (strncmp(arg1->data, arg2->data, NAMEDATALEN) < 0));
|
||||
return((bool) 0);
|
||||
return((bool) (strncmp(arg1->data, arg2->data, NAMEDATALEN) < 0));
|
||||
}
|
||||
|
||||
int32 namele(NameData *arg1, NameData *arg2)
|
||||
bool namele(NameData *arg1, NameData *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((int32) (strncmp(arg1->data, arg2->data, NAMEDATALEN) <= 0));
|
||||
return((bool) 0);
|
||||
return((bool) (strncmp(arg1->data, arg2->data, NAMEDATALEN) <= 0));
|
||||
}
|
||||
|
||||
int32 namegt(NameData *arg1, NameData *arg2)
|
||||
bool namegt(NameData *arg1, NameData *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
|
||||
return((int32) (strncmp(arg1->data, arg2->data, NAMEDATALEN) > 0));
|
||||
return((bool) (strncmp(arg1->data, arg2->data, NAMEDATALEN) > 0));
|
||||
}
|
||||
|
||||
int32 namege(NameData *arg1, NameData *arg2)
|
||||
bool namege(NameData *arg1, NameData *arg2)
|
||||
{
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
|
||||
return((int32) (strncmp(arg1->data, arg2->data, NAMEDATALEN) >= 0));
|
||||
return((bool) (strncmp(arg1->data, arg2->data, NAMEDATALEN) >= 0));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.5 1997/03/12 21:09:15 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.6 1997/03/14 23:20:52 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -100,19 +100,19 @@ char *oidout(Oid o)
|
|||
* PUBLIC ROUTINES *
|
||||
*****************************************************************************/
|
||||
|
||||
int32 oideq(Oid arg1, Oid arg2)
|
||||
bool oideq(Oid arg1, Oid arg2)
|
||||
{
|
||||
return(arg1 == arg2);
|
||||
}
|
||||
|
||||
int32 oidne(Oid arg1, Oid arg2)
|
||||
bool oidne(Oid arg1, Oid arg2)
|
||||
{
|
||||
return(arg1 != arg2);
|
||||
}
|
||||
|
||||
int32 oid8eq(Oid arg1[], Oid arg2[])
|
||||
bool oid8eq(Oid arg1[], Oid arg2[])
|
||||
{
|
||||
return (int32)(memcmp(arg1, arg2, 8 * sizeof(Oid)) == 0);
|
||||
return (bool)(memcmp(arg1, arg2, 8 * sizeof(Oid)) == 0);
|
||||
}
|
||||
|
||||
bool oideqint4(Oid arg1, int32 arg2)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.6 1996/11/10 03:03:20 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.7 1997/03/14 23:21:01 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -180,13 +180,13 @@ bcTruelen(char *arg)
|
|||
return (i+1);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
bpchareq(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = bcTruelen(arg1);
|
||||
len2 = bcTruelen(arg2);
|
||||
|
||||
|
@ -196,13 +196,13 @@ bpchareq(char *arg1, char *arg2)
|
|||
return(strncmp(arg1+4, arg2+4, len1) == 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
bpcharne(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = bcTruelen(arg1);
|
||||
len2 = bcTruelen(arg2);
|
||||
|
||||
|
@ -212,14 +212,14 @@ bpcharne(char *arg1, char *arg2)
|
|||
return(strncmp(arg1+4, arg2+4, len1) != 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
bpcharlt(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
int cmp;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = bcTruelen(arg1);
|
||||
len2 = bcTruelen(arg2);
|
||||
|
||||
|
@ -230,32 +230,32 @@ bpcharlt(char *arg1, char *arg2)
|
|||
return (cmp < 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
bpcharle(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
int cmp;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = bcTruelen(arg1);
|
||||
len2 = bcTruelen(arg2);
|
||||
|
||||
cmp = strncmp(arg1+4, arg2+4, Min(len1,len2));
|
||||
if (0 == cmp)
|
||||
return (int32)(len1 <= len2 ? 1 : 0);
|
||||
return (bool)(len1 <= len2 ? 1 : 0);
|
||||
else
|
||||
return (int32)(cmp <= 0);
|
||||
return (bool)(cmp <= 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
bpchargt(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
int cmp;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = bcTruelen(arg1);
|
||||
len2 = bcTruelen(arg2);
|
||||
|
||||
|
@ -266,22 +266,22 @@ bpchargt(char *arg1, char *arg2)
|
|||
return (cmp > 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
bpcharge(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
int cmp;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = bcTruelen(arg1);
|
||||
len2 = bcTruelen(arg2);
|
||||
|
||||
cmp = strncmp(arg1+4, arg2+4, Min(len1,len2));
|
||||
if (0 == cmp)
|
||||
return (int32)(len1 >= len2 ? 1 : 0);
|
||||
return (bool)(len1 >= len2 ? 1 : 0);
|
||||
else
|
||||
return (int32)(cmp >= 0);
|
||||
return (bool)(cmp >= 0);
|
||||
}
|
||||
|
||||
int32
|
||||
|
@ -319,13 +319,13 @@ vcTruelen(char *arg)
|
|||
return i;
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
varchareq(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = vcTruelen(arg1);
|
||||
len2 = vcTruelen(arg2);
|
||||
|
||||
|
@ -335,13 +335,13 @@ varchareq(char *arg1, char *arg2)
|
|||
return(strncmp(arg1+4, arg2+4, len1) == 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
varcharne(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = vcTruelen(arg1);
|
||||
len2 = vcTruelen(arg2);
|
||||
|
||||
|
@ -351,14 +351,14 @@ varcharne(char *arg1, char *arg2)
|
|||
return(strncmp(arg1+4, arg2+4, len1) != 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
varcharlt(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
int cmp;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = vcTruelen(arg1);
|
||||
len2 = vcTruelen(arg2);
|
||||
|
||||
|
@ -369,32 +369,32 @@ varcharlt(char *arg1, char *arg2)
|
|||
return (cmp < 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
varcharle(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
int cmp;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = vcTruelen(arg1);
|
||||
len2 = vcTruelen(arg2);
|
||||
|
||||
cmp = strncmp(arg1+4, arg2+4, Min(len1,len2));
|
||||
if (0 == cmp)
|
||||
return (int32)( len1 <= len2 ? 1 : 0);
|
||||
return (bool)( len1 <= len2 ? 1 : 0);
|
||||
else
|
||||
return (int32)(cmp <= 0);
|
||||
return (bool)(cmp <= 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
varchargt(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
int cmp;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = vcTruelen(arg1);
|
||||
len2 = vcTruelen(arg2);
|
||||
|
||||
|
@ -405,22 +405,22 @@ varchargt(char *arg1, char *arg2)
|
|||
return (cmp > 0);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
varcharge(char *arg1, char *arg2)
|
||||
{
|
||||
int len1, len2;
|
||||
int cmp;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
len1 = vcTruelen(arg1);
|
||||
len2 = vcTruelen(arg2);
|
||||
|
||||
cmp = strncmp(arg1+4, arg2+4, Min(len1,len2));
|
||||
if (0 == cmp)
|
||||
return (int32)(len1 >= len2 ? 1 : 0);
|
||||
return (bool)(len1 >= len2 ? 1 : 0);
|
||||
else
|
||||
return (int32)(cmp >= 0);
|
||||
return (bool)(cmp >= 0);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.10 1997/01/16 03:53:51 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.11 1997/03/14 23:21:12 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -255,16 +255,16 @@ textcat(text* t1, text* t2)
|
|||
* texteq - returns 1 iff arguments are equal
|
||||
* textne - returns 1 iff arguments are not equal
|
||||
*/
|
||||
int32
|
||||
bool
|
||||
texteq(struct varlena *arg1, struct varlena *arg2)
|
||||
{
|
||||
register int len;
|
||||
register char *a1p, *a2p;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) NULL);
|
||||
return((bool) NULL);
|
||||
if ((len = arg1->vl_len) != arg2->vl_len)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
a1p = arg1->vl_dat;
|
||||
a2p = arg2->vl_dat;
|
||||
/*
|
||||
|
@ -275,17 +275,17 @@ texteq(struct varlena *arg1, struct varlena *arg2)
|
|||
len -= sizeof(int32);
|
||||
while (len-- != 0)
|
||||
if (*a1p++ != *a2p++)
|
||||
return((int32) 0);
|
||||
return((int32) 1);
|
||||
return((bool) 0);
|
||||
return((bool) 1);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
textne(struct varlena *arg1, struct varlena *arg2)
|
||||
{
|
||||
return((int32) !texteq(arg1, arg2));
|
||||
return((bool) !texteq(arg1, arg2));
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
text_lt(struct varlena *arg1, struct varlena *arg2)
|
||||
{
|
||||
int len;
|
||||
|
@ -295,7 +295,7 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
|
|||
char *a1p, *a2p;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
|
||||
a1p = (unsigned char *)VARDATA(arg1);
|
||||
a2p = (unsigned char *)VARDATA(arg2);
|
||||
|
@ -311,12 +311,12 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
|
|||
len--;
|
||||
}
|
||||
if (len)
|
||||
return (int32) (*a1p < *a2p);
|
||||
return (bool) (*a1p < *a2p);
|
||||
else
|
||||
return (int32) (arg1->vl_len < arg2->vl_len);
|
||||
return (bool) (arg1->vl_len < arg2->vl_len);
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
text_le(struct varlena *arg1, struct varlena *arg2)
|
||||
{
|
||||
int len;
|
||||
|
@ -326,7 +326,7 @@ text_le(struct varlena *arg1, struct varlena *arg2)
|
|||
char *a1p, *a2p;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return((int32) 0);
|
||||
return((bool) 0);
|
||||
|
||||
a1p = (unsigned char *)VARDATA(arg1);
|
||||
a2p = (unsigned char *)VARDATA(arg2);
|
||||
|
@ -342,21 +342,21 @@ text_le(struct varlena *arg1, struct varlena *arg2)
|
|||
len--;
|
||||
}
|
||||
if (len)
|
||||
return (int32) (*a1p < *a2p);
|
||||
return (bool) (*a1p < *a2p);
|
||||
else
|
||||
return ((int32) VARSIZE(arg1) <= VARSIZE(arg2));
|
||||
return ((bool) VARSIZE(arg1) <= VARSIZE(arg2));
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
text_gt(struct varlena *arg1, struct varlena *arg2)
|
||||
{
|
||||
return ((int32) !text_le(arg1, arg2));
|
||||
return ((bool) !text_le(arg1, arg2));
|
||||
}
|
||||
|
||||
int32
|
||||
bool
|
||||
text_ge(struct varlena *arg1, struct varlena *arg2)
|
||||
{
|
||||
return ((int32) !text_lt(arg1, arg2));
|
||||
return ((bool) !text_lt(arg1, arg2));
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue