From 427a964c302dd6ec2359eb4a8318303b09bc9363 Mon Sep 17 00:00:00 2001
From: "Marc G. Fournier" <scrappy@hub.org>
Date: Sun, 26 Jan 1997 17:28:48 +0000
Subject: [PATCH] |From: Keith Parks <emkxp01@mtcc.demon.co.uk> |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 | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/backend/parser/sysfunc.c b/src/backend/parser/sysfunc.c
index 18e3c5afe54..fac1b60fd5a 100644
--- a/src/backend/parser/sysfunc.c
+++ b/src/backend/parser/sysfunc.c
@@ -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*";
 }
 
-- 
GitLab