Date in yyyyy-mm-dd format not throwing an error

Well, it may sound strange, but I see that when converting a string to a date, the value 20155-10-10 did not throw an invalid date error.

the function used is below

fn-bea:date-from-string-with-format("MM/dd/yyyy",'10/10/20155')

      

the above function returns the date 20155-10-10 when the above string is passed in and also checked by the schema. the field is declared as type xs: date

function prototype is

fn-bea:date-from-string-with-format($format as xs:string?, $dateString as xs:string?) as xs:date?

      

go to the link http://docs.oracle.com/cd/E13167_01/aldsp/docs25/xquery/extensions.html#wp1297249 to use the function and example

+3


source to share


1 answer


This is expected and documented behavior, although admittedly surprising.

OSB Date Templates

Oracle documentationfn-bea:date-from-string-with-format(...)

does not contain the following note about date patterns (emphasis added by me):

You can create date and time patterns using standard Java class characters . [...] Repeat each character to match the maximum number of characters needed to represent the actual value. [...]

So OSB uses the default Java date patterns and YYYY

sets a date that requires a year declaration of at least four digits, but allows arbitrary longer ones. For example, MM/dd/yyyy

matches 23/02/2014

and 23/02/20155

; but not 23/02/42

.

Java date patterns



Looking at the Java specs to see this, even the last date (in year 42) will be resolved:

For parsing, if the number of pattern letters is greater than 2, the year is interpreted literally, regardless of the number of digits. So using the pattern "MM / dd / yyyy", "01/11/12" parses to 11 January 12 AD

OSB might be using its own parsing rules along with the Java date class characters.


I have not tested the OSB that is in use, but both specifications allow five-digit years for YYYY

.

+4


source







All Articles