Changeset: ed4eedaa420d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ed4eedaa420d
Modified Files:
        monetdb5/modules/atoms/mtime.c
        sql/test/pg_regress/Tests/date.stable.err
        sql/test/pg_regress/Tests/date.stable.out
        sql/test/pg_regress/Tests/time.stable.out
        sql/test/pg_regress/Tests/timestamp.stable.out
        sql/test/pg_regress/Tests/timestamptz.stable.out
        sql/test/snodgrass/Tests/date_parsing.stable.out
Branch: mtime
Log Message:

Some fixes + approvals.


diffs (truncated from 442 to 300 lines):

diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -408,8 +408,9 @@ timestamp_add_usec(timestamp t, lng usec
 
        tm += usec;
        if (tm < 0) {
-               dt = date_add_day(dt, -(int) ((DAY_USEC - tm) / DAY_USEC));
-               tm = DAY_USEC - -tm % DAY_USEC;
+               int add = (int) ((DAY_USEC - 1 - tm) / DAY_USEC);
+               tm += add * DAY_USEC;
+               dt = date_add_day(dt, -add);
        } else if (tm >= DAY_USEC) {
                dt = date_add_day(dt, (int) (tm / DAY_USEC));
                tm %= DAY_USEC;
@@ -582,7 +583,7 @@ parse_date(const char *buf, date *d, boo
                if (day > 31)
                        break;
        }
-       if (yearlast && buf[pos] == ',') {
+       if (yearlast && (buf[pos] == ',' || buf[pos] == ' ')) {
                while (buf[++pos] == ' ')
                        ;
                if (buf[pos] == '-') {
@@ -1592,9 +1593,13 @@ MTIMEtimestamp_diff_msec(lng *ret, const
        *ret = timestamp_diff(*t1, *t2);
        if (!is_lng_nil(*ret)) {
 #ifndef TRUNCATE_NUMBERS
-               *ret += 500;
+               if (*ret < 0)
+                       *ret = -((-*ret + 500) / 1000);
+               else
+                       *ret = (*ret + 500) / 1000;
+#else
+               *ret /= 1000;
 #endif
-               *ret /= 1000;
        }
        return MAL_SUCCEED;
 }
@@ -1637,9 +1642,13 @@ MTIMEtimestamp_diff_msec_bulk(bat *ret, 
                        bn->tnil = true;
                else {
 #ifndef TRUNCATE_NUMBERS
-                       df[i] += 500;
+                       if (df[i] < 0)
+                               df[i] = -((-df[i] + 500) / 1000);
+                       else
+                               df[i] = (df[i] + 500) / 1000;
+#else
+                       df[i] /= 1000;
 #endif
-                       df[i] /= 1000;
                }
        }
        bn->tnonil = !bn->tnil;
diff --git a/sql/test/pg_regress/Tests/date.stable.err 
b/sql/test/pg_regress/Tests/date.stable.err
--- a/sql/test/pg_regress/Tests/date.stable.err
+++ b/sql/test/pg_regress/Tests/date.stable.err
@@ -169,15 +169,7 @@ MAPI  = (monetdb) /var/tmp/mtest-30274/.
 QUERY = SELECT date '08 Jan 1999';
 ERROR = !Incorrect date value (08 Jan 1999) in: "select date '08 Jan 1999';"
 CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
-QUERY = SELECT date 'Jan 08 99';
-ERROR = !Incorrect date value (Jan 08 99) in: "select date 'Jan 08 99';"
-CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
-QUERY = SELECT date 'Jan 08 1999';
-ERROR = !Incorrect date value (Jan 08 1999) in: "select date 'Jan 08 1999';"
-CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
+MAPI  = (monetdb) /var/tmp/mtest-23598/.s.monetdb.38771
 QUERY = SELECT date '99 08 Jan';
 ERROR = !Incorrect date value (99 08 Jan) in: "select date '99 08 Jan';"
 CODE  = 22007
@@ -277,15 +269,7 @@ MAPI  = (monetdb) /var/tmp/mtest-30274/.
 QUERY = SELECT date '08 Jan 1999';
 ERROR = !Incorrect date value (08 Jan 1999) in: "select date '08 Jan 1999';"
 CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
-QUERY = SELECT date 'Jan 08 99';
-ERROR = !Incorrect date value (Jan 08 99) in: "select date 'Jan 08 99';"
-CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
-QUERY = SELECT date 'Jan 08 1999';
-ERROR = !Incorrect date value (Jan 08 1999) in: "select date 'Jan 08 1999';"
-CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
+MAPI  = (monetdb) /var/tmp/mtest-23598/.s.monetdb.38771
 QUERY = SELECT date '99 08 Jan';
 ERROR = !Incorrect date value (99 08 Jan) in: "select date '99 08 Jan';"
 CODE  = 22007
@@ -385,15 +369,7 @@ MAPI  = (monetdb) /var/tmp/mtest-30274/.
 QUERY = SELECT date '08 Jan 1999';
 ERROR = !Incorrect date value (08 Jan 1999) in: "select date '08 Jan 1999';"
 CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
-QUERY = SELECT date 'Jan 08 99';
-ERROR = !Incorrect date value (Jan 08 99) in: "select date 'Jan 08 99';"
-CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
-QUERY = SELECT date 'Jan 08 1999';
-ERROR = !Incorrect date value (Jan 08 1999) in: "select date 'Jan 08 1999';"
-CODE  = 22007
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
+MAPI  = (monetdb) /var/tmp/mtest-23598/.s.monetdb.38771
 QUERY = SELECT date '99 08 Jan';
 ERROR = !Incorrect date value (99 08 Jan) in: "select date '99 08 Jan';"
 CODE  = 22007
diff --git a/sql/test/pg_regress/Tests/date.stable.out 
b/sql/test/pg_regress/Tests/date.stable.out
--- a/sql/test/pg_regress/Tests/date.stable.out
+++ b/sql/test/pg_regress/Tests/date.stable.out
@@ -444,21 +444,21 @@ stdout of test 'date` in directory 'sql/
 % f1,  L4 # name
 % date,        decimal # type
 % 10,  11 # length
-[ 1957-04-09,  0.000   ]
-[ 1957-06-13,  0.000   ]
-[ 1996-02-28,  0.000   ]
-[ 1996-02-29,  0.000   ]
-[ 1996-03-01,  0.000   ]
-[ 1996-03-02,  0.000   ]
-[ 1997-02-28,  0.000   ]
-[ 1997-03-01,  0.000   ]
-[ 1997-03-02,  0.000   ]
-[ 2000-04-01,  0.000   ]
-[ 2000-04-02,  0.000   ]
-[ 2000-04-03,  0.000   ]
-[ 2038-04-08,  0.000   ]
-[ 2039-04-09,  0.000   ]
-[ 2040-04-10,  0.000   ]
+[ 1957-04-09,  0.000000        ]
+[ 1957-06-13,  0.000000        ]
+[ 1996-02-28,  0.000000        ]
+[ 1996-02-29,  0.000000        ]
+[ 1996-03-01,  0.000000        ]
+[ 1996-03-02,  0.000000        ]
+[ 1997-02-28,  0.000000        ]
+[ 1997-03-01,  0.000000        ]
+[ 1997-03-02,  0.000000        ]
+[ 2000-04-01,  0.000000        ]
+[ 2000-04-02,  0.000000        ]
+[ 2000-04-03,  0.000000        ]
+[ 2038-04-08,  0.000000        ]
+[ 2039-04-09,  0.000000        ]
+[ 2040-04-10,  0.000000        ]
 [ NULL,        NULL    ]
 #SELECT f1, extract(hour from cast(f1 as timestamp)) FROM DATE_TBL;
 % sys.date_tbl,        sys.L4 # table_name
@@ -507,21 +507,21 @@ stdout of test 'date` in directory 'sql/
 % f1,  L4 # name
 % date,        decimal # type
 % 10,  11 # length
-[ 1957-04-09,  0.000   ]
-[ 1957-06-13,  0.000   ]
-[ 1996-02-28,  0.000   ]
-[ 1996-02-29,  0.000   ]
-[ 1996-03-01,  0.000   ]
-[ 1996-03-02,  0.000   ]
-[ 1997-02-28,  0.000   ]
-[ 1997-03-01,  0.000   ]
-[ 1997-03-02,  0.000   ]
-[ 2000-04-01,  0.000   ]
-[ 2000-04-02,  0.000   ]
-[ 2000-04-03,  0.000   ]
-[ 2038-04-08,  0.000   ]
-[ 2039-04-09,  0.000   ]
-[ 2040-04-10,  0.000   ]
+[ 1957-04-09,  0.000000        ]
+[ 1957-06-13,  0.000000        ]
+[ 1996-02-28,  0.000000        ]
+[ 1996-02-29,  0.000000        ]
+[ 1996-03-01,  0.000000        ]
+[ 1996-03-02,  0.000000        ]
+[ 1997-02-28,  0.000000        ]
+[ 1997-03-01,  0.000000        ]
+[ 1997-03-02,  0.000000        ]
+[ 2000-04-01,  0.000000        ]
+[ 2000-04-02,  0.000000        ]
+[ 2000-04-03,  0.000000        ]
+[ 2038-04-08,  0.000000        ]
+[ 2039-04-09,  0.000000        ]
+[ 2040-04-10,  0.000000        ]
 [ NULL,        NULL    ]
 #SELECT f1, sql_add(f1, 365*24*60*60.0) FROM DATE_TBL;
 % sys.date_tbl,        sys.L3 # table_name
@@ -787,6 +787,18 @@ stdout of test 'date` in directory 'sql/
 % date # type
 % 10 # length
 [ 1999-01-08   ]
+#SELECT date 'Jan 08 99';
+% .L2 # table_name
+% L2 # name
+% date # type
+% 10 # length
+[ 99-01-08     ]
+#SELECT date 'Jan 08 1999';
+% .L2 # table_name
+% L2 # name
+% date # type
+% 10 # length
+[ 1999-01-08   ]
 #SELECT date '99-01-08';
 % .L2 # table_name
 % L2 # name
@@ -889,6 +901,18 @@ stdout of test 'date` in directory 'sql/
 % date # type
 % 10 # length
 [ 1999-01-08   ]
+#SELECT date 'Jan 08 99';
+% .L2 # table_name
+% L2 # name
+% date # type
+% 10 # length
+[ 99-01-08     ]
+#SELECT date 'Jan 08 1999';
+% .L2 # table_name
+% L2 # name
+% date # type
+% 10 # length
+[ 1999-01-08   ]
 #SELECT date '99-01-08';
 % .L2 # table_name
 % L2 # name
@@ -991,6 +1015,18 @@ stdout of test 'date` in directory 'sql/
 % date # type
 % 10 # length
 [ 1999-01-08   ]
+#SELECT date 'Jan 08 99';
+% .L2 # table_name
+% L2 # name
+% date # type
+% 10 # length
+[ 99-01-08     ]
+#SELECT date 'Jan 08 1999';
+% .L2 # table_name
+% L2 # name
+% date # type
+% 10 # length
+[ 1999-01-08   ]
 #SELECT date '99-01-08';
 % .L2 # table_name
 % L2 # name
@@ -1101,13 +1137,13 @@ stdout of test 'date` in directory 'sql/
 % L2 # name
 % timestamp # type
 % 26 # length
-[ 1001-01-01 00:00:00.000000   ]
+[ 1000-01-01 00:00:00.000000   ]
 #SELECT DATE_TRUNC('CENTURY', TIMESTAMP '1970-03-20 04:30:00.00000'); -- 1901
 % .L2 # table_name
 % L2 # name
 % timestamp # type
 % 26 # length
-[ 1901-01-01 00:00:00.000000   ]
+[ 1900-01-01 00:00:00.000000   ]
 #DROP TABLE DATE_TBL;
 
 # 11:57:21 >  
diff --git a/sql/test/pg_regress/Tests/time.stable.out 
b/sql/test/pg_regress/Tests/time.stable.out
--- a/sql/test/pg_regress/Tests/time.stable.out
+++ b/sql/test/pg_regress/Tests/time.stable.out
@@ -106,11 +106,11 @@ stdout of test 'time` in directory 'sql/
 % f1,  L3 # name
 % time,        decimal # type
 % 11,  11 # length
-[ 00:00:00.00, 0.000   ]
-[ 01:00:00.00, 0.000   ]
-[ 12:00:00.00, 0.000   ]
-[ 12:01:00.00, 0.000   ]
-[ 23:59:00.00, 0.000   ]
+[ 00:00:00.00, 0.000000        ]
+[ 01:00:00.00, 0.000000        ]
+[ 12:00:00.00, 0.000000        ]
+[ 12:01:00.00, 0.000000        ]
+[ 23:59:00.00, 0.000000        ]
 [ NULL,        NULL    ]
 #SELECT f1, extract(hour from f1) FROM TIME_TBL;
 % sys.time_tbl,        sys.L3 # table_name
@@ -139,11 +139,11 @@ stdout of test 'time` in directory 'sql/
 % f1,  L3 # name
 % time,        decimal # type
 % 11,  11 # length
-[ 00:00:00.00, 0.000   ]
-[ 01:00:00.00, 0.000   ]
-[ 12:00:00.00, 0.000   ]
-[ 12:01:00.00, 0.000   ]
-[ 23:59:00.00, 0.000   ]
+[ 00:00:00.00, 0.000000        ]
+[ 01:00:00.00, 0.000000        ]
+[ 12:00:00.00, 0.000000        ]
+[ 12:01:00.00, 0.000000        ]
+[ 23:59:00.00, 0.000000        ]
 [ NULL,        NULL    ]
 #SELECT f1, sql_add(f1, 12*60*60.0 + 66) FROM TIME_TBL;
 % sys.time_tbl,        sys.L3 # table_name
diff --git a/sql/test/pg_regress/Tests/timestamp.stable.out 
b/sql/test/pg_regress/Tests/timestamp.stable.out
--- a/sql/test/pg_regress/Tests/timestamp.stable.out
+++ b/sql/test/pg_regress/Tests/timestamp.stable.out
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to