validdate question.



IBM's cross-platform compiler PL/I for MVS, VM & VSE, OS/390 and Enterprise PL/I for z/OS

validdate question.

Postby igorkigork » Tue Jun 29, 2010 1:27 am

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
igorkigork
 
Posts: 16
Joined: Thu Feb 11, 2010 9:56 pm
Has thanked: 0 time
Been thanked: 0 time

Re: validdate question.

Postby dick scherrer » Tue Jun 29, 2010 2:25 am

Hello,

Possibly because a "day" may begin with 1 or 2 or 3 but not 4 and higher. . .?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: validdate question.

Postby igorkigork » Tue Jun 29, 2010 8:14 pm

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.
igorkigork
 
Posts: 16
Joined: Thu Feb 11, 2010 9:56 pm
Has thanked: 0 time
Been thanked: 0 time

Re: validdate question.

Postby enrico-sorichetti » Tue Jun 29, 2010 8:15 pm

since You specified the date mask as YYYYMMDD
I would check for a length of 8 before the validdate call
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: validdate question.

Postby igorkigork » Tue Jun 29, 2010 8:39 pm

Enrico,

in my example the length of '2010013 ' is - 8.
igorkigork
 
Posts: 16
Joined: Thu Feb 11, 2010 9:56 pm
Has thanked: 0 time
Been thanked: 0 time

Re: validdate question.

Postby enrico-sorichetti » Tue Jun 29, 2010 8:49 pm

:oops: I had not noticed the blanks
then use the VERIFY builtin to check for 8 numbers
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: validdate question.

Postby igorkigork » Tue Jun 29, 2010 9:40 pm

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...
igorkigork
 
Posts: 16
Joined: Thu Feb 11, 2010 9:56 pm
Has thanked: 0 time
Been thanked: 0 time

Re: validdate question.

Postby enrico-sorichetti » Tue Jun 29, 2010 10:17 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: validdate question.

Postby dick scherrer » Tue Jun 29, 2010 11:50 pm

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.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: validdate question.

Postby igorkigork » Wed Jun 30, 2010 1:48 am

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.
igorkigork
 
Posts: 16
Joined: Thu Feb 11, 2010 9:56 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post