1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-22 21:53:06 +03:00
Subject: [HACKERS] More date time functions

Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).

I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.

These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).

The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
This commit is contained in:
Marc G. Fournier
1997-04-02 18:36:24 +00:00
parent 920c58df71
commit 2ab34dfe1a
12 changed files with 997 additions and 340 deletions

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.6 1997/03/14 23:19:57 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.7 1997/04/02 18:33:09 scrappy Exp $
*
* NOTES
* This code is actually (almost) unused.
@@ -32,15 +32,14 @@
#include "postgres.h"
#include "miscadmin.h"
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#include "access/xact.h"
#include "utils/builtins.h" /* where function declarations go */
#include "utils/palloc.h"
#include "utils/dt.h"
#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)
#define RELTIME_LABEL '@'
@@ -235,6 +234,55 @@ char *tintervalout(TimeInterval interval)
* PUBLIC ROUTINES *
*****************************************************************************/
RelativeTime
timespan_reltime(TimeSpan *timespan)
{
RelativeTime time;
double span;
if (!PointerIsValid(timespan))
time = INVALID_RELTIME;
if (TIMESPAN_IS_INVALID(*timespan)) {
time = INVALID_RELTIME;
} else {
span = ((((double) 30*86400)*timespan->month) + timespan->time);
#ifdef DATEDEBUG
printf( "timespan_reltime- convert m%d s%f to %f [%d %d]\n",
timespan->month, timespan->time, span, INT_MIN, INT_MAX);
#endif
time = (((span > INT_MIN) && (span < INT_MAX))? span: INVALID_RELTIME);
};
return(time);
} /* timespan_reltime() */
TimeSpan *
reltime_timespan(RelativeTime reltime)
{
TimeSpan *result;
if (!PointerIsValid(result = PALLOCTYPE(TimeSpan)))
elog(WARN,"Memory allocation failed, can't convert reltime to timespan",NULL);
switch(reltime) {
case INVALID_RELTIME:
TIMESPAN_INVALID(*result);
break;
default:
result->time = reltime;
result->month = 0;
};
return(result);
} /* reltime_timespan() */
/*
* mktinterval - creates a time interval with endpoints t1 and t2
*/