http://coldfusion.com logo
#cfml-general
Title
# cfml-general
j

John Varady

02/08/2022, 2:13 PM
Copy code
form.st_dob = '04052016';

  writedump(isValid('date', form.st_dob));
  writedump(isDate(form.st_dob));
  writedump(dateDiff('d', now(), form.st_dob));
  writedump(now().diff('d', form.st_dob));
make this make sense - these kind of inconsistencies are nuts
s

sknowlton

02/08/2022, 2:15 PM
works on Lucee, interesting
tbh I'd rather fewer things pass as 'valid' dates, whether with isValid or isDate; seems like CFML is super eager to want to accept something as a date
making your date value
452016
causes Lucee to return
true
for isValid and
false
for isDate
w

websolete

02/08/2022, 2:19 PM
form.st_dob is a string, and it should be incumbent on you to validate that the string representation is valid before doing any date stuff with it, imo. i'd treat it like a string and validate against regexes before testing with the bif for the reasons you're seeing
d

Dave Merrill

02/08/2022, 2:36 PM
Practically speaking I agree, but that said, wth with the bif? A validation function that requires you to validate the data before using it has missed the point IMO.
w

websolete

02/08/2022, 2:38 PM
i don't disagree, date validation has been sketchy with cf for a long time, not sure what to say
a

Adam Cameron

02/08/2022, 2:41 PM
I think there's a point being missed here
This works:
Copy code
dateDiff('d', now(), form.st_dob)
This doesn't:
Copy code
now().diff('d', form.st_dob)
They should be analogous.
w

websolete

02/08/2022, 2:43 PM
guess i missed that, yeah. that's a very good point, i like the way you comb your hair around it.
a

Adam Cameron

02/08/2022, 2:43 PM
It's not to do with string/date ambiguity. It's to do with CF being shite
💯 1
@Mark Takata (Adobe) this is where you come in 😉
w

websolete

02/08/2022, 2:43 PM
i withdraw everything i said up to the combing part
a

Adam Cameron

02/08/2022, 2:44 PM
@John Varady your example could have been clearer, that said. And your question.
s

sknowlton

02/08/2022, 2:47 PM
also the point about
isDate()
and
isValid( 'date' )
having different definitions of a valid date, no?
w

websolete

02/08/2022, 2:48 PM
i seem to recall isValid being the preferred replacement for isDate because of 'better' date validation?
a

Adam Cameron

02/08/2022, 3:08 PM
I didn't even notice that. f***in hell.
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-in-k/isvalid.html
• date or time: any date-time value, including dates or times; equivalent to the IsNumericDate function.
Sigh
However. The behaviour does reflect what's documented, yeah?
j

John Varady

02/08/2022, 3:26 PM
sorry for not being clearer - my issue came down to this if/else falling through and throwing a hard error when I expected the date to be valid. Also I like to use the member functions whenever possible but they should have the same results as the function equivalent
Copy code
if (!isValid('date', form.st_dob)) {
      flash.error('Date of birth is required.');
    } else if (now().diff('d', form.st_dob) < 0) {
      flash.error('Date of birth is in the future.');
    } else if (now().diff('yyyy', form.st_dob) > 20) {
      flash.error('Date of birth is past deadline. Student is over 20 years old.');
    }
1
m

Mark Takata (Adobe)

02/08/2022, 4:25 PM
Copy code
@Mark Takata (Adobe) this is where you come in  :wink:
Not at 6am I don't LOL
a

Adam Cameron

02/08/2022, 4:53 PM
HAHAHA
Sorry honey, didn't mean to wake you.
m

Mark Takata (Adobe)

02/08/2022, 5:07 PM
s'ok. I'm in training so I had to get up anyway lmao
2 Views