@@ -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 */
4954const char *
5055timestamptz_to_str (TimestampTz dt )
5156{
5257 static char buf [MAXDATELEN + 1 ];
53- static char ts [MAXDATELEN + 1 ];
54- static char zone [MAXDATELEN + 1 ];
55- pg_time_t result = timestamptz_to_time_t (dt );
58+ char ts [MAXDATELEN + 1 ];
59+ char zone [MAXDATELEN + 1 ];
60+ time_t result = ( time_t ) timestamptz_to_time_t (dt );
5661 struct tm * 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#ifdef HAVE_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