Presto: Date constructor should handle year 0 correctly

Created on 20 Apr 2016  路  7Comments  路  Source: prestodb/presto

Year zero is converted to January 2nd of 1 AD:

presto> select date '0000-12-31';
   _col0    
------------
 0001-01-02 
(1 row)

It should be rejected, similar to other invalid dates:

presto> select date '2015-02-29';
Query ... failed: Value cannot be cast to date: 2015-02-29

presto> select date '2016-12-32';
Query ... failed: Value cannot be cast to date: 2016-12-32
beginner-task bug

Most helpful comment

@martint then this is a totally different story. I think I need to find out what's wrong with joda time's iso dat formatter/parser logic.

All 7 comments

I didn't see you assigned yourself @geraint0923.
sorry about that and I'll cancel my PR if you want.

0000 is a valid year. ANSI SQL uses the ISO 8601 notion of year, which allows anything between 0000 and 9999. 0000 is supposed to be 1 BC.

@nazgul33 You don't need to cancel your PR, you could continue to work on this. Thank you very much!

@martint then this is a totally different story. I think I need to find out what's wrong with joda time's iso dat formatter/parser logic.

In my experience, Joda is always correct and my understanding of Date/Timestamps is wrong.

@nazgul33 I figured out that the problem is that we use joda which follows ISO standard and ignore the Julian calendar to parse but use the formatter in java.util which use both Julian calendar and Gregorian calendar to format the output string. I submitted a pull request #5073 in which we use Java 8 time API to format the output string only with Gregorian calendar. Thank you so much for your contribution!

hehehehehe everything finished while I was sleeping. :+1:

Was this page helpful?
0 / 5 - 0 ratings