diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-07-11 04:57:20 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-07-11 04:57:20 +0000 |
commit | c8c40bbc9ea8fcb2e47767a9f15c4a5c74569b8d (patch) | |
tree | 43d1604b59e7b1880d140b566d78838913d5bf46 /src/backend/utils/adt/datetime.c | |
parent | 59429adea9155d9de0de56f32f7d169be63df420 (diff) | |
download | postgresql-c8c40bbc9ea8fcb2e47767a9f15c4a5c74569b8d.tar.gz postgresql-c8c40bbc9ea8fcb2e47767a9f15c4a5c74569b8d.zip |
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'.
Diffstat (limited to 'src/backend/utils/adt/datetime.c')
-rw-r--r-- | src/backend/utils/adt/datetime.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 6fdefc536e8..3ca0da8845d 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -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() |