*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.58 2001/01/17 16:46:56 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.59 2001/01/18 07:22:35 thomas Exp $
*
*-------------------------------------------------------------------------
*/
*tzp = -(tm->tm_gmtoff); /* tm_gmtoff is
* Sun/DEC-ism */
# elif defined(HAVE_INT_TIMEZONE)
-# ifdef __CYGWIN__
- *tzp = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
-# else
- *tzp = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
-# endif /* __CYGWIN__ */
+ *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
# endif /* HAVE_INT_TIMEZONE */
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
# if defined(HAVE_TM_ZONE)
*tzp = -(tmp->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
# elif defined(HAVE_INT_TIMEZONE)
-# ifdef __CYGWIN__
- *tzp = ((tmp->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
-# else
- *tzp = ((tmp->tm_isdst > 0) ? (timezone - 3600) : timezone);
-# endif
+ *tzp = ((tmp->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
# endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
is_before = (tm->tm_mday < 0);
is_nonzero = TRUE;
}
+ if ((!is_nonzero) || (tm->tm_hour != 0) || (tm->tm_min != 0)
+ || (tm->tm_sec != 0) || (fsec != 0))
{
int minus = ((tm->tm_hour < 0) || (tm->tm_min < 0)
|| (tm->tm_sec < 0) || (fsec < 0));
sprintf(cp, "%s%s%02d:%02d", (is_nonzero ? " " : ""),
- (minus ? "-" : (is_nonzero ? "+" : "")),
+ (minus ? "-" : (is_before ? "+" : "")),
abs(tm->tm_hour), abs(tm->tm_min));
cp += strlen(cp);
/* Mark as "non-zero" since the fields are now filled in */
if (tm->tm_year != 0)
{
- int year = ((tm->tm_year < 0) ? -(tm->tm_year) : tm->tm_year);
+ int year = tm->tm_year;
+ if (tm->tm_year < 0)
+ year = -year;
sprintf(cp, "%d year%s", year,
((year != 1) ? "s" : ""));
if (tm->tm_mon != 0)
{
- int mon = ((is_before && (tm->tm_mon > 0)) ? -(tm->tm_mon) : tm->tm_mon);
+ int mon = tm->tm_mon;
+ if (is_before || ((!is_nonzero) && (tm->tm_mon < 0)))
+ mon = -mon;
sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""), mon,
((mon != 1) ? "s" : ""));
if (tm->tm_mday != 0)
{
- int day = ((is_before && (tm->tm_mday > 0)) ? -(tm->tm_mday) : tm->tm_mday);
+ int day = tm->tm_mday;
+ if (is_before || ((!is_nonzero) && (tm->tm_mday < 0)))
+ day = -day;
sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""), day,
((day != 1) ? "s" : ""));
}
if (tm->tm_hour != 0)
{
- int hour = ((is_before && (tm->tm_hour > 0)) ? -(tm->tm_hour) : tm->tm_hour);
+ int hour = tm->tm_hour;
+ if (is_before || ((!is_nonzero) && (tm->tm_hour < 0)))
+ hour = -hour;
sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""), hour,
((hour != 1) ? "s" : ""));
if (tm->tm_min != 0)
{
- int min = ((is_before && (tm->tm_min > 0)) ? -(tm->tm_min) : tm->tm_min);
+ int min = tm->tm_min;
+ if (is_before || ((!is_nonzero) && (tm->tm_min < 0)))
+ min = -min;
sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""), min,
((min != 1) ? "s" : ""));
/* fractional seconds? */
if (fsec != 0)
{
+ double sec;
fsec += tm->tm_sec;
- sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""),
- ((is_before && (fsec > 0)) ? -(fsec) : fsec));
+ sec = fsec;
+ if (is_before || ((!is_nonzero) && (fsec < 0)))
+ sec = -sec;
+
+ sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""), sec);
cp += strlen(cp);
if (! is_nonzero)
is_before = (fsec < 0);
}
else if (tm->tm_sec != 0)
{
- int sec = ((is_before && (tm->tm_sec > 0)) ? -(tm->tm_sec) : tm->tm_sec);
+ int sec = tm->tm_sec;
+ if (is_before || ((!is_nonzero) && (tm->tm_sec < 0)))
+ sec = -sec;
sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""), sec,
((sec != 1) ? "s" : ""));
/* -----------------------------------------------------------------------
* formatting.c
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.29 2001/01/17 16:46:56 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.30 2001/01/18 07:22:36 thomas Exp $
*
*
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
# if defined(HAVE_TM_ZONE)
tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
# elif defined(HAVE_INT_TIMEZONE)
-
-# ifdef __CYGWIN__
- tz = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
-# else
- tz = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
-# endif
-
+ tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
# endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.78 2001/01/17 16:46:56 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.79 2001/01/18 07:22:36 thomas Exp $
*
* NOTES
*
tm = localtime(&now);
CDayLight = tm->tm_isdst;
- CTimeZone =
-# ifdef __CYGWIN__
- ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
-# else
- ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
-# endif
+ CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
strcpy(CTZName, tzname[tm->tm_isdst]);
#else /* neither HAVE_TM_ZONE nor HAVE_INT_TIMEZONE */
CTimeZone = tb.timezone * 60;
}
# elif defined(HAVE_INT_TIMEZONE)
if (tzp != NULL)
-# ifdef __CYGWIN__
- *tzp = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
-# else
- *tzp = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
-# endif
+ *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
+
if (tzn != NULL)
{
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.42 2001/01/17 16:46:56 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.43 2001/01/18 07:22:36 thomas Exp $
*
*-------------------------------------------------------------------------
*/
/* XXX HACK
* Argh! My Linux box puts in a 1 second offset for dates less than 1970
* but only if the seconds field was non-zero. So, don't copy the seconds
- * field and instead carry forward from the original - tgl 97/06/18
+ * field and instead carry forward from the original - thomas 97/06/18
* Note that GNU/Linux uses the standard freeware zic package as do
* many other platforms so this may not be GNU/Linux/ix86-specific.
+ * Still shows a problem on my up to date Linux box - thomas 2001-01-17
*/
tm->tm_sec = tx->tm_sec;
#endif
if (tzn != NULL)
*tzn = (char *) tm->tm_zone;
# elif defined(HAVE_INT_TIMEZONE)
-# ifdef __CYGWIN__
- *tzp = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
-# else
- *tzp = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
-# endif
+ *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
if (tzn != NULL)
*tzn = tzname[(tm->tm_isdst > 0)];
# endif
# if defined(HAVE_TM_ZONE)
tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
# elif defined(HAVE_INT_TIMEZONE)
-
-# ifdef __CYGWIN__
- tz = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
-# else
- tz = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
-# endif
-
+ tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
# endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
# if defined(HAVE_TM_ZONE)
tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
# elif defined(HAVE_INT_TIMEZONE)
-
-# ifdef __CYGWIN__
- tz = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
-# else
- tz = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
-# endif
-
+ tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
# endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: datetime.h,v 1.15 2000/06/08 22:37:58 momjian Exp $
+ * $Id: datetime.h,v 1.16 2001/01/18 07:22:42 thomas Exp $
*
*-------------------------------------------------------------------------
*/
t -= rint(q * u); \
} while(0)
+#ifdef __CYGWIN__
+#define TIMEZONE_GLOBAL _timezone
+#else
+#define TIMEZONE_GLOBAL timezone
+#endif
/*
* Date/time validation
SELECT INTERVAL '01:00' AS "One hour";
One hour
----------
- +01:00
+ 01:00
(1 row)
SELECT INTERVAL '+02:00' AS "Two hours";
Two hours
-----------
- +02:00
+ 02:00
(1 row)
SELECT INTERVAL '-08:00' AS "Eight hours";
(1 row)
SELECT INTERVAL '10 years -11 month -12 days +13:14' AS "9 years...";
- 9 years...
---------------------------
- 9 years 1 mon -11 -10:46
+ 9 years...
+-------------------------------
+ 9 years 1 mon -11 days -10:46
(1 row)
CREATE TABLE INTERVAL_TBL (f1 interval);
ERROR: Bad interval external representation '@ 30 eons ago'
-- test interval operators
SELECT '' AS ten, INTERVAL_TBL.*;
- ten | f1
------+-----------------
- | +00:01
- | +05:00
- | 10 +00:00
- | 34 years +00:00
- | 3 mons +00:00
+ ten | f1
+-----+----------------
+ | 00:01
+ | 05:00
+ | 10 days
+ | 34 years
+ | 3 mons
| -00:00:14
- | 1 +02:03:04
- | 6 years +00:00
- | 5 mons +00:00
- | 5 mons +12:00
+ | 1 day 02:03:04
+ | 6 years
+ | 5 mons
+ | 5 mons 12:00
(10 rows)
SELECT '' AS nine, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 <> interval '@ 10 days';
- nine | f1
-------+-----------------
- | +00:01
- | +05:00
- | 34 years +00:00
- | 3 mons +00:00
+ nine | f1
+------+----------------
+ | 00:01
+ | 05:00
+ | 34 years
+ | 3 mons
| -00:00:14
- | 1 +02:03:04
- | 6 years +00:00
- | 5 mons +00:00
- | 5 mons +12:00
+ | 1 day 02:03:04
+ | 6 years
+ | 5 mons
+ | 5 mons 12:00
(9 rows)
SELECT '' AS three, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 <= interval '@ 5 hours';
three | f1
-------+-----------
- | +00:01
- | +05:00
+ | 00:01
+ | 05:00
| -00:00:14
(3 rows)
WHERE INTERVAL_TBL.f1 < interval '@ 1 day';
three | f1
-------+-----------
- | +00:01
- | +05:00
+ | 00:01
+ | 05:00
| -00:00:14
(3 rows)
SELECT '' AS one, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 = interval '@ 34 years';
- one | f1
------+-----------------
- | 34 years +00:00
+ one | f1
+-----+----------
+ | 34 years
(1 row)
SELECT '' AS five, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 >= interval '@ 1 month';
- five | f1
-------+-----------------
- | 34 years +00:00
- | 3 mons +00:00
- | 6 years +00:00
- | 5 mons +00:00
- | 5 mons +12:00
+ five | f1
+------+--------------
+ | 34 years
+ | 3 mons
+ | 6 years
+ | 5 mons
+ | 5 mons 12:00
(5 rows)
SELECT '' AS nine, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 > interval '@ 3 seconds ago';
- nine | f1
-------+-----------------
- | +00:01
- | +05:00
- | 10 +00:00
- | 34 years +00:00
- | 3 mons +00:00
- | 1 +02:03:04
- | 6 years +00:00
- | 5 mons +00:00
- | 5 mons +12:00
+ nine | f1
+------+----------------
+ | 00:01
+ | 05:00
+ | 10 days
+ | 34 years
+ | 3 mons
+ | 1 day 02:03:04
+ | 6 years
+ | 5 mons
+ | 5 mons 12:00
(9 rows)
SELECT '' AS fortyfive, r1.*, r2.*
FROM INTERVAL_TBL r1, INTERVAL_TBL r2
WHERE r1.f1 > r2.f1
ORDER BY r1.f1, r2.f1;
- fortyfive | f1 | f1
------------+-----------------+----------------
- | +00:01 | -00:00:14
- | +05:00 | -00:00:14
- | +05:00 | +00:01
- | 1 +02:03:04 | -00:00:14
- | 1 +02:03:04 | +00:01
- | 1 +02:03:04 | +05:00
- | 10 +00:00 | -00:00:14
- | 10 +00:00 | +00:01
- | 10 +00:00 | +05:00
- | 10 +00:00 | 1 +02:03:04
- | 3 mons +00:00 | -00:00:14
- | 3 mons +00:00 | +00:01
- | 3 mons +00:00 | +05:00
- | 3 mons +00:00 | 1 +02:03:04
- | 3 mons +00:00 | 10 +00:00
- | 5 mons +00:00 | -00:00:14
- | 5 mons +00:00 | +00:01
- | 5 mons +00:00 | +05:00
- | 5 mons +00:00 | 1 +02:03:04
- | 5 mons +00:00 | 10 +00:00
- | 5 mons +00:00 | 3 mons +00:00
- | 5 mons +12:00 | -00:00:14
- | 5 mons +12:00 | +00:01
- | 5 mons +12:00 | +05:00
- | 5 mons +12:00 | 1 +02:03:04
- | 5 mons +12:00 | 10 +00:00
- | 5 mons +12:00 | 3 mons +00:00
- | 5 mons +12:00 | 5 mons +00:00
- | 6 years +00:00 | -00:00:14
- | 6 years +00:00 | +00:01
- | 6 years +00:00 | +05:00
- | 6 years +00:00 | 1 +02:03:04
- | 6 years +00:00 | 10 +00:00
- | 6 years +00:00 | 3 mons +00:00
- | 6 years +00:00 | 5 mons +00:00
- | 6 years +00:00 | 5 mons +12:00
- | 34 years +00:00 | -00:00:14
- | 34 years +00:00 | +00:01
- | 34 years +00:00 | +05:00
- | 34 years +00:00 | 1 +02:03:04
- | 34 years +00:00 | 10 +00:00
- | 34 years +00:00 | 3 mons +00:00
- | 34 years +00:00 | 5 mons +00:00
- | 34 years +00:00 | 5 mons +12:00
- | 34 years +00:00 | 6 years +00:00
+ fortyfive | f1 | f1
+-----------+----------------+----------------
+ | 00:01 | -00:00:14
+ | 05:00 | -00:00:14
+ | 05:00 | 00:01
+ | 1 day 02:03:04 | -00:00:14
+ | 1 day 02:03:04 | 00:01
+ | 1 day 02:03:04 | 05:00
+ | 10 days | -00:00:14
+ | 10 days | 00:01
+ | 10 days | 05:00
+ | 10 days | 1 day 02:03:04
+ | 3 mons | -00:00:14
+ | 3 mons | 00:01
+ | 3 mons | 05:00
+ | 3 mons | 1 day 02:03:04
+ | 3 mons | 10 days
+ | 5 mons | -00:00:14
+ | 5 mons | 00:01
+ | 5 mons | 05:00
+ | 5 mons | 1 day 02:03:04
+ | 5 mons | 10 days
+ | 5 mons | 3 mons
+ | 5 mons 12:00 | -00:00:14
+ | 5 mons 12:00 | 00:01
+ | 5 mons 12:00 | 05:00
+ | 5 mons 12:00 | 1 day 02:03:04
+ | 5 mons 12:00 | 10 days
+ | 5 mons 12:00 | 3 mons
+ | 5 mons 12:00 | 5 mons
+ | 6 years | -00:00:14
+ | 6 years | 00:01
+ | 6 years | 05:00
+ | 6 years | 1 day 02:03:04
+ | 6 years | 10 days
+ | 6 years | 3 mons
+ | 6 years | 5 mons
+ | 6 years | 5 mons 12:00
+ | 34 years | -00:00:14
+ | 34 years | 00:01
+ | 34 years | 05:00
+ | 34 years | 1 day 02:03:04
+ | 34 years | 10 days
+ | 34 years | 3 mons
+ | 34 years | 5 mons
+ | 34 years | 5 mons 12:00
+ | 34 years | 6 years
(45 rows)
SET DATESTYLE = 'postgres';