Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fd071bd

Browse files
committed
Fix to_char for 1 BC. Previously it returned 1 AD.
Fix to_char(year) for BC dates. Previously it returned one less than the current year. Add documentation mentioning that there is no 0 AD.
1 parent f2c064a commit fd071bd

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

doc/src/sgml/func.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.195 2004/03/19 19:13:26 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.196 2004/03/30 15:53:18 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -5216,8 +5216,7 @@ SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
52165216
<term><literal>week</literal></term>
52175217
<listitem>
52185218
<para>
5219-
The number of
5220-
the week of the year that the day is in. By definition
5219+
The number of the week of the year that the day is in. By definition
52215220
(<acronym>ISO</acronym> 8601), the first week of a year
52225221
contains January 4 of that year. (The <acronym>ISO</acronym>-8601
52235222
week starts on Monday.) In other words, the first Thursday of
@@ -5235,7 +5234,8 @@ SELECT EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40');
52355234
<term><literal>year</literal></term>
52365235
<listitem>
52375236
<para>
5238-
The year field
5237+
The year field. Keep in mind there is no <literal>0 AD</>, so subtracting
5238+
<literal>BC</> years from <literal>AD</> years should be done with care.
52395239
</para>
52405240

52415241
<screen>

src/backend/utils/adt/datetime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.125 2004/02/25 19:41:23 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.126 2004/03/30 15:53:18 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -93,7 +93,7 @@ static datetkn datetktbl[] = {
9393
{"acsst", DTZ, POS(42)}, /* Cent. Australia */
9494
{"acst", DTZ, NEG(16)}, /* Atlantic/Porto Acre Summer Time */
9595
{"act", TZ, NEG(20)}, /* Atlantic/Porto Acre Time */
96-
{DA_D, ADBC, AD}, /* "ad" for years >= 0 */
96+
{DA_D, ADBC, AD}, /* "ad" for years > 0 */
9797
{"adt", DTZ, NEG(12)}, /* Atlantic Daylight Time */
9898
{"aesst", DTZ, POS(44)}, /* E. Australia */
9999
{"aest", TZ, POS(40)}, /* Australia Eastern Std Time */
@@ -139,7 +139,7 @@ static datetkn datetktbl[] = {
139139
{"azot", TZ, NEG(4)}, /* Azores Time */
140140
{"azst", DTZ, POS(20)}, /* Azerbaijan Summer Time */
141141
{"azt", TZ, POS(16)}, /* Azerbaijan Time */
142-
{DB_C, ADBC, BC}, /* "bc" for years < 0 */
142+
{DB_C, ADBC, BC}, /* "bc" for years <= 0 */
143143
{"bdst", TZ, POS(8)}, /* British Double Summer Time */
144144
{"bdt", TZ, POS(24)}, /* Dacca */
145145
{"bnt", TZ, POS(32)}, /* Brunei Darussalam Time */

src/backend/utils/adt/formatting.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.72 2004/01/07 18:56:28 neilc Exp $
4+
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.73 2004/03/30 15:53:18 momjian Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2003, PostgreSQL Global Development Group
@@ -169,7 +169,7 @@ static char *months_full[] = {
169169
* AC / DC
170170
* ----------
171171
*/
172-
#define YEAR_ABS(_y) (_y < 0 ? -(_y -1) : _y)
172+
#define YEAR_ABS(_y) (_y <= 0 ? -(_y -1) : _y)
173173
#define BC_STR_ORIG " BC"
174174

175175
#define A_D_STR "A.D."
@@ -2119,7 +2119,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
21192119
case DCH_B_C:
21202120
if (flag == TO_CHAR)
21212121
{
2122-
strcpy(inout, (tm->tm_year < 0 ? B_C_STR : A_D_STR));
2122+
strcpy(inout, (tm->tm_year <= 0 ? B_C_STR : A_D_STR));
21232123
return 3;
21242124

21252125
}
@@ -2134,7 +2134,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
21342134
case DCH_BC:
21352135
if (flag == TO_CHAR)
21362136
{
2137-
strcpy(inout, (tm->tm_year < 0 ? BC_STR : AD_STR));
2137+
strcpy(inout, (tm->tm_year <= 0 ? BC_STR : AD_STR));
21382138
return 1;
21392139

21402140
}
@@ -2149,7 +2149,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
21492149
case DCH_b_c:
21502150
if (flag == TO_CHAR)
21512151
{
2152-
strcpy(inout, (tm->tm_year < 0 ? b_c_STR : a_d_STR));
2152+
strcpy(inout, (tm->tm_year <= 0 ? b_c_STR : a_d_STR));
21532153
return 3;
21542154

21552155
}
@@ -2164,7 +2164,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
21642164
case DCH_bc:
21652165
if (flag == TO_CHAR)
21662166
{
2167-
strcpy(inout, (tm->tm_year < 0 ? bc_STR : ad_STR));
2167+
strcpy(inout, (tm->tm_year <= 0 ? bc_STR : ad_STR));
21682168
return 1;
21692169

21702170
}

src/backend/utils/adt/timestamp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.102 2004/03/22 01:38:17 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.103 2004/03/30 15:53:18 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3261,7 +3261,11 @@ timestamp_part(PG_FUNCTION_ARGS)
32613261
break;
32623262

32633263
case DTK_YEAR:
3264-
result = tm->tm_year;
3264+
if (tm->tm_year > 0)
3265+
result = tm->tm_year;
3266+
else
3267+
/* there is no year 0, just 1 BC and 1 AD*/
3268+
result = tm->tm_year - 1;
32653269
break;
32663270

32673271
case DTK_DECADE:

0 commit comments

Comments
 (0)