Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1418e6e

Browse files
committed
Clean up "stopgap" implementation of timestamptz_to_str().
Use correct type for "result", fix bogus strftime argument, don't useunnecessary static variables, improve comments.Andres Freund and Tom Lane
1 parentc153530 commit1418e6e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

‎contrib/pg_xlogdump/compat.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,30 @@ timestamptz_to_time_t(TimestampTz t)
4141

4242
/*
4343
* Stopgap implementation of timestamptz_to_str that doesn't depend on backend
44-
* infrastructure.
44+
* infrastructure. This will work for timestamps that are within the range
45+
* of the platform time_t type. (pg_time_t is compatible except for possibly
46+
* being wider.)
47+
*
48+
* XXX the return value points to a static buffer, so beware of using more
49+
* than one result value concurrently.
4550
*
4651
* XXX: The backend timestamp infrastructure should instead be split out and
47-
* moved into src/common.
52+
* moved into src/common. That's a large project though.
4853
*/
4954
constchar*
5055
timestamptz_to_str(TimestampTzdt)
5156
{
5257
staticcharbuf[MAXDATELEN+1];
53-
staticcharts[MAXDATELEN+1];
54-
staticcharzone[MAXDATELEN+1];
55-
pg_time_tresult=timestamptz_to_time_t(dt);
58+
charts[MAXDATELEN+1];
59+
charzone[MAXDATELEN+1];
60+
time_tresult= (time_t)timestamptz_to_time_t(dt);
5661
structtm*ltime=localtime(&result);
5762

58-
strftime(ts,sizeof(zone),"%Y-%m-%d %H:%M:%S",ltime);
63+
strftime(ts,sizeof(ts),"%Y-%m-%d %H:%M:%S",ltime);
5964
strftime(zone,sizeof(zone),"%Z",ltime);
6065

6166
#ifdefHAVE_INT64_TIMESTAMP
62-
sprintf(buf,"%s.%06d %s",ts, (int)(dt %USECS_PER_SEC),zone);
67+
sprintf(buf,"%s.%06d %s",ts, (int)(dt %USECS_PER_SEC),zone);
6368
#else
6469
sprintf(buf,"%s.%.6f %s",ts,fabs(dt-floor(dt)),zone);
6570
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp