Re: BUG #1609: Bug in interval datatype for 64 Bit timestamps - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #1609: Bug in interval datatype for 64 Bit timestamps
Date
Msg-id 3036.1114017359@sss.pgh.pa.us
Whole thread Raw
In response to BUG #1609: Bug in interval datatype for 64 Bit timestamps  ("Oliver Siegmar" <oliver@siegmar.net>)
List pgsql-bugs
I've applied this patch.

            regards, tom lane

Index: datetime.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v
retrieving revision 1.137
diff -c -r1.137 datetime.c
*** datetime.c    11 Jan 2005 18:33:45 -0000    1.137
--- datetime.c    20 Apr 2005 17:09:57 -0000
***************
*** 3883,3899 ****
              /* fractional seconds? */
              if (fsec != 0)
              {
  #ifdef HAVE_INT64_TIMESTAMP
                  if (is_before || ((!is_nonzero) && (tm->tm_sec < 0)))
                      tm->tm_sec = -tm->tm_sec;
                  sprintf(cp, "%s%d.%02d secs", (is_nonzero ? " " : ""),
!                         tm->tm_sec, (((int) fsec) / 10000));
                  cp += strlen(cp);
-                 if (!is_nonzero)
-                     is_before = (fsec < 0);
  #else
-                 fsec_t        sec;
-
                  fsec += tm->tm_sec;
                  sec = fsec;
                  if (is_before || ((!is_nonzero) && (fsec < 0)))
--- 3883,3907 ----
              /* fractional seconds? */
              if (fsec != 0)
              {
+                 fsec_t        sec;
+
  #ifdef HAVE_INT64_TIMESTAMP
+                 sec = fsec;
                  if (is_before || ((!is_nonzero) && (tm->tm_sec < 0)))
+                 {
                      tm->tm_sec = -tm->tm_sec;
+                     sec = -sec;
+                     is_before = TRUE;
+                 }
+                 else if ((!is_nonzero) && (tm->tm_sec == 0) && (fsec < 0))
+                 {
+                     sec = -sec;
+                     is_before = TRUE;
+                 }
                  sprintf(cp, "%s%d.%02d secs", (is_nonzero ? " " : ""),
!                         tm->tm_sec, (((int) sec) / 10000));
                  cp += strlen(cp);
  #else
                  fsec += tm->tm_sec;
                  sec = fsec;
                  if (is_before || ((!is_nonzero) && (fsec < 0)))
***************
*** 3905,3913 ****
                      is_before = (fsec < 0);
  #endif
                  is_nonzero = TRUE;
-
-                 /* otherwise, integer seconds only? */
              }
              else if (tm->tm_sec != 0)
              {
                  int            sec = tm->tm_sec;
--- 3913,3920 ----
                      is_before = (fsec < 0);
  #endif
                  is_nonzero = TRUE;
              }
+             /* otherwise, integer seconds only? */
              else if (tm->tm_sec != 0)
              {
                  int            sec = tm->tm_sec;

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #1609: Bug in interval datatype for 64 Bit timestamps
Next
From: Oliver Siegmar
Date:
Subject: Re: BUG #1609: Bug in interval datatype for 64 Bit timestamps