aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/sgml/func.sgml8
-rw-r--r--src/backend/utils/adt/datetime.c6
-rw-r--r--src/backend/utils/adt/formatting.c12
-rw-r--r--src/backend/utils/adt/timestamp.c8
4 files changed, 19 insertions, 15 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index ccd430a97ff..19d35765178 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1,5 +1,5 @@
<!--
-$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.195 2004/03/19 19:13:26 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.196 2004/03/30 15:53:18 momjian Exp $
PostgreSQL documentation
-->
@@ -5216,8 +5216,7 @@ SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
<term><literal>week</literal></term>
<listitem>
<para>
- The number of
- the week of the year that the day is in. By definition
+ The number of the week of the year that the day is in. By definition
(<acronym>ISO</acronym> 8601), the first week of a year
contains January 4 of that year. (The <acronym>ISO</acronym>-8601
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');
<term><literal>year</literal></term>
<listitem>
<para>
- The year field
+ The year field. Keep in mind there is no <literal>0 AD</>, so subtracting
+ <literal>BC</> years from <literal>AD</> years should be done with care.
</para>
<screen>
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 5f340dd2a13..be764ce45e2 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.125 2004/02/25 19:41:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.126 2004/03/30 15:53:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -93,7 +93,7 @@ static datetkn datetktbl[] = {
{"acsst", DTZ, POS(42)}, /* Cent. Australia */
{"acst", DTZ, NEG(16)}, /* Atlantic/Porto Acre Summer Time */
{"act", TZ, NEG(20)}, /* Atlantic/Porto Acre Time */
- {DA_D, ADBC, AD}, /* "ad" for years >= 0 */
+ {DA_D, ADBC, AD}, /* "ad" for years > 0 */
{"adt", DTZ, NEG(12)}, /* Atlantic Daylight Time */
{"aesst", DTZ, POS(44)}, /* E. Australia */
{"aest", TZ, POS(40)}, /* Australia Eastern Std Time */
@@ -139,7 +139,7 @@ static datetkn datetktbl[] = {
{"azot", TZ, NEG(4)}, /* Azores Time */
{"azst", DTZ, POS(20)}, /* Azerbaijan Summer Time */
{"azt", TZ, POS(16)}, /* Azerbaijan Time */
- {DB_C, ADBC, BC}, /* "bc" for years < 0 */
+ {DB_C, ADBC, BC}, /* "bc" for years <= 0 */
{"bdst", TZ, POS(8)}, /* British Double Summer Time */
{"bdt", TZ, POS(24)}, /* Dacca */
{"bnt", TZ, POS(32)}, /* Brunei Darussalam Time */
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 25db1b0f5d3..3393a0ac4ce 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* formatting.c
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.72 2004/01/07 18:56:28 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.73 2004/03/30 15:53:18 momjian Exp $
*
*
* Portions Copyright (c) 1999-2003, PostgreSQL Global Development Group
@@ -169,7 +169,7 @@ static char *months_full[] = {
* AC / DC
* ----------
*/
-#define YEAR_ABS(_y) (_y < 0 ? -(_y -1) : _y)
+#define YEAR_ABS(_y) (_y <= 0 ? -(_y -1) : _y)
#define BC_STR_ORIG " BC"
#define A_D_STR "A.D."
@@ -2119,7 +2119,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_B_C:
if (flag == TO_CHAR)
{
- strcpy(inout, (tm->tm_year < 0 ? B_C_STR : A_D_STR));
+ strcpy(inout, (tm->tm_year <= 0 ? B_C_STR : A_D_STR));
return 3;
}
@@ -2134,7 +2134,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_BC:
if (flag == TO_CHAR)
{
- strcpy(inout, (tm->tm_year < 0 ? BC_STR : AD_STR));
+ strcpy(inout, (tm->tm_year <= 0 ? BC_STR : AD_STR));
return 1;
}
@@ -2149,7 +2149,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_b_c:
if (flag == TO_CHAR)
{
- strcpy(inout, (tm->tm_year < 0 ? b_c_STR : a_d_STR));
+ strcpy(inout, (tm->tm_year <= 0 ? b_c_STR : a_d_STR));
return 3;
}
@@ -2164,7 +2164,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_bc:
if (flag == TO_CHAR)
{
- strcpy(inout, (tm->tm_year < 0 ? bc_STR : ad_STR));
+ strcpy(inout, (tm->tm_year <= 0 ? bc_STR : ad_STR));
return 1;
}
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 11a75cc2bd5..dafc8ae5bed 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.102 2004/03/22 01:38:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.103 2004/03/30 15:53:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3261,7 +3261,11 @@ timestamp_part(PG_FUNCTION_ARGS)
break;
case DTK_YEAR:
- result = tm->tm_year;
+ if (tm->tm_year > 0)
+ result = tm->tm_year;
+ else
+ /* there is no year 0, just 1 BC and 1 AD*/
+ result = tm->tm_year - 1;
break;
case DTK_DECADE: