diff options
Diffstat (limited to 'src/extend/datetime')
-rw-r--r-- | src/extend/datetime/datetime_functions.c | 147 | ||||
-rw-r--r-- | src/extend/datetime/datetime_functions.doc | 25 | ||||
-rw-r--r-- | src/extend/datetime/datetime_functions.sql | 69 |
3 files changed, 0 insertions, 241 deletions
diff --git a/src/extend/datetime/datetime_functions.c b/src/extend/datetime/datetime_functions.c deleted file mode 100644 index dc1fec8bd20..00000000000 --- a/src/extend/datetime/datetime_functions.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * datetime_functions.c -- - * - * This file defines new functions for the time and date data types. - * - * Copyright (c) 1996, Massimo Dal Zotto <dz@cs.unitn.it> - */ - -#include <time.h> - -#include "postgres.h" -#include "pg_type.h" -#include "utils/palloc.h" - -typedef struct DateADT { - char day; - char month; - short year; -} DateADT; - -typedef struct TimeADT { - short hr; - short min; - float sec; -} TimeADT; - -TimeADT * -time_difference(TimeADT *time1, TimeADT *time2) -{ - TimeADT *time = (TimeADT*)palloc(sizeof(TimeADT)); - - time->sec = time1->sec - time2->sec; - time->min = time1->min - time2->min; - time->hr = time1->hr - time2->hr; - - if (time->sec < 0) { - time->sec += 60.0; - time->min--; - } else if (time->sec >= 60.0) { - time->sec -= 60.0; - time->min++; - } - - if (time->min < 0) { - time->min += 60; - time->hr--; - } else if (time->min >= 60) { - time->min -= 60; - time->hr++; - } - - if (time->hr < 0) { - time->hr += 24; - } else if (time->hr >= 24) { - time->hr -= 24; - } - - return (time); -} - -TimeADT * -currentTime() -{ - time_t current_time; - struct tm *tm; - TimeADT *result = (TimeADT*)palloc(sizeof(TimeADT)); - - current_time = time(NULL); - tm = localtime(¤t_time); - result->sec = tm->tm_sec; - result->min = tm->tm_min; - result->hr = tm->tm_hour; - - return (result); -} - -int4 -currentDate() -{ - time_t current_time; - struct tm *tm; - int4 result; - DateADT *date = (DateADT*)&result; - - current_time = time(NULL); - tm = localtime(¤t_time); - date->day = tm->tm_mday; - date->month = tm->tm_mon+1; - date->year = tm->tm_year+1900; - - return (result); -} - -int4 -hours(TimeADT *time) -{ - return (time->hr); -} - -int4 -minutes(TimeADT *time) -{ - return (time->min); -} - -int4 -seconds(TimeADT *time) -{ - int seconds = (int)time->sec; - return (seconds); -} - -int4 -day(int4 val) -{ - DateADT *date = (DateADT*)&val; - return (date->day); -} - -int4 -month(int4 val) -{ - DateADT *date = (DateADT*)&val; - return (date->month); -} - -int4 -year(int4 val) -{ - DateADT *date = (DateADT*)&val; - return (date->year); -} - -int4 -asMinutes(TimeADT *time) -{ - int seconds = (int)time->sec; - return (time->min + 60*time->hr); -} - -int4 -asSeconds(TimeADT *time) -{ - int seconds = (int)time->sec; - return (seconds + 60*time->min + 3600*time->hr); -} - diff --git a/src/extend/datetime/datetime_functions.doc b/src/extend/datetime/datetime_functions.doc deleted file mode 100644 index 0c7a01819a5..00000000000 --- a/src/extend/datetime/datetime_functions.doc +++ /dev/null @@ -1,25 +0,0 @@ -From: Massimo Dal Zotto <dz@cs.unitn.it> -Date: Tue, 14 May 1996 14:31:18 +0200 (MET DST) -Subject: [PG95]: new postgres functions - -- -----BEGIN PGP SIGNED MESSAGE----- - -Some time ago I read in the mailing list requests of people looking -for more time and date functions. I have now written some of them: - - time_difference(time1, time2) ,also defined as operator '-' - hour(time) - minutes(time) - seconds(time) - asMinutes(time) - asSeconds(time) - currentTime() - currentDate() - -The file can be compiled as shared library and loaded as dynamic module -without need to recompile the backend. This can also be taken as an example -of the extensibility of postgres (user-defined functions, operators, etc). -I would be nice to see more of these user contributed modules posted to this -list and hopefully accessible from the Postgres home page. - - diff --git a/src/extend/datetime/datetime_functions.sql b/src/extend/datetime/datetime_functions.sql deleted file mode 100644 index 2e50a4a19fd..00000000000 --- a/src/extend/datetime/datetime_functions.sql +++ /dev/null @@ -1,69 +0,0 @@ - --- SQL code to load and define 'datetime' functions - --- load the new functions - -load '/home/dz/lib/postgres/datetime_functions.so'; - --- define the new functions in postgres - -create function time_difference(time,time) - returns time - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function currentDate() - returns date - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function currentTime() - returns time - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function hours(time) - returns int4 - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function minutes(time) - returns int4 - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function seconds(time) - returns int4 - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function day(date) - returns int4 - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function month(date) - returns int4 - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function year(date) - returns int4 - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function asMinutes(time) - returns int4 - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create function asSeconds(time) - returns int4 - as '/home/dz/lib/postgres/datetime_functions.so' - language 'c'; - -create operator - ( - leftarg=time, - rightarg=time, - procedure=time_difference); - |