aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/timestamp.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-08-12 18:23:56 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-08-12 18:23:56 +0000
commita43ea120bf7539232d9f41a3bf7f7986fde84837 (patch)
treed273c2bf155291a526c6b9c8700ab7803359ae36 /src/backend/utils/adt/timestamp.c
parentcb29f669b0b67b82f1f5422b3aaf0f54ac5d20ee (diff)
downloadpostgresql-a43ea120bf7539232d9f41a3bf7f7986fde84837.tar.gz
postgresql-a43ea120bf7539232d9f41a3bf7f7986fde84837.zip
Code & docs review for server instrumentation patch. File timestamps
should surely be timestamptz not timestamp; fix some but not all of the holes in check_and_make_absolute(); other minor cleanup. Also put in the missed catversion bump.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r--src/backend/utils/adt/timestamp.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 62c6effbfe3..476923c6364 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.147 2005/07/30 18:20:44 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.148 2005/08/12 18:23:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -939,7 +939,7 @@ GetCurrentTimestamp(void)
gettimeofday(&tp, NULL);
- result = tp.tv_sec -
+ result = (TimestampTz) tp.tv_sec -
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY);
#ifdef HAVE_INT64_TIMESTAMP
@@ -951,6 +951,29 @@ GetCurrentTimestamp(void)
return result;
}
+
+/*
+ * Convert a time_t to TimestampTz.
+ *
+ * We do not use time_t internally in Postgres, but this is provided for use
+ * by functions that need to interpret, say, a stat(2) result.
+ */
+TimestampTz
+time_t_to_timestamptz(time_t tm)
+{
+ TimestampTz result;
+
+ result = (TimestampTz) tm -
+ ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY);
+
+#ifdef HAVE_INT64_TIMESTAMP
+ result *= USECS_PER_SEC;
+#endif
+
+ return result;
+}
+
+
void
dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
{