@@ -41,25 +41,30 @@ timestamptz_to_time_t(TimestampTz t)
41
41
42
42
/*
43
43
* 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.
45
50
*
46
51
* 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.
48
53
*/
49
54
const char *
50
55
timestamptz_to_str (TimestampTz dt )
51
56
{
52
57
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 );
56
61
struct tm * ltime = localtime (& result );
57
62
58
- strftime (ts , sizeof (zone ), "%Y-%m-%d %H:%M:%S" , ltime );
63
+ strftime (ts , sizeof (ts ), "%Y-%m-%d %H:%M:%S" , ltime );
59
64
strftime (zone , sizeof (zone ), "%Z" , ltime );
60
65
61
66
#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 );
63
68
#else
64
69
sprintf (buf , "%s.%.6f %s" , ts , fabs (dt - floor (dt )), zone );
65
70
#endif
0 commit comments