timestamp refactor effort
So...in the vein of my last mail, I have tried to create another patch
for refactoring out some of the HAVE_INT64_TIMESTAMP ifdefs in the
code in timestamp.c. I have attached the patch. Please let me know if
this patch is acceptable and what I can do to continue this effort.
Thanks,
wt
Attachments:
0001-Add-PackedTime-typedef.patchtext/x-diff; name=0001-Add-PackedTime-typedef.patchDownload
From 77db4f84999161c0c7ba8ded78636512cc719878 Mon Sep 17 00:00:00 2001
From: Warren Turkal <wt@penguintechs.org>
Date: Wed, 9 Jan 2008 00:19:46 -0800
Subject: [PATCH] Add PackedTime typedef.
The PackedTime type is meant to be a type that holds the hour, minute,
second, and fractional seconds part of the time. The actual primitive
type that the PackedTime type uses is determined by the
HAVE_INT64_TIMESTAMP define.
I have also changed some of the instances of variable declaratations
for times to use the PackedTime type instead of the primitive types.
---
src/backend/utils/adt/timestamp.c | 21 ++++++---------------
src/include/utils/timestamp.h | 9 +++------
2 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 2883caf..1a4c247 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -44,11 +44,7 @@
TimestampTz PgStartTime;
-#ifdef HAVE_INT64_TIMESTAMP
-static int64 time2t(const int hour, const int min, const int sec, const fsec_t fsec);
-#else
-static double time2t(const int hour, const int min, const int sec, const fsec_t fsec);
-#endif
+static PackedTime time2t(const int hour, const int min, const int sec, const fsec_t fsec);
static int EncodeSpecialTimestamp(Timestamp dt, char *str);
static Timestamp dt2local(Timestamp dt, int timezone);
static void AdjustTimestampForTypmod(Timestamp *time, int32 typmod);
@@ -1539,11 +1535,10 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
{
#ifdef HAVE_INT64_TIMESTAMP
int date;
- int64 time;
#else
- double date,
- time;
+ double date;
#endif
+ PackedTime time;
/* Julian day routines are not correct for negative Julian days */
if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
@@ -1648,19 +1643,15 @@ tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
return 0;
}
-#ifdef HAVE_INT64_TIMESTAMP
-static int64
+static PackedTime
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{
+#ifdef HAVE_INT64_TIMESTAMP
return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec;
-} /* time2t() */
#else
-static double
-time2t(const int hour, const int min, const int sec, const fsec_t fsec)
-{
return (((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec + fsec;
-} /* time2t() */
#endif
+} /* time2t() */
static Timestamp
dt2local(Timestamp dt, int tz)
diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h
index 6eec76d..945b970 100644
--- a/src/include/utils/timestamp.h
+++ b/src/include/utils/timestamp.h
@@ -36,20 +36,17 @@
#ifdef HAVE_INT64_TIMESTAMP
typedef int64 Timestamp;
typedef int64 TimestampTz;
+typedef int64 PackedTime;
#else
typedef double Timestamp;
typedef double TimestampTz;
+typedef double PackedTime;
#endif
typedef struct
{
-#ifdef HAVE_INT64_TIMESTAMP
- int64 time; /* all time units other than days, months and
- * years */
-#else
- double time; /* all time units other than days, months and
+ PackedTime time; /* all time units other than days, months and
* years */
-#endif
int32 day; /* days, after time for alignment */
int32 month; /* months and years, after time for alignment */
} Interval;
--
1.5.3.7
"Warren Turkal" <wturkal@gmail.com> writes:
So...in the vein of my last mail, I have tried to create another patch
for refactoring out some of the HAVE_INT64_TIMESTAMP ifdefs in the
code in timestamp.c. I have attached the patch. Please let me know if
this patch is acceptable and what I can do to continue this effort.
Hmm, PackedTime seems like a fairly random name for the type --- there's
not anything particularly "packed" about it IMO.
I'm a bit inclined to suggest just using the Timestamp typedef.
I guess though that there's some risk of confusion between values
that actually are "timestamp without time zone" and values that need
the same representation but aren't actually intended to represent a
specific point in time.
Maybe "TimeOffset" or "TimeValue" or something like that?
Other than the name game, I think you're headed in the right direction.
regards, tom lane
On Jan 12, 2008 5:23 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Hmm, PackedTime seems like a fairly random name for the type --- there's
not anything particularly "packed" about it IMO.I'm a bit inclined to suggest just using the Timestamp typedef.
I guess though that there's some risk of confusion between values
that actually are "timestamp without time zone" and values that need
the same representation but aren't actually intended to represent a
specific point in time.Maybe "TimeOffset" or "TimeValue" or something like that?
I do agree that Timestamp seems to express the same thing PackedTime
does Should we rename Timestamp to TimeOffset?
Other than the name game, I think you're headed in the right direction.
Thanks.
I have a question. Are the low level representations of Timestamp and
TimestampTZ the same?
wt
-my gmail account
Show quoted text
On Jan 13, 2008 12:13 AM, Warren Turkal <turkal@google.com> wrote:
On Jan 12, 2008 5:23 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Hmm, PackedTime seems like a fairly random name for the type --- there's
not anything particularly "packed" about it IMO.I'm a bit inclined to suggest just using the Timestamp typedef.
I guess though that there's some risk of confusion between values
that actually are "timestamp without time zone" and values that need
the same representation but aren't actually intended to represent a
specific point in time.Maybe "TimeOffset" or "TimeValue" or something like that?
I do agree that Timestamp seems to express the same thing PackedTime
does Should we rename Timestamp to TimeOffset?Other than the name game, I think you're headed in the right direction.
Thanks.
I have a question. Are the low level representations of Timestamp and
TimestampTZ the same?wt
"Warren Turkal" <turkal@google.com> writes:
I have a question. Are the low level representations of Timestamp and
TimestampTZ the same?
They're the same but the interpretations are different, which is why
I think it's useful to have two typedefs as a way of documenting what
any given value is intended to be. The argument for having a third
typedef would be exactly the same: to help document what a value is
intended to be.
regards, tom lane
On Jan 13, 2008 9:21 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Warren Turkal" <turkal@google.com> writes:
I have a question. Are the low level representations of Timestamp and
TimestampTZ the same?They're the same but the interpretations are different, which is why
I think it's useful to have two typedefs as a way of documenting what
any given value is intended to be. The argument for having a third
typedef would be exactly the same: to help document what a value is
intended to be.
Makes sense.
wt