diff options
author | Thomas G. Lockhart <lockhart@fourpalms.org> | 2000-04-07 13:40:45 +0000 |
---|---|---|
committer | Thomas G. Lockhart <lockhart@fourpalms.org> | 2000-04-07 13:40:45 +0000 |
commit | a349733bbbeaca5aa5b0b3520963b01a455c9ff8 (patch) | |
tree | 75b3222de81890c5fafb91eee0b0f920716d6df4 /src/backend/utils/adt/timestamp.c | |
parent | 1b992b468bc5fef62f5a1470f382c70311e9d162 (diff) | |
download | postgresql-a349733bbbeaca5aa5b0b3520963b01a455c9ff8.tar.gz postgresql-a349733bbbeaca5aa5b0b3520963b01a455c9ff8.zip |
Add transcendental math functions (sine, cosine, etc)
Add a random number generator and seed setter (random(), SET SEED)
Fix up the interval*float8 math to carry partial months
into the time field.
Add float8*interval so we have symmetry in the available math.
Fix the parser and define.c to accept SQL92 types as field arguments.
Fix the parser to accept SQL92 types for CREATE TYPE, etc. This is
necessary to allow...
Bit/varbit support in contrib/bit cleaned up to compile and load
cleanly. Still needs some work before final release.
Implement the "SOME" keyword as a synonym for "ANY" per SQL92.
Implement ascii(text), ichar(int4), repeat(text,int4) to help
support the ODBC driver.
Enable the TRUNCATE() function mapping in the ODBC driver.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 111 |
1 files changed, 38 insertions, 73 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 4086a803dd7..7a94ddd804d 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.23 2000/03/14 23:06:37 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.24 2000/04/07 13:39:41 thomas Exp $ * *------------------------------------------------------------------------- */ @@ -32,72 +32,6 @@ #include "utils/builtins.h" -#if 0 - - -static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm); -static int DecodeNumber(int flen, char *field, - int fmask, int *tmask, struct tm * tm, double *fsec, int *is2digits); -static int DecodeNumberField(int len, char *str, - int fmask, int *tmask, struct tm * tm, double *fsec, int *is2digits); -static int DecodeSpecial(int field, char *lowtoken, int *val); -static int DecodeTime(char *str, int fmask, int *tmask, - struct tm * tm, double *fsec); -static int DecodeTimezone(char *str, int *tzp); -static int DecodeUnits(int field, char *lowtoken, int *val); -static int EncodeSpecialTimestamp(Timestamp dt, char *str); -static datetkn *datebsearch(char *key, datetkn *base, unsigned int nel); -static Timestamp dt2local(Timestamp dt, int timezone); -static int j2day(int jd); -static double time2t(const int hour, const int min, const double sec); -static int interval2tm(Interval span, struct tm * tm, float8 *fsec); -static int tm2interval(struct tm * tm, double fsec, Interval *span); - - -#define USE_DATE_CACHE 1 -#define ROUND_ALL 0 - -int day_tab[2][13] = { - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}, -{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}}; - - -char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", -"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL}; - -char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", -"Thursday", "Friday", "Saturday", NULL}; - -/* TMODULO() - * Macro to replace modf(), which is broken on some platforms. - */ -#define TMODULO(t,q,u) \ -do { \ - q = ((t < 0)? ceil(t / u): floor(t / u)); \ - if (q != 0) \ - t -= rint(q * u); \ -} while(0) - -static void GetEpochTime(struct tm * tm); - -#define UTIME_MINYEAR (1901) -#define UTIME_MINMONTH (12) -#define UTIME_MINDAY (14) -#define UTIME_MAXYEAR (2038) -#define UTIME_MAXMONTH (01) -#define UTIME_MAXDAY (18) - -#define IS_VALID_UTIME(y,m,d) (((y > UTIME_MINYEAR) \ - || ((y == UTIME_MINYEAR) && ((m > UTIME_MINMONTH) \ - || ((m == UTIME_MINMONTH) && (d >= UTIME_MINDAY))))) \ - && ((y < UTIME_MAXYEAR) \ - || ((y == UTIME_MAXYEAR) && ((m < UTIME_MAXMONTH) \ - || ((m == UTIME_MAXMONTH) && (d <= UTIME_MAXDAY)))))) - - -#endif - - static double time2t(const int hour, const int min, const double sec); @@ -1334,21 +1268,52 @@ interval_mi(Interval *span1, Interval *span2) } /* interval_mi() */ Interval * -interval_div(Interval *span1, float8 *arg2) +interval_mul(Interval *span1, float8 *factor) +{ + Interval *result; + double months; + + if ((!PointerIsValid(span1)) || (!PointerIsValid(factor))) + return NULL; + + if (!PointerIsValid(result = palloc(sizeof(Interval)))) + elog(ERROR, "Memory allocation failed, can't multiply interval"); + + months = (span1->month * *factor); + result->month = rint(months); + result->time = JROUND(span1->time * *factor); + /* evaluate fractional months as 30 days */ + result->time += JROUND((months - result->month) * 30 * 86400); + + return result; +} /* interval_mul() */ + +Interval * +mul_d_interval(float8 *factor, Interval *span1) +{ + return interval_mul(span1, factor); +} /* mul_d_interval() */ + +Interval * +interval_div(Interval *span1, float8 *factor) { Interval *result; + double months; - if ((!PointerIsValid(span1)) || (!PointerIsValid(arg2))) + if ((!PointerIsValid(span1)) || (!PointerIsValid(factor))) return NULL; if (!PointerIsValid(result = palloc(sizeof(Interval)))) - elog(ERROR, "Memory allocation failed, can't divide intervals"); + elog(ERROR, "Memory allocation failed, can't divide interval"); - if (*arg2 == 0.0) + if (*factor == 0.0) elog(ERROR, "interval_div: divide by 0.0 error"); - result->month = rint(span1->month / *arg2); - result->time = JROUND(span1->time / *arg2); + months = (span1->month / *factor); + result->month = rint(months); + result->time = JROUND(span1->time / *factor); + /* evaluate fractional months as 30 days */ + result->time += JROUND((months - result->month) * 30 * 86400); return result; } /* interval_div() */ |