aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/timestamp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r--src/backend/utils/adt/timestamp.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 2a83ae96b2a..f9fb9ef5820 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.175 2007/04/30 03:23:49 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.176 2007/04/30 21:01:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1301,6 +1301,33 @@ timestamptz_to_time_t(TimestampTz t)
return result;
}
+/*
+ * Produce a C-string representation of a TimestampTz.
+ *
+ * This is mostly for use in emitting messages. The primary difference
+ * from timestamptz_out is that we force the output format to ISO. Note
+ * also that the result is in a static buffer, not pstrdup'd.
+ */
+const char *
+timestamptz_to_str(TimestampTz t)
+{
+ static char buf[MAXDATELEN + 1];
+ int tz;
+ struct pg_tm tt,
+ *tm = &tt;
+ fsec_t fsec;
+ char *tzn;
+
+ if (TIMESTAMP_NOT_FINITE(t))
+ EncodeSpecialTimestamp(t, buf);
+ else if (timestamp2tm(t, &tz, tm, &fsec, &tzn, NULL) == 0)
+ EncodeDateTime(tm, fsec, &tz, &tzn, USE_ISO_DATES, buf);
+ else
+ strlcpy(buf, "(timestamp out of range)", sizeof(buf));
+
+ return buf;
+}
+
void
dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)