A few more WTFs and this could collapse into a WTF black hole.



  •  Found in a jsp page I have the misfortune of maintaining. Thankfully this isn't actually used anywhere.

     

    String getDate(ResultSet rset, int a) {
    String retun_String=null;

    try {
    if (rset.getDate(a).getDate()<10) {
    retun_String="0" + rset.getDate(a).getDate() + "/";
    } else {
    retun_String=rset.getDate(a).getDate() + "/";
    }

    int month;
    month = rset.getDate(a).getMonth()+1;
    if (month<10) {
    retun_String=retun_String + "0" + month + "/";
    } else {
    retun_String=retun_String + month + "/";
    }

    int year = rset.getDate(a).getYear() + 1900;
    retun_String=retun_String + year;

    } catch (SQLException sqle) {  }
    finally { return retun_String; }
    }

     

    tl;dr version: No indentation, single-letter variable, all dates are obviously in the 20th century, manually formatting dates, can't even declare a single variable without a typo, should have become an accountant.

     

    tl;dr;tl;dr version: java clusterf*ck.



  • @DOA said:

    int year = rset.getDate(a).getYear() + 1900;

    Heh, a Y3.9K bug.



  • Well, at least SQL exceptions are handled caught.



  • Also: calling rset.getDate(a) repeatedly and not using a string buffer, though that's minor.



  •  @DOA said:

    tl;dr version: No indentation, single-letter variable, all dates are obviously in the 20th century, manually formatting dates, can't even declare a single variable without a typo, should have become an accountant.

     

    Well, dates up to 2999 will work, so I don't think that will be a problem, but yeah, why is DateFormatter so difficult for people to use?

     



  • @DOA said:

    tl;dr;tl;dr version: java clusterf*ck.

    Can someone sum this up for me?



  • @morbiuswilters said:

    @DOA said:

    tl;dr;tl;dr version: java clusterf*ck.

    Can someone sum this up for me?

    You pretty much just did.  But essentially it's a horribly retarded way to add leading zeroes to a date.


  • @DOA said:

    all dates are obviously in the 20th century
     

    JavaScript 1.3: deprecated; also getYear returns the year minus 1900 regardless of the date specified. 

    So 1900 + getYear does actually return the current year.

    EDIT: After posting this I remembered IE getYear gives you the full year if it's greater than 1999, or 2 digit year if less.  Yay standards.

    More EDIT:  I guess that's Java, not Javascript? So if I read the javadocs right, my initial post is correct.  Java's Date.getYear() follows the same behavior as ECMAScript's



  • @vt_mruhlin said:

    @DOA said:

    all dates are obviously in the 20th century
     

    JavaScript 1.3: deprecated; also getYear returns the year minus 1900 regardless of the date specified. 

    So 1900 + getYear does actually return the current year.

    EDIT: After posting this I remembered IE getYear gives you the full year if it's greater than 1999, or 2 digit year if less.  Yay standards.

    More EDIT:  I guess that's Java, not Javascript? So if I read the javadocs right, my initial post is correct.  Java's Date.getYear() follows the same behavior as ECMAScript's


    The behaviour comes from the Unix gmtime(3) and localtime(3) functions (also note the zero-based month) and since everybody already knows that, it is followed by most APIs except the ones from Microsoft, who does not like to follow anything. Of course the asctime(3) and ctime(3) come from the same era and most date APIs provide their equivalent, usually even using the same format specifications, so there's no excuse for formatting dates manually.



  • @Bulb said:

    The behaviour comes from the Unix gmtime(3) and localtime(3) functions (also note the zero-based month) and since everybody already knows that, it is followed by most APIs except the ones from Microsoft, who does not like to follow anything.
     

    The C datetime API is so ugly that anybody following that should be shot. It's so counterintuitive that, unless you use it very often, you will have to learn it again each time you want to use it.


Log in to reply