OSDN Git Service

|From: Keith Parks <emkxp01@mtcc.demon.co.uk>
authorMarc G. Fournier <scrappy@hub.org>
Sun, 26 Jan 1997 17:28:48 +0000 (17:28 +0000)
committerMarc G. Fournier <scrappy@hub.org>
Sun, 26 Jan 1997 17:28:48 +0000 (17:28 +0000)
|Subject: [PATCH] adding SYS_TIME just for fun.
|
|Hi,
|
|Whilst I was playing round with the European dates patch I noticed the sysfunc()
|that allows you to do :-
|
|create table test ( da date);
|insert into test values (SYS_DATE);
|
|and have the current system date inserted.
|
|So I thought it would be nice to have the SYS_TIME facility too.
|
|I've cloned the function and changed a few things and there you have it,
|you can now do:
|
|create table test2 ( ti time);
|insert into test2 values (SYS_TIME);

src/backend/parser/sysfunc.c

index 18e3c5a..fac1b60 100644 (file)
@@ -45,10 +45,26 @@ static char *Sysfunc_system_date(void)
        return &buf[0];
 }
 
+static char *Sysfunc_system_time(void)
+{
+       time_t  cur_time_secs;
+       struct  tm *cur_time_expanded;
+       static  char buf[10]; /* Just for safety, y'understand... */
+       
+       time(&cur_time_secs);
+       cur_time_expanded = localtime(&cur_time_secs);
+       sprintf(buf, "%2.2d:%2.2d:%2.2d", cur_time_expanded->tm_hour,
+               cur_time_expanded->tm_min, cur_time_expanded->tm_sec);
+
+       return &buf[0];
+}
+
 char *SystemFunctionHandler(char *funct)
 {
        if (!strcmp(funct, "SYS_DATE"))
                return Sysfunc_system_date();
+       if (!strcmp(funct, "SYS_TIME"))
+               return Sysfunc_system_time();
        return "*unknown function*";
 }