Page 1 of 2

validdate question.

PostPosted: Tue Jun 29, 2010 1:27 am
by igorkigork
Could you please help me explain the following results:

program:

DCL VALIDDATE BUILTIN;

IF    VALIDDATE('2010011 ','YYYYMMDD')                       
THEN PUT SKIP LIST (''''||'2010011 '||''''|| ' IS VALID '); 
ELSE PUT SKIP LIST (''''||'2010011 '||''''|| ' IS NOT   '); 
IF    VALIDDATE('2010012 ','YYYYMMDD')                       
THEN PUT SKIP LIST (''''||'2010012 '||''''|| ' IS VALID '); 
ELSE PUT SKIP LIST (''''||'2010012 '||''''|| ' IS NOT   '); 
IF    VALIDDATE('2010013 ','YYYYMMDD')                       
THEN PUT SKIP LIST (''''||'2010013 '||''''|| ' IS VALID '); 
ELSE PUT SKIP LIST (''''||'2010013 '||''''|| ' IS NOT   '); 
IF    VALIDDATE('2010014 ','YYYYMMDD')                       
THEN PUT SKIP LIST (''''||'2010014 '||''''|| ' IS VALID '); 
ELSE PUT SKIP LIST (''''||'2010014 '||''''|| ' IS NOT   '); 
IF    VALIDDATE('2010015 ','YYYYMMDD')                       
THEN PUT SKIP LIST (''''||'2010015 '||''''|| ' IS VALID '); 
ELSE PUT SKIP LIST (''''||'2010015 '||''''|| ' IS NOT   '); 
IF    VALIDDATE('2010016 ','YYYYMMDD')                       
THEN PUT SKIP LIST (''''||'2010016 '||''''|| ' IS VALID '); 
ELSE PUT SKIP LIST (''''||'2010016 '||''''|| ' IS NOT   '); 
IF    VALIDDATE('2010019 ','YYYYMMDD')                       
THEN PUT SKIP LIST (''''||'2010019 '||''''|| ' IS VALID '); 
ELSE PUT SKIP LIST (''''||'2010019 '||''''|| ' IS NOT   ');


results: ???????

'2010011 ' IS VALID
'2010012 ' IS VALID
'2010013 ' IS VALID
'2010014 ' IS NOT
'2010015 ' IS NOT
'2010016 ' IS NOT
'2010019 ' IS NOT

Re: validdate question.

PostPosted: Tue Jun 29, 2010 2:25 am
by dick scherrer
Hello,

Possibly because a "day" may begin with 1 or 2 or 3 but not 4 and higher. . .?

Re: validdate question.

PostPosted: Tue Jun 29, 2010 8:14 pm
by igorkigork
Dick,

do you think it is the right way?

example:

user makes online transaction and thinks to buy something on '20100103',
he already has drunk enough and mistyped date: '2010013', validdate says - it is the valid
date, edits are passed, and the rest of the business is unpredictable... I understand additional checking might be done, what I do not - why I need something additional to VALIDDATE.

Re: validdate question.

PostPosted: Tue Jun 29, 2010 8:15 pm
by enrico-sorichetti
since You specified the date mask as YYYYMMDD
I would check for a length of 8 before the validdate call

Re: validdate question.

PostPosted: Tue Jun 29, 2010 8:39 pm
by igorkigork
Enrico,

in my example the length of '2010013 ' is - 8.

Re: validdate question.

PostPosted: Tue Jun 29, 2010 8:49 pm
by enrico-sorichetti
:oops: I had not noticed the blanks
then use the VERIFY builtin to check for 8 numbers

Re: validdate question.

PostPosted: Tue Jun 29, 2010 9:40 pm
by igorkigork
Enrico,

there are 6400 ways how to check date, I just think the function VALIDDATE is invalid...
by the way it says '201001 ' is a valid for 'YYYYDDD' mask...

Re: validdate question.

PostPosted: Tue Jun 29, 2010 10:17 pm
by enrico-sorichetti
there are 6400 ways how to check date

glad to see You can count up to that value
if You feel that the VALIDDATE function behavior is improper open an issue with IBM

the behavior seems consistent with the parsing approach
YYYYMMDD will parse as 4 chars for the year, 2 chars for the month the remaining chars are right aligned to 2 chars for the day part
YYYYDDD will parse as 4 chars for the year,the remaining chars are right aligned to 3 chars for the julian day part

thats why I suggested to use the verify/length builtins to check for gross mismatches

Re: validdate question.

PostPosted: Tue Jun 29, 2010 11:50 pm
by dick scherrer
Hello,

I just think the function VALIDDATE is invalid...
It works as advertised. . .

You need to change your understanding of what is valid/invalid. PL/I probably won't be changed because you do not approve of this implementation. . .

So, if you are going to write pl/i code (that actually works correcty) you have to follow the current rules.
he already has drunk enough and mistyped date: '2010013', validdate says - it is the valid
The code needs to always reject incorrect values. . . Even when this requires a bit more/different code.

Re: validdate question.

PostPosted: Wed Jun 30, 2010 1:48 am
by igorkigork
Dick,

read manual, It does not work as advertised:
VALIDDATE returns a '1'B if the string d holds a date/time value that matches the pattern p
pattern is:
...
YYYY Four-digit year
YY Two-digit year
MM Two-digit month
DD Two-digit day within a given month
...

if you think "3 " matches two-digit day - accept my congratulations...

Enrico,
I also have 6400 ideas how it pars chars, but..

Dick, Enrico,

What date compiler pl/i thinks about when it tells "2010013 " is valid?
20100103 or 20100130 ??? based on you posts - Enrico votes for the first one, but Dick for the second.