- 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
The real WTF is that they hardcoded the 19 seconds...
In all seriousness... my eyes, the goggles do nothing!!
Admin
I want to know what WTF is really at work here. The need to add 19 seconds to a time hints at a bigger wtf.
Admin
I did this, back in CS160 the day before they told us about the time functionality. sad
Admin
ignorance of a library is bad, but this is atrocious:
HARDCODING for leap-year detection?!? Oi.
Admin
oh we've all done this before when we were new.
Admin
At least, he doesn't expect his code to be running in 2016...
Admin
Admin
Admin
haha here is a WTF, this code will work until 2016. After that I suppose this is his way of saying he doesn't plan to be around by then.
Also, using modulo would yield the correct leap year. Oh, or the gmtime library!
Admin
Nobody has commented on
yet. Apparently, he's computing localtime by hard-coding the GMT offset! That's gonna break, half of the year. Great.Admin
Superb :-))
"Before August, odd months have 31 days; from August onwards, even months do." It's the good old counting-on-the-knuckles trick.
Admin
This doesn't seem very Y2K friendly.
Admin
Only if he's in Armenia, Azerbaijan, or Russia. If he's in Georgia, Mauritius, Oman, Réunion, Seychelles or the United Arab Emirates he's fine.
Admin
The whole thing doesn't seem friendly to anything except his LOC count.
Admin
Not to mention the fact that he hardcoded 41 (60-19) at one place, but left it as -19 + 60 in another. Phew! - this has to be one of the best WTFs I have seen for a while.
Admin
The Real WTF is that he doesn't check whether the output of gmtime() is valid. If the date is, say, 1998-14-31, 23:59:59, the result will be 1998-14-31, 00:00:18. I mean, how can't he trust on the time library when he obviously doesn't really know it exists?
Admin
That's one of the only OK lines in the code.
In perl, localtime() returns an array of different parts of the date/time. Element 5 is the number of years since 1900, so 2007 would have a value of 107 in $date[5].
my $new_date = time + 19;
Programmers like this amaze me. Not knowing gmtime exists is excusable. What is NOT excusable is not stopping about 1/10th of the way through that and going, "wait, this is stupid. there has to be an easier way."
Admin
That results from a stupidity in Perl, as you can see if you look at the gmtime docs. The year element of the array returned by gmtime() is equal to the current year minus 1900.
Admin
newTime = ConvertTimeToSeconds(time) newTime += 19 time = ConvertSecondsToTime(newTime)
simple enough, right? :)
Captcha: onomatopoeia (I hope I spell it right)
Admin
Actually, this is correct in the UNIX world. From the StdC gmtime() documentation:
Also, the fix proposed by the submitter isn't correct, since the original code accounts for the offset from GMT, whereas the solution should be using localtime() instead of gmtime().
Admin
So you thought you'd type it a second time for practice?
Admin
Fail! This is a "stupidity" that Perl inherited from Standard C/POSIX. As an aside, I've found that aside from basic math operations (off-by-one errors etc) the biggest atrocities in programming languages occurs in date manipulations.
Admin
my $hour = $date[2]+4;
Apparently this code will only work properly between 04:00 and 24:00 local time, as any time from 00:01 to 03:59 will actually show up as 00:xx
Admin
The real wtf is that he isn't accounting for leap seconds
Admin
Admin
reminds me of a recent post on a (french, sorry) SEO forum :
http://www.webrankinfo.com/forums/viewtopic_80454.htm
for those who don't speak french, the initial poster wants a php function that formats 2500000 to 2,500,000
the first answer is an interesting home-made function.
the second answer is, well, the right answer.
Admin
Ha, good old java.util.Calendar. I once wrote a class that added a certain amount of days (or weeks or months or years) to a date by incrementing the date once for every day. Yeah, I knew it was a WTF, but I was in a hurry and dammit it worked! All that to avoid Java's built in date handling... tsk tsk.
Admin
Um, gmtime library? That ought to say "gmtime library function" or something similar.
Admin
Admin
And furthermore, not simply using the Internet to search for a solution!
As an "old timer" I sometimes fault the younguns for being lazy and jumping directly to Google. But, it is a great resource. If someone else on the planet has faced this problem once before, you can probably find their answer in a few minutes!
Admin
I don't need to know French to find that even funnier than today's CodeSOD. Any why on earth did he name his function "ToMoney"??? Am I missing something in the French back-and-forth that mentions money?
Admin
The numbers he's formatting are prices.
Admin
like getTheResultIWant()
Anyway, you're right, it's evwen better than the current WTF :)
I'm off to get some captcha (tacos)
Admin
The 1900+$date[5] is a Perl-WTF, it is perfectly Y2K friendly so long as you remember that Perl starts counting years from 1900.
That led to some amusing bugs on Jan 1 2000. For example there were those who did string concatenations instead of addition and got Today is Jan 1 19100.
Admin
Be careful what you wish for, you might get it. Hint: see JSR 310.
Admin
The real WTF is that they are using Perl.
Admin
And what happens in 2016, 2020, etc... Only thing better than overly complicated, and unnecessary code is overly complicated, unnecessary, insufficient, and broken code Guess that's what they call job security
Capcha: waffles, Mmmmmmmmmmmmmmmmmmmmmm waffles! :9
Admin
Admin
Admin
Lots of WTFs...
Isn't ($month==2) checking March, not February? Month is 0-based in Perl IIRC
Admin
Not in this case, because the original programmer added 1 to the retrieved value stored in $month, as well as adding 1900 to the $year.
Admin
"expand your solution from exercise 1 to take leap seconds into account".
Admin
Yes, if you google for 19107, and ignore the zip code hits from Philadephia, you can still get quite a bit of amusement. Every one of them WTF-worthy.
Admin
Technically, it would work until Feb 28th at 23:59:40.999, 2020..since that would be the last point that you could add 19 seconds to and the code would return the correct date.
Admin
The real wtf is people actually suggesting improvements to this crap. Its kinda like saying: "HAHA, are you eating shit? In my opinion, you should use less salt!"
Admin
And hold your nose
captcha = tesla. Shocking
Admin
Nope, I was born lazy -- and remember, kids, Lazy Is A Virtue.
Admin
Admin
That should be:
my @time = gmtime(time + 19);
-not-
my @ time = gmtime(time + 19);
No spaces allowed in Perl identifiers!
Admin