struct pg_tm tm;
DateADT date;
int dterr;
+ bool bc = false;
tm.tm_year = PG_GETARG_INT32(0);
tm.tm_mon = PG_GETARG_INT32(1);
tm.tm_mday = PG_GETARG_INT32(2);
- /*
- * Note: we'll reject zero or negative year values. Perhaps negatives
- * should be allowed to represent BC years?
- */
- dterr = ValidateDate(DTK_DATE_M, false, false, false, &tm);
+ /* Handle negative years as BC */
+ if (tm.tm_year < 0)
+ {
+ bc = true;
+ tm.tm_year = -tm.tm_year;
+ }
+
+ dterr = ValidateDate(DTK_DATE_M, false, false, bc, &tm);
if (dterr != 0)
ereport(ERROR,
07-15-2013
(1 row)
+select make_date(-44, 3, 15);
+ make_date
+---------------
+ 03-15-0044 BC
+(1 row)
+
select make_time(8, 20, 0.0);
make_time
-----------
ERROR: date field value out of range: 2013-13-01
select make_date(2013, 11, -1);
ERROR: date field value out of range: 2013-11--1
-select make_date(-44, 3, 15); -- perhaps we should allow this sometime?
-ERROR: date field value out of range: -44-03-15
select make_time(10, 55, 100.1);
ERROR: time field value out of range: 10:55:100.1
select make_time(24, 0, 2.1);
-- test constructors
select make_date(2013, 7, 15);
+select make_date(-44, 3, 15);
select make_time(8, 20, 0.0);
-- should fail
select make_date(2013, 2, 30);
select make_date(2013, 13, 1);
select make_date(2013, 11, -1);
-select make_date(-44, 3, 15); -- perhaps we should allow this sometime?
select make_time(10, 55, 100.1);
select make_time(24, 0, 2.1);