mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Move timeofday() implementation out of nabstime.c.
nabstime.c is about to be removed, but timeofday() isn't related to the rest of the functionality therein, and some find it useful. Move to timestamp.c. Discussion: https://postgr.es/m/20181009192237.34wjp3nmw7oynmmr@alap3.anarazel.de https://postgr.es/m/20180928223240.kgwc4czzzekrpsid%40alap3.anarazel.de
This commit is contained in:
@ -1609,6 +1609,26 @@ GetSQLLocalTimestamp(int32 typmod)
|
||||
return ts;
|
||||
}
|
||||
|
||||
/*
|
||||
* timeofday(*) -- returns the current time as a text.
|
||||
*/
|
||||
Datum
|
||||
timeofday(PG_FUNCTION_ARGS)
|
||||
{
|
||||
struct timeval tp;
|
||||
char templ[128];
|
||||
char buf[128];
|
||||
pg_time_t tt;
|
||||
|
||||
gettimeofday(&tp, NULL);
|
||||
tt = (pg_time_t) tp.tv_sec;
|
||||
pg_strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
|
||||
pg_localtime(&tt, session_timezone));
|
||||
snprintf(buf, sizeof(buf), templ, tp.tv_usec);
|
||||
|
||||
PG_RETURN_TEXT_P(cstring_to_text(buf));
|
||||
}
|
||||
|
||||
/*
|
||||
* TimestampDifference -- convert the difference between two timestamps
|
||||
* into integer seconds and microseconds
|
||||
|
Reference in New Issue
Block a user