- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Are you sure that's a regex? It might just be thinly disguised exploit shellcode.
Admin
One of the first exercises given to prospective candidates for a job in my company is to write a short program for counting the number of days between two dates reported in the Gregorian calendar. Checking for accurate handling of leap years is one of the crucial factors. If you're as clueless about the world around you as not to understand that, you're too clueless to work for me.
Admin
Erm... this is a regex to validate a date ... but good lmfao . who the hell hardcodes years and forgets about post 2100... if you're going to hardcode it, do it till the end.
Admin
Quick question though, why not use d at all ?
Admin
Shh Westwood, we all know you're unemployed anyway - and a sock puppet of Zunesis, and we all know what zunie does to socks...
Admin
The logic is in the way it is said. But if you have an international audience it's best to make it explicit i usually add (DD/MM/YYYY) and a picker so everybody knows for filename yyyymmdd makes the best sorting sense. And an other pain is the / . - used to separate the parts (and probably 16 other chars used)
Admin
Then the real WTF is java, this behaviour is completly brain dead so much so it is what javascript does as well.
Admin
(Overall, all this WTF shows is that jwz was right when the regexp user doesn't know what they're doing. Depressing…)
Admin
Admin
Sigh. You're new around here, aren't you?
Admin
Admin
Submitter here :-)
The reason that 20's were rejected was the reason I fell over that piece of shiny regex.
There were about 5 other Versions of the same regex all over the Project - different Versions had different bugs (couldn't even find one that passed a simple Test I wrote just for fun)
It was simply replaced by a DateTime.TryParse btw.
And WTF-Joe isn't a coworker anymore - so it didn't help him to stay.
Admin
If so; The Y3k bug is here!
Admin
It would have also caused problems if you wanted to localize to US M0/DD/YYYY format or ISO YYYY-MM-DD format.
Admin
However, as it only allows years in the range 2000-2099 in the first place, the fact that 1900 and 2100 aren't leap years is about as relevant as the fact that there was no year zero.
Admin
It's "You're" and "insightful". Maybe you need a regex spell-checker.
Admin
Admin
Procedural code is so much better than Regexes
Admin
Typical WTF idiocy responses (at least those that weren't trolls). Validating a date is a two step operation. First, parse the string into numbers for month, day, and year. Second, ensure that the month, day, and year are a valid date. Trying to cram a two part operation into a single line is a guaranteed source of WTFs, typically done by programmers who got A's on all of their homework problems but are complete disaster's when it comes to real work on production systems.
Admin
https://metacpan.org/module/Regexp::Grammars
Admin
Using regular expressions to validate dates just isn't the right tool for the job. It is painstakinly complicated to make sure that all cases are covered.
A quick brute force check of this code revealed that the 10th of every month isn't accepted as a valid date. Did you see that?
This is just an example of why regular expressions shouldn't be used - they are great for validating syntax, but suck at validating semantics.
Also, my check above doesn't cover all the invalid dates that this regex may accept as valid.
The only sane approach is to extract day, month and year, and then do checks on them. It is more readable and doesn't open up for crazy flukes like then one above.
Admin
...and Perl 6, of course.
Admin
Regex is only used to show off knowhow. In real life program I am yet to find any good use for it.
Admin
Admin
I use it regularly (heh). But then, perl makes it easy.
Admin
My bank's website says that dates should be entered in the from "mm/dd/yyyy". And they mean it: If you enter a single digit for the month or the day, they reject the date as invalid.
Admin
Nagesh's manager?
Admin
fixed some smoking shit
Admin
Dear sirs and madams,
I regret to inform you of the untimely passing of Alex for the third time this week. As I will now be souly responsible for the content of this site, you can expect one article per week from this point forward. As I am lazy, however, I will not be changing the name.
Sincerely yours,
Remy Martin
Admin
Before gagging her with his cock
Admin
Admin
Then "Remy" would have to come first.
Admin
After reading the comments, I've realized somthing. Some of you think way too hard about the solution and it's shittiness, without knowing the problem.
There are really only 3 problems with this WTF, in descdending order:
1.) It doesn't account for 10th and 20th dates (someone mentioned this earlier, I didn't confirm) 2.) It's a huge hard to maintain regex
the dates thing comes first, because it means that #2 is true for no reason. You can't even say "at least it works".
As far as it not detecting EVERY leap year, or not thinking < 1900 or > 2100 or dates, that doesn't matter. What if this code isn't to validate that ANY date is correct? It could be validating dates of jobs that this company has taken, which was founded in 2006. That means any job date before then is bad user input even if it's a valid date, and any date too far in the future is also probably bad.
In the above case, the programmer made an assumption that any date this code would ever process should never be from the next century. I see no problem with that... if this crap code is still being used 90 years from now to validate order dates, something more major is wrong. Of course, it means in 2012 I can still enter a job with a date of 2080, which is bogus.
WITH THAT SAID, it's still a WTF. But some of your solutions would actually be less effective at solving the problem, if the case is what I described above. Just use a date library.
Admin
Admin
Show me on the doll where the programmers who got A's touched you.
Admin
You missed the point, obvious troll is trying to incite the grammar nazis.
Admin
Admin
There are 3 kinds of people in the world: those who can count, and those who can't.
Admin
He's very incitefull: he's always inciting trouble.
Admin
Admin
Admin
captcha: suscipere
Admin
I recommend that you read up on perl6 and specifically perl6 grammars and rules.
Example lifted from wikipedia:
Admin
That 20(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96) must have something to do with leap years. Yeah, some basic algebraic operations would have been fine too, but that's cooler.