|
9 | 9 | *
|
10 | 10 | *
|
11 | 11 | * IDENTIFICATION
|
12 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.6 1997/03/14 23:19:57 scrappy Exp $ |
| 12 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.7 1997/04/02 18:33:09 scrappy Exp $ |
13 | 13 | *
|
14 | 14 | * NOTES
|
15 | 15 | * This code is actually (almost) unused.
|
|
32 | 32 |
|
33 | 33 | #include "postgres.h"
|
34 | 34 | #include "miscadmin.h"
|
| 35 | +#ifdef HAVE_LIMITS_H |
| 36 | +# include <limits.h> |
| 37 | +#endif |
35 | 38 | #include "access/xact.h"
|
36 | 39 | #include "utils/builtins.h" /* where function declarations go */
|
37 | 40 | #include "utils/palloc.h"
|
38 | 41 | #include "utils/dt.h"
|
39 | 42 |
|
40 |
| -#ifndef USE_NEW_TIME_CODE |
41 |
| -#define USE_NEW_TIME_CODE 1 |
42 |
| -#endif |
43 |
| - |
44 | 43 | #define INVALID_RELTIME_STR "Undefined RelTime"
|
45 | 44 | #define INVALID_RELTIME_STR_LEN (sizeof(INVALID_RELTIME_STR)-1)
|
46 | 45 | #define RELTIME_LABEL '@'
|
@@ -235,6 +234,55 @@ char *tintervalout(TimeInterval interval)
|
235 | 234 | * PUBLIC ROUTINES *
|
236 | 235 | *****************************************************************************/
|
237 | 236 |
|
| 237 | +RelativeTime |
| 238 | +timespan_reltime(TimeSpan *timespan) |
| 239 | +{ |
| 240 | + RelativeTime time; |
| 241 | + double span; |
| 242 | + |
| 243 | + if (!PointerIsValid(timespan)) |
| 244 | + time = INVALID_RELTIME; |
| 245 | + |
| 246 | + if (TIMESPAN_IS_INVALID(*timespan)) { |
| 247 | + time = INVALID_RELTIME; |
| 248 | + |
| 249 | + } else { |
| 250 | + span = ((((double) 30*86400)*timespan->month) + timespan->time); |
| 251 | + |
| 252 | +#ifdef DATEDEBUG |
| 253 | +printf( "timespan_reltime- convert m%d s%f to %f [%d %d]\n", |
| 254 | + timespan->month, timespan->time, span, INT_MIN, INT_MAX); |
| 255 | +#endif |
| 256 | + |
| 257 | + time = (((span > INT_MIN) && (span < INT_MAX))? span: INVALID_RELTIME); |
| 258 | + }; |
| 259 | + |
| 260 | + return(time); |
| 261 | +} /* timespan_reltime() */ |
| 262 | + |
| 263 | + |
| 264 | +TimeSpan * |
| 265 | +reltime_timespan(RelativeTime reltime) |
| 266 | +{ |
| 267 | + TimeSpan *result; |
| 268 | + |
| 269 | + if (!PointerIsValid(result = PALLOCTYPE(TimeSpan))) |
| 270 | + elog(WARN,"Memory allocation failed, can't convert reltime to timespan",NULL); |
| 271 | + |
| 272 | + switch(reltime) { |
| 273 | + case INVALID_RELTIME: |
| 274 | + TIMESPAN_INVALID(*result); |
| 275 | + break; |
| 276 | + |
| 277 | + default: |
| 278 | + result->time = reltime; |
| 279 | + result->month = 0; |
| 280 | + }; |
| 281 | + |
| 282 | + return(result); |
| 283 | +} /* reltime_timespan() */ |
| 284 | + |
| 285 | + |
238 | 286 | /*
|
239 | 287 | * mktinterval - creates a time interval with endpoints t1 and t2
|
240 | 288 | */
|
|
0 commit comments