Cause the format of BC timestamptz output to be 'datetime zone BC' rather

than 'datetime BC zone', because the former is accepted by the timestamptz
input converter while the latter may not be depending on spacing.  This
is not a loss of compatibility w.r.t. 7.4 and before, because until very
recently there was never a case where we'd output both zone and 'BC'.
This commit is contained in:
Tom Lane 2004-07-11 04:57:20 +00:00
parent 59429adea9
commit c8c40bbc9e
3 changed files with 32 additions and 23 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.130 2004/06/03 02:08:04 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.131 2004/07/11 04:57:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -3521,19 +3521,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
if (fsec != 0)
{
sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
TrimTrailingZeros(str);
}
#else
if ((fsec != 0) && (tm->tm_year > 0))
{
sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
#endif
TrimTrailingZeros(str);
}
#endif
else
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
if (tm->tm_year <= 0)
sprintf((str + strlen(str)), " BC");
/*
* tzp == NULL indicates that we don't want *any* time zone
* info in the output string. *tzn != NULL indicates that we
@ -3546,6 +3545,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
min = ((abs(*tzp) / 60) % 60);
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
}
if (tm->tm_year <= 0)
sprintf((str + strlen(str)), " BC");
break;
case USE_SQL_DATES:
@ -3571,19 +3573,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
if (fsec != 0)
{
sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
TrimTrailingZeros(str);
}
#else
if ((fsec != 0) && (tm->tm_year > 0))
{
sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
#endif
TrimTrailingZeros(str);
}
#endif
else
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
if (tm->tm_year <= 0)
sprintf((str + strlen(str)), " BC");
if ((tzp != NULL) && (tm->tm_isdst >= 0))
{
if (*tzn != NULL)
@ -3595,6 +3596,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
}
}
if (tm->tm_year <= 0)
sprintf((str + strlen(str)), " BC");
break;
case USE_GERMAN_DATES:
@ -3617,19 +3621,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
if (fsec != 0)
{
sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
TrimTrailingZeros(str);
}
#else
if ((fsec != 0) && (tm->tm_year > 0))
{
sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
#endif
TrimTrailingZeros(str);
}
#endif
else
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
if (tm->tm_year <= 0)
sprintf((str + strlen(str)), " BC");
if ((tzp != NULL) && (tm->tm_isdst >= 0))
{
if (*tzn != NULL)
@ -3641,6 +3644,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
}
}
if (tm->tm_year <= 0)
sprintf((str + strlen(str)), " BC");
break;
case USE_POSTGRES_DATES:
@ -3671,20 +3677,20 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
if (fsec != 0)
{
sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
TrimTrailingZeros(str);
}
#else
if ((fsec != 0) && (tm->tm_year > 0))
{
sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
#endif
TrimTrailingZeros(str);
}
#endif
else
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
sprintf((str + strlen(str)), " %04d",
((tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1)));
if (tm->tm_year <= 0)
sprintf((str + strlen(str)), " BC");
if ((tzp != NULL) && (tm->tm_isdst >= 0))
{
@ -3704,11 +3710,14 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
sprintf((str + strlen(str)), ((min != 0) ? " %+03d:%02d" : " %+03d"), hour, min);
}
}
if (tm->tm_year <= 0)
sprintf((str + strlen(str)), " BC");
break;
}
return TRUE;
} /* EncodeDateTime() */
}
/* EncodeInterval()

View File

@ -672,7 +672,7 @@ SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL;
| Sat Feb 14 17:32:01 1998 PST
| Sun Feb 15 17:32:01 1998 PST
| Mon Feb 16 17:32:01 1998 PST
| Thu Feb 16 17:32:01 0096 BC PST
| Thu Feb 16 17:32:01 0096 PST BC
| Sun Feb 16 17:32:01 0098 PST
| Fri Feb 16 17:32:01 0598 PST
| Wed Feb 16 17:32:01 1098 PST
@ -741,7 +741,7 @@ SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL;
| Wed Feb 14 17:32:01 1996 PST
| Thu Feb 15 17:32:01 1996 PST
| Fri Feb 16 17:32:01 1996 PST
| Mon Feb 16 17:32:01 0098 BC PST
| Mon Feb 16 17:32:01 0098 PST BC
| Thu Feb 16 17:32:01 0096 PST
| Tue Feb 16 17:32:01 0596 PST
| Sun Feb 16 17:32:01 1096 PST

View File

@ -180,7 +180,7 @@ SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL;
| Fri Feb 14 17:32:01 1997 PST
| Sat Feb 15 17:32:01 1997 PST
| Sun Feb 16 17:32:01 1997 PST
| Tue Feb 16 17:32:01 0097 BC PST
| Tue Feb 16 17:32:01 0097 PST BC
| Sat Feb 16 17:32:01 0097 PST
| Thu Feb 16 17:32:01 0597 PST
| Tue Feb 16 17:32:01 1097 PST
@ -266,7 +266,7 @@ SELECT '' AS "15", d1 FROM TIMESTAMPTZ_TBL
----+---------------------------------
| -infinity
| Wed Dec 31 16:00:00 1969 PST
| Tue Feb 16 17:32:01 0097 BC PST
| Tue Feb 16 17:32:01 0097 PST BC
| Sat Feb 16 17:32:01 0097 PST
| Thu Feb 16 17:32:01 0597 PST
| Tue Feb 16 17:32:01 1097 PST
@ -332,7 +332,7 @@ SELECT '' AS "63", d1 FROM TIMESTAMPTZ_TBL
| Fri Feb 14 17:32:01 1997 PST
| Sat Feb 15 17:32:01 1997 PST
| Sun Feb 16 17:32:01 1997 PST
| Tue Feb 16 17:32:01 0097 BC PST
| Tue Feb 16 17:32:01 0097 PST BC
| Sat Feb 16 17:32:01 0097 PST
| Thu Feb 16 17:32:01 0597 PST
| Tue Feb 16 17:32:01 1097 PST
@ -364,7 +364,7 @@ SELECT '' AS "16", d1 FROM TIMESTAMPTZ_TBL
| -infinity
| Wed Dec 31 16:00:00 1969 PST
| Thu Jan 02 00:00:00 1997 PST
| Tue Feb 16 17:32:01 0097 BC PST
| Tue Feb 16 17:32:01 0097 PST BC
| Sat Feb 16 17:32:01 0097 PST
| Thu Feb 16 17:32:01 0597 PST
| Tue Feb 16 17:32:01 1097 PST