Comment On All For 19 Seconds

Date and Time computations aren’t easy. Unless you’re fortunate enough to use Metric Time, there are a whole lot of uneven measurements to work with. Sixty seconds in a minute. Twenty four hours in a day. Thirty, thirty one, twenty eight, maybe twenty nine days in a month. Fifty two point something weeks in a year. It’s just ugly. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: All For 19 Seconds

2007-09-21 10:37 • by SomeCoder (unregistered)
The real WTF is that they hardcoded the 19 seconds...

In all seriousness... my eyes, the goggles do nothing!!

Re: All For 19 Seconds

2007-09-21 10:41 • by T604
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.

Re: All For 19 Seconds

2007-09-21 10:46 • by Macxdmg (unregistered)
I did this, back in CS160 the day before they told us about the time functionality. sad

Re: All For 19 Seconds

2007-09-21 10:48 • by diaphanein (unregistered)
ignorance of a library is bad, but this is atrocious:


if (($year == 2008)||($year == 2012)){


HARDCODING for leap-year detection?!? Oi.

Re: All For 19 Seconds

2007-09-21 10:51 • by Vechni
oh we've all done this before when we were new.

Re: All For 19 Seconds

2007-09-21 10:52 • by Kokuma
154198 in reply to 154195
diaphanein:
ignorance of a library is bad, but this is atrocious:


if (($year == 2008)||($year == 2012)){


HARDCODING for leap-year detection?!? Oi.


At least, he doesn't expect his code to be running in 2016...

Re: All For 19 Seconds

2007-09-21 10:53 • by Tes (unregistered)
154199 in reply to 154195
diaphanein:
ignorance of a library is bad, but this is atrocious:


if (($year == 2008)||($year == 2012)){


HARDCODING for leap-year detection?!? Oi.

leap-year?? He's only hardcoding if February has 28 or 29 days. He should have used another four ifs to check if the year is congruent modulo 4 and modulo 400. You never know for how much time your code will be used... even being a WTF!

Re: All For 19 Seconds

2007-09-21 10:53 • by Tes (unregistered)
154200 in reply to 154195
diaphanein:
ignorance of a library is bad, but this is atrocious:


if (($year == 2008)||($year == 2012)){


HARDCODING for leap-year detection?!? Oi.

leap-year?? He's only hardcoding if February has 28 or 29 days. He should have used another four ifs to check if the year is congruent modulo 4 and modulo 400. You never know for how much time your code will be used... even being a WTF!

Re: All For 19 Seconds

2007-09-21 10:56 • by Vechni
if ($month == 2){
if (($year == 2008)||($year == 2012)){
if ($day < 29){$day++;}
else{$day = 1;$month = 3;}

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!

Re: All For 19 Seconds

2007-09-21 11:01 • by realmerlyn
Nobody has commented on
my $hour = $date[2]+4;
yet. Apparently, he's computing localtime by hard-coding the GMT offset! That's gonna break, half of the year. Great.

Re: All For 19 Seconds

2007-09-21 11:08 • by awt (unregistered)
Superb :-))

"Before August, odd months have 31 days; from August
onwards, even months do." It's the good old counting-on-the-knuckles trick.

Re: All For 19 Seconds

2007-09-21 11:10 • by gsmalleus
my $year = $date[5]+1900;


This doesn't seem very Y2K friendly.

Re: All For 19 Seconds

2007-09-21 11:12 • by Andrew (unregistered)
154211 in reply to 154204
realmerlyn:
Nobody has commented on
my $hour = $date[2]+4;
yet. Apparently, he's computing localtime by hard-coding the GMT offset! That's gonna break, half of the year. Great.


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.

Re: All For 19 Seconds

2007-09-21 11:14 • by Kemp
154212 in reply to 154210
gsmalleus:
my $year = $date[5]+1900;


This doesn't seem very Y2K friendly.


The whole thing doesn't seem friendly to anything except his LOC count.

Re: All For 19 Seconds

2007-09-21 11:20 • by B (unregistered)
154214 in reply to 154191
SomeCoder:
The real WTF is that they hardcoded the 19 seconds...

In all seriousness... my eyes, the goggles do nothing!!


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.

Re: All For 19 Seconds

2007-09-21 11:29 • by derula
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?

Re: All For 19 Seconds

2007-09-21 11:31 • by dnm (unregistered)
154218 in reply to 154210
gsmalleus:
my $year = $date[5]+1900;


This doesn't seem very Y2K friendly.


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."

Re: All For 19 Seconds

2007-09-21 11:32 • by Anonymous (unregistered)
154219 in reply to 154210
gsmalleus:
my $year = $date[5]+1900;


This doesn't seem very Y2K friendly.


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.

Re: All For 19 Seconds

2007-09-21 11:33 • by dekarguy (unregistered)
newTime = ConvertTimeToSeconds(time)
newTime += 19
time = ConvertSecondsToTime(newTime)

simple enough, right? :)


Captcha: onomatopoeia (I hope I spell it right)

Re: All For 19 Seconds

2007-09-21 11:35 • by Aquatoad (unregistered)
154221 in reply to 154210
Actually, this is correct in the UNIX world.
From the StdC gmtime() documentation:

int tm_year; /* years since 1900 */

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().

Re: All For 19 Seconds

2007-09-21 11:37 • by Synonymous Awkward (unregistered)
154222 in reply to 154220
dekarguy:
newTime = ConvertTimeToSeconds(time)
newTime += 19
time = ConvertSecondsToTime(newTime)

simple enough, right? :)


Captcha: onomatopoeia (I hope I spell it right)


So you thought you'd type it a second time for practice?

Re: All For 19 Seconds

2007-09-21 11:39 • by Aquatoad (unregistered)
154224 in reply to 154219
Anonymous:

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.


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.

Re: All For 19 Seconds

2007-09-21 11:42 • by diggity (unregistered)
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

Re: All For 19 Seconds

2007-09-21 11:54 • by anonymouse (unregistered)
The real wtf is that he isn't accounting for leap seconds

Re: All For 19 Seconds

2007-09-21 11:57 • by Asd (unregistered)
154233 in reply to 154224
Aquatoad:

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.

You are not wrong. God save us from java.util.Calendar

Re: All For 19 Seconds

2007-09-21 12:17 • by bob ardkor
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.

Re: All For 19 Seconds

2007-09-21 12:19 • by CynicalTyler (unregistered)
154241 in reply to 154233
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.

Re: All For 19 Seconds

2007-09-21 12:20 • by Spectre
Um, gmtime library? That ought to say "gmtime library function" or something similar.

Re: All For 19 Seconds

2007-09-21 12:38 • by n9ds
154247 in reply to 154220
dekarguy:

Captcha: onomatopoeia (I hope I spell it right)

You spelled it right, but it still sounds wrong.

Re: All For 19 Seconds

2007-09-21 12:40 • by ParkinT
154248 in reply to 154218
dnm:
gsmalleus:
my $year = $date[5]+1900;


This doesn't seem very Y2K friendly.


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."


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!

Re: All For 19 Seconds

2007-09-21 12:51 • by tmountjr
154254 in reply to 154240
bob ardkor:
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.


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?

Re: All For 19 Seconds

2007-09-21 12:56 • by skington
154255 in reply to 154254
tmountjr:
Any why on earth did he name his function "ToMoney"??? Am I missing something in the French back-and-forth that mentions money?


The numbers he's formatting are prices.

Re: All For 19 Seconds

2007-09-21 13:02 • by Theo (unregistered)
154260 in reply to 154254
tmountjr:

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?

No they don't mention money, I guess the original purpose of the method was to display the number with a currency, for an amount of money... That's another WTF, naming methods for the purpose and not according to what they actually do...

like getTheResultIWant()

Anyway, you're right, it's evwen better than the current WTF :)

I'm off to get some captcha (tacos)

Re: All For 19 Seconds

2007-09-21 13:33 • by Mr Fred (unregistered)
154265 in reply to 154212
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.



Re: All For 19 Seconds

2007-09-21 13:38 • by Mr Fred (unregistered)
154266 in reply to 154233
Asd:
Aquatoad:

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.

You are not wrong. God save us from java.util.Calendar


Be careful what you wish for, you might get it. Hint: see JSR 310.


Re: All For 19 Seconds

2007-09-21 13:42 • by Mr Fred (unregistered)
The real WTF is that they are using Perl.

Re: All For 19 Seconds

2007-09-21 13:42 • by ahgan (unregistered)
154269 in reply to 154195
diaphanein:
ignorance of a library is bad, but this is atrocious:


if (($year == 2008)||($year == 2012)){


HARDCODING for leap-year detection?!? Oi.


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

Re: All For 19 Seconds

2007-09-21 13:49 • by Michael (unregistered)
154271 in reply to 154233
Asd:
God save us from java.util.Calendar

http://jcp.org/en/jsr/detail?id=310
https://jsr-310.dev.java.net/

Re: All For 19 Seconds

2007-09-21 13:53 • by Corey (unregistered)
154274 in reply to 154268
Mr Fred:
The real WTF is that they are using Perl.


The fact that I see this type of comment no matter what the language is leads me to believe that the actual real WTF is that they're using a computer at all.

Re: All For 19 Seconds

2007-09-21 13:53 • by Steve (unregistered)
Lots of WTFs...

Isn't ($month==2) checking March, not February? Month is 0-based in Perl IIRC

Re: All For 19 Seconds

2007-09-21 14:08 • by sinistral
154277 in reply to 154275
Steve:
Lots of WTFs...

Isn't ($month==2) checking March, not February? Month is 0-based in Perl IIRC


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.

And his next assignment was…

2007-09-21 14:24 • by Someone (unregistered)
"expand your solution from exercise 1 to take leap seconds into account".

Re: All For 19 Seconds

2007-09-21 14:47 • by realmerlyn
154282 in reply to 154265
Mr Fred:
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.





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.

Re: All For 19 Seconds

2007-09-21 14:48 • by Pingmaster
154284 in reply to 154201
Vechni:
if ($month == 2){
if (($year == 2008)||($year == 2012)){
if ($day < 29){$day++;}
else{$day = 1;$month = 3;}

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!


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.

Re: All For 19 Seconds

2007-09-21 15:14 • by Tp (unregistered)
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!"

Re: All For 19 Seconds

2007-09-21 15:21 • by wiregoat (unregistered)
154289 in reply to 154288
Tp:
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!"


And hold your nose

captcha = tesla. Shocking

Re: All For 19 Seconds

2007-09-21 15:26 • by James (unregistered)
154291 in reply to 154197
Vechni:
oh we've all done this before when we were new.


Nope, I was born lazy -- and remember, kids, Lazy Is A Virtue.

Re: All For 19 Seconds

2007-09-21 15:31 • by Vechni
154293 in reply to 154288
Tp:
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!"

LMAO

Re: All For 19 Seconds

2007-09-21 15:35 • by Nobody (unregistered)
154297 in reply to 154191
That should be:

my @time = gmtime(time + 19);

-not-

my @ time = gmtime(time + 19);

No spaces allowed in Perl identifiers!

Re: And his next assignment was…

2007-09-21 15:51 • by iMalc (unregistered)
154298 in reply to 154279
Someone:
"expand your solution from exercise 1 to take leap seconds into account".
Yeah, except you can't anyway because they don't occur at precise calculateable times, their coming is announced.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment