• SomeCoder (unregistered)

    The real WTF is that they hardcoded the 19 seconds...

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

  • (cs)

    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.

  • Macxdmg (unregistered)

    I did this, back in CS160 the day before they told us about the time functionality. sad

  • diaphanein (unregistered)

    ignorance of a library is bad, but this is atrocious:

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

    HARDCODING for leap-year detection?!? Oi.

  • (cs)

    oh we've all done this before when we were new.

  • (cs) in reply to diaphanein
    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...

  • Tes (unregistered) in reply to diaphanein
    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!

  • Tes (unregistered) in reply to diaphanein
    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!

  • (cs)
               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!

  • (cs)

    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.

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

  • (cs)
    my $year = $date[5]+1900;

    This doesn't seem very Y2K friendly.

  • Andrew (unregistered) in reply to realmerlyn
    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.

  • (cs) in reply to gsmalleus
    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.

  • B (unregistered) in reply to SomeCoder
    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.

  • (cs)

    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?

  • dnm (unregistered) in reply to gsmalleus
    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."

  • Anonymous (unregistered) in reply to gsmalleus
    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.

  • dekarguy (unregistered)

    newTime = ConvertTimeToSeconds(time) newTime += 19 time = ConvertSecondsToTime(newTime)

    simple enough, right? :)

    Captcha: onomatopoeia (I hope I spell it right)

  • Aquatoad (unregistered) in reply to gsmalleus

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

  • Synonymous Awkward (unregistered) in reply to dekarguy
    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?

  • Aquatoad (unregistered) in reply to Anonymous
    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.

  • 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

  • anonymouse (unregistered)

    The real wtf is that he isn't accounting for leap seconds

  • Asd (unregistered) in reply to Aquatoad
    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
  • (cs)

    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.

  • CynicalTyler (unregistered) in reply to Asd

    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.

  • (cs)

    Um, gmtime library? That ought to say "gmtime library function" or something similar.

  • (cs) in reply to dekarguy
    dekarguy:
    Captcha: onomatopoeia (I hope I spell it right)
    You spelled it right, but it still sounds wrong.
  • (cs) in reply to dnm
    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!

  • (cs) in reply to bob ardkor
    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?

  • (cs) in reply to tmountjr
    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.

  • Theo (unregistered) in reply to tmountjr
    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)

  • Mr Fred (unregistered) in reply to Kemp

    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.

  • Mr Fred (unregistered) in reply to Asd
    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.

  • Mr Fred (unregistered)

    The real WTF is that they are using Perl.

  • ahgan (unregistered) in reply to diaphanein
    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

  • Michael (unregistered) in reply to Asd
    Asd:
    God save us from java.util.Calendar
    http://jcp.org/en/jsr/detail?id=310 https://jsr-310.dev.java.net/
  • Corey (unregistered) in reply to Mr Fred
    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.
  • Steve (unregistered)

    Lots of WTFs...

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

  • (cs) in reply to Steve
    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.

  • Someone (unregistered)

    "expand your solution from exercise 1 to take leap seconds into account".

  • (cs) in reply to Mr Fred
    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.

  • (cs) in reply to Vechni
    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.

  • 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!"

  • wiregoat (unregistered) in reply to Tp
    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

  • James (unregistered) in reply to Vechni
    Vechni:
    oh we've all done this before when we were new.

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

  • (cs) in reply to Tp
    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
  • Nobody (unregistered) in reply to SomeCoder

    That should be:

    my @time = gmtime(time + 19);

    -not-

    my @ time = gmtime(time + 19);

    No spaces allowed in Perl identifiers!

  • iMalc (unregistered) in reply to Someone
    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.

Leave a comment on “All For 19 Seconds”

Log In or post as a guest

Replying to comment #:

« Return to Article