mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Fix to_char YYY, YY, Y format codes so that FM zero-suppression really works,
rather than only sort-of working as the previous attempt had left it. Clean up some unnecessary differences between the way these were coded and the way the YYYY case was coded. Update the regression test cases that proved that it wasn't working.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* formatting.c
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.169 2010/03/03 22:28:42 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.170 2010/04/07 21:41:53 tgl Exp $
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1999-2010, PostgreSQL Global Development Group
|
||||
@ -2044,7 +2044,6 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
|
||||
FormatNode *n;
|
||||
char *s;
|
||||
struct pg_tm *tm = &in->tm;
|
||||
char buff[DCH_CACHE_SIZE];
|
||||
int i;
|
||||
|
||||
/* cache localized days and months */
|
||||
@ -2394,67 +2393,55 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
|
||||
break;
|
||||
case DCH_YYYY:
|
||||
case DCH_IYYY:
|
||||
if (tm->tm_year <= 9999 && tm->tm_year >= -9998)
|
||||
sprintf(s, "%0*d",
|
||||
S_FM(n->suffix) ? 0 : 4,
|
||||
n->key->id == DCH_YYYY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(
|
||||
tm->tm_year,
|
||||
tm->tm_mon,
|
||||
tm->tm_mday), is_interval));
|
||||
else
|
||||
sprintf(s, "%d",
|
||||
n->key->id == DCH_YYYY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(
|
||||
tm->tm_year,
|
||||
tm->tm_mon,
|
||||
tm->tm_mday), is_interval));
|
||||
sprintf(s, "%0*d",
|
||||
S_FM(n->suffix) ? 0 : 4,
|
||||
(n->key->id == DCH_YYYY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
||||
tm->tm_mon,
|
||||
tm->tm_mday),
|
||||
is_interval)));
|
||||
if (S_THth(n->suffix))
|
||||
str_numth(s, s, S_TH_TYPE(n->suffix));
|
||||
s += strlen(s);
|
||||
break;
|
||||
case DCH_YYY:
|
||||
case DCH_IYY:
|
||||
snprintf(buff, sizeof(buff), "%0*d",
|
||||
S_FM(n->suffix) ? 0 : 3,
|
||||
n->key->id == DCH_YYY ?
|
||||
sprintf(s, "%0*d",
|
||||
S_FM(n->suffix) ? 0 : 3,
|
||||
(n->key->id == DCH_YYY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
i = strlen(buff);
|
||||
strcpy(s, buff + (i > 3 ? i - 3 : 0));
|
||||
tm->tm_mon,
|
||||
tm->tm_mday),
|
||||
is_interval)) % 1000);
|
||||
if (S_THth(n->suffix))
|
||||
str_numth(s, s, S_TH_TYPE(n->suffix));
|
||||
s += strlen(s);
|
||||
break;
|
||||
case DCH_YY:
|
||||
case DCH_IY:
|
||||
snprintf(buff, sizeof(buff), "%0*d",
|
||||
S_FM(n->suffix) ? 0 : 2,
|
||||
n->key->id == DCH_YY ?
|
||||
sprintf(s, "%0*d",
|
||||
S_FM(n->suffix) ? 0 : 2,
|
||||
(n->key->id == DCH_YY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
i = strlen(buff);
|
||||
strcpy(s, buff + (i > 2 ? i - 2 : 0));
|
||||
tm->tm_mon,
|
||||
tm->tm_mday),
|
||||
is_interval)) % 100);
|
||||
if (S_THth(n->suffix))
|
||||
str_numth(s, s, S_TH_TYPE(n->suffix));
|
||||
s += strlen(s);
|
||||
break;
|
||||
case DCH_Y:
|
||||
case DCH_I:
|
||||
snprintf(buff, sizeof(buff), "%1d",
|
||||
n->key->id == DCH_Y ?
|
||||
sprintf(s, "%1d",
|
||||
(n->key->id == DCH_Y ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
i = strlen(buff);
|
||||
strcpy(s, buff + (i > 1 ? i - 1 : 0));
|
||||
tm->tm_mon,
|
||||
tm->tm_mday),
|
||||
is_interval)) % 10);
|
||||
if (S_THth(n->suffix))
|
||||
str_numth(s, s, S_TH_TYPE(n->suffix));
|
||||
s += strlen(s);
|
||||
|
Reference in New Issue
Block a user