*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.57 2000/12/03 20:45:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.58 2001/01/17 16:46:56 thomas Exp $
*
*-------------------------------------------------------------------------
*/
sprintf(cp, "%d year%s",
tm->tm_year, ((tm->tm_year != 1) ? "s" : ""));
cp += strlen(cp);
+ is_before = (tm->tm_year < 0);
is_nonzero = TRUE;
}
if (tm->tm_mon != 0)
{
- sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""),
+ sprintf(cp, "%s%s%d mon%s", (is_nonzero ? " " : ""),
+ ((is_before && (tm->tm_mon > 0)) ? "+" : ""),
tm->tm_mon, ((tm->tm_mon != 1) ? "s" : ""));
cp += strlen(cp);
+ is_before = (tm->tm_mon < 0);
is_nonzero = TRUE;
}
if (tm->tm_mday != 0)
{
- sprintf(cp, "%s%d", (is_nonzero ? " " : ""), tm->tm_mday);
+ sprintf(cp, "%s%s%d day%s", (is_nonzero ? " " : ""),
+ ((is_before && (tm->tm_mday > 0)) ? "+" : ""),
+ tm->tm_mday, ((tm->tm_mday != 1) ? "s" : ""));
cp += strlen(cp);
+ is_before = (tm->tm_mday < 0);
is_nonzero = TRUE;
}
{
|| (tm->tm_sec < 0) || (fsec < 0));
sprintf(cp, "%s%s%02d:%02d", (is_nonzero ? " " : ""),
- (minus ? "-" : "+"),
+ (minus ? "-" : (is_nonzero ? "+" : "")),
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)
{
- is_before = (tm->tm_year < 0);
- if (is_before)
- tm->tm_year = -tm->tm_year;
- sprintf(cp, "%d year%s",
- tm->tm_year, ((tm->tm_year != 1) ? "s" : ""));
+ int year = ((tm->tm_year < 0) ? -(tm->tm_year) : tm->tm_year);
+
+ sprintf(cp, "%d year%s", year,
+ ((year != 1) ? "s" : ""));
cp += strlen(cp);
+ is_before = (tm->tm_year < 0);
is_nonzero = TRUE;
}
if (tm->tm_mon != 0)
{
+ int mon = ((is_before && (tm->tm_mon > 0)) ? -(tm->tm_mon) : tm->tm_mon);
+
+ sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""), mon,
+ ((mon != 1) ? "s" : ""));
+ cp += strlen(cp);
if (! is_nonzero)
is_before = (tm->tm_mon < 0);
- if (is_before)
- tm->tm_mon = -tm->tm_mon;
- sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""),
- tm->tm_mon, ((tm->tm_mon != 1) ? "s" : ""));
- cp += strlen(cp);
is_nonzero = TRUE;
}
if (tm->tm_mday != 0)
{
+ int day = ((is_before && (tm->tm_mday > 0)) ? -(tm->tm_mday) : tm->tm_mday);
+
+ sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""), day,
+ ((day != 1) ? "s" : ""));
+ cp += strlen(cp);
if (! is_nonzero)
is_before = (tm->tm_mday < 0);
- if (is_before)
- tm->tm_mday = -tm->tm_mday;
- sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""),
- tm->tm_mday, ((tm->tm_mday != 1) ? "s" : ""));
- cp += strlen(cp);
is_nonzero = TRUE;
}
if (tm->tm_hour != 0)
{
+ int hour = ((is_before && (tm->tm_hour > 0)) ? -(tm->tm_hour) : tm->tm_hour);
+
+ sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""), hour,
+ ((hour != 1) ? "s" : ""));
+ cp += strlen(cp);
if (! is_nonzero)
is_before = (tm->tm_hour < 0);
- if (is_before)
- tm->tm_hour = -tm->tm_hour;
- sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""),
- tm->tm_hour, ((tm->tm_hour != 1) ? "s" : ""));
- cp += strlen(cp);
is_nonzero = TRUE;
}
if (tm->tm_min != 0)
{
+ int min = ((is_before && (tm->tm_min > 0)) ? -(tm->tm_min) : tm->tm_min);
+
+ sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""), min,
+ ((min != 1) ? "s" : ""));
+ cp += strlen(cp);
if (! is_nonzero)
is_before = (tm->tm_min < 0);
- if (is_before)
- tm->tm_min = -tm->tm_min;
- sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""),
- tm->tm_min, ((tm->tm_min != 1) ? "s" : ""));
- cp += strlen(cp);
is_nonzero = TRUE;
}
if (fsec != 0)
{
fsec += tm->tm_sec;
+ sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""),
+ ((is_before && (fsec > 0)) ? -(fsec) : fsec));
+ cp += strlen(cp);
if (! is_nonzero)
is_before = (fsec < 0);
- if (is_before)
- fsec = -fsec;
- sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""), fsec);
- cp += strlen(cp);
is_nonzero = TRUE;
/* otherwise, integer seconds only? */
}
else if (tm->tm_sec != 0)
{
+ int sec = ((is_before && (tm->tm_sec > 0)) ? -(tm->tm_sec) : tm->tm_sec);
+
+ sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""), sec,
+ ((sec != 1) ? "s" : ""));
+ cp += strlen(cp);
if (! is_nonzero)
is_before = (tm->tm_sec < 0);
- if (is_before)
- tm->tm_sec = -tm->tm_sec;
- sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""),
- tm->tm_sec, ((tm->tm_sec != 1) ? "s" : ""));
- cp += strlen(cp);
is_nonzero = TRUE;
}
break;
cp += strlen(cp);
}
- if (is_before)
+ if (is_before && (style == USE_POSTGRES_DATES))
{
strcat(cp, " ago");
cp += strlen(cp);
/* -----------------------------------------------------------------------
* formatting.c
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.28 2000/12/23 04:05:31 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.29 2001/01/17 16:46:56 thomas Exp $
*
*
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\
tm->tm_sec, tm->tm_year,\
tm->tm_min, tm->tm_wday, tm->tm_hour, tm->tm_yday,\
- tm->tm_mday, tm->tm_isdst,tm->tm_mon)
+ tm->tm_mday, tm->tm_isdst, tm->tm_mon)
#endif
#define ZERO_tm( _X ) \
# elif defined(HAVE_INT_TIMEZONE)
# ifdef __CYGWIN__
- tz = (tm->tm_isdst ? (_timezone - 3600) : _timezone);
+ tz = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
# else
- tz = (tm->tm_isdst ? (timezone - 3600) : timezone);
+ tz = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
# endif
# endif
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.41 2001/01/03 16:48:02 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.42 2001/01/17 16:46:56 thomas Exp $
*
*-------------------------------------------------------------------------
*/
*tzn = (char *) tm->tm_zone;
# elif defined(HAVE_INT_TIMEZONE)
# ifdef __CYGWIN__
- *tzp = (tm->tm_isdst ? (_timezone - 3600) : _timezone);
+ *tzp = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
# else
- *tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
+ *tzp = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
# endif
if (tzn != NULL)
*tzn = tzname[(tm->tm_isdst > 0)];
# elif defined(HAVE_INT_TIMEZONE)
# ifdef __CYGWIN__
- tz = (tm->tm_isdst ? (_timezone - 3600) : _timezone);
+ tz = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
# else
- tz = (tm->tm_isdst ? (timezone - 3600) : timezone);
+ tz = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
# endif
# endif
# elif defined(HAVE_INT_TIMEZONE)
# ifdef __CYGWIN__
- tz = (tm->tm_isdst ? (_timezone - 3600) : _timezone);
+ tz = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone);
# else
- tz = (tm->tm_isdst ? (timezone - 3600) : timezone);
+ tz = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
# endif
# endif