Index: doc/src/sgml/func.sgml =================================================================== RCS file: /cvsroot/pgsql-server/doc/src/sgml/func.sgml,v retrieving revision 1.195 diff -c -c -r1.195 func.sgml *** doc/src/sgml/func.sgml 19 Mar 2004 19:13:26 -0000 1.195 --- doc/src/sgml/func.sgml 29 Mar 2004 20:31:28 -0000 *************** *** 5216,5223 **** week ! The number of ! the week of the year that the day is in. By definition (ISO 8601), the first week of a year contains January 4 of that year. (The ISO-8601 week starts on Monday.) In other words, the first Thursday of --- 5216,5222 ---- week ! The number of the week of the year that the day is in. By definition (ISO 8601), the first week of a year contains January 4 of that year. (The ISO-8601 week starts on Monday.) In other words, the first Thursday of *************** *** 5235,5241 **** year ! The year field --- 5234,5241 ---- year ! The year field. Keep in mind there is no 0 AD, so subtracting ! BC years from AD years should be done with care. Index: src/backend/utils/adt/datetime.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/utils/adt/datetime.c,v retrieving revision 1.125 diff -c -c -r1.125 datetime.c *** src/backend/utils/adt/datetime.c 25 Feb 2004 19:41:23 -0000 1.125 --- src/backend/utils/adt/datetime.c 29 Mar 2004 20:31:34 -0000 *************** *** 93,99 **** {"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 */ {"adt", DTZ, NEG(12)}, /* Atlantic Daylight Time */ {"aesst", DTZ, POS(44)}, /* E. Australia */ {"aest", TZ, POS(40)}, /* Australia Eastern Std Time */ --- 93,99 ---- {"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 */ {"adt", DTZ, NEG(12)}, /* Atlantic Daylight Time */ {"aesst", DTZ, POS(44)}, /* E. Australia */ {"aest", TZ, POS(40)}, /* Australia Eastern Std Time */ *************** *** 139,145 **** {"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 */ {"bdst", TZ, POS(8)}, /* British Double Summer Time */ {"bdt", TZ, POS(24)}, /* Dacca */ {"bnt", TZ, POS(32)}, /* Brunei Darussalam Time */ --- 139,145 ---- {"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 */ {"bdst", TZ, POS(8)}, /* British Double Summer Time */ {"bdt", TZ, POS(24)}, /* Dacca */ {"bnt", TZ, POS(32)}, /* Brunei Darussalam Time */ Index: src/backend/utils/adt/formatting.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/utils/adt/formatting.c,v retrieving revision 1.72 diff -c -c -r1.72 formatting.c *** src/backend/utils/adt/formatting.c 7 Jan 2004 18:56:28 -0000 1.72 --- src/backend/utils/adt/formatting.c 29 Mar 2004 20:31:40 -0000 *************** *** 169,175 **** * AC / DC * ---------- */ ! #define YEAR_ABS(_y) (_y < 0 ? -(_y -1) : _y) #define BC_STR_ORIG " BC" #define A_D_STR "A.D." --- 169,175 ---- * AC / DC * ---------- */ ! #define YEAR_ABS(_y) (_y <= 0 ? -(_y -1) : _y) #define BC_STR_ORIG " BC" #define A_D_STR "A.D." *************** *** 2119,2125 **** case DCH_B_C: if (flag == TO_CHAR) { ! strcpy(inout, (tm->tm_year < 0 ? B_C_STR : A_D_STR)); return 3; } --- 2119,2125 ---- case DCH_B_C: if (flag == TO_CHAR) { ! strcpy(inout, (tm->tm_year <= 0 ? B_C_STR : A_D_STR)); return 3; } *************** *** 2134,2140 **** case DCH_BC: if (flag == TO_CHAR) { ! strcpy(inout, (tm->tm_year < 0 ? BC_STR : AD_STR)); return 1; } --- 2134,2140 ---- case DCH_BC: if (flag == TO_CHAR) { ! strcpy(inout, (tm->tm_year <= 0 ? BC_STR : AD_STR)); return 1; } *************** *** 2149,2155 **** case DCH_b_c: if (flag == TO_CHAR) { ! strcpy(inout, (tm->tm_year < 0 ? b_c_STR : a_d_STR)); return 3; } --- 2149,2155 ---- case DCH_b_c: if (flag == TO_CHAR) { ! strcpy(inout, (tm->tm_year <= 0 ? b_c_STR : a_d_STR)); return 3; } *************** *** 2164,2170 **** case DCH_bc: if (flag == TO_CHAR) { ! strcpy(inout, (tm->tm_year < 0 ? bc_STR : ad_STR)); return 1; } --- 2164,2170 ---- case DCH_bc: if (flag == TO_CHAR) { ! strcpy(inout, (tm->tm_year <= 0 ? bc_STR : ad_STR)); return 1; } Index: src/backend/utils/adt/timestamp.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/utils/adt/timestamp.c,v retrieving revision 1.102 diff -c -c -r1.102 timestamp.c *** src/backend/utils/adt/timestamp.c 22 Mar 2004 01:38:17 -0000 1.102 --- src/backend/utils/adt/timestamp.c 29 Mar 2004 20:31:44 -0000 *************** *** 3261,3267 **** break; case DTK_YEAR: ! result = tm->tm_year; break; case DTK_DECADE: --- 3261,3271 ---- break; case DTK_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: