diff options
author | Andres Freund | 2018-10-11 18:30:59 +0000 |
---|---|---|
committer | Andres Freund | 2018-10-11 18:30:59 +0000 |
commit | 86896be60ef7ace74b7b6858588ec7fae030fefd (patch) | |
tree | fe8df6e2ac10dd30fe332821adaad74ff7a02250 /src/backend/utils/adt/timestamp.c | |
parent | e9edc1ba0be21278de8f04a068c2fb3504dc03fc (diff) |
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/[email protected]
https://postgr.es/m/20180928223240.kgwc4czzzekrpsid%40alap3.anarazel.de
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 284e14dd739..ba15a29ddbd 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -1610,6 +1610,26 @@ GetSQLLocalTimestamp(int32 typmod) } /* + * 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 * |