• wulong (unregistered)

    Of course it's a WTF to not use builtin date functions (obviously a language that allows you to check for AM/PM with an API call probably has a few good date/time API calls), and it's a WTF to not use string formatting when s/he could have.


    tempMinute = ""+Minute;

    This line makes this a major WTF. If the author knew that integers could be turned into strings this way, why did s/he waste 9 lines on the Month??

  • Jeremy Morton (unregistered)

    "why did s/he waste 9 lines on the Month??"

    Twice, even.

  • Lorad (unregistered)

    insertTimeStamp = ""+Year+"."+Month+"."+Day+""+tempHour+":"+tempMinute;

    tempMonth is not even used after all the trouble of setting it.....

  • necroyeti (unregistered)

    is this the result of a 10K loc/day job?

  • Chewbacca (unregistered)

    That should be scenic route unless you were making a pun on the repetitive nature of the code and then it's funny++

  • Bustaz Kool (unregistered)

    I love the way there are 25 hours in a day (0 thru 11) and (0 thru 12)...

  • Phil Scott (unregistered)

    I think Bustaz is on to something here. Obviously this developer is working on something that operates on some sort of different time continuum that gives them an extra hour a day.

    With that extra hour, who cares about effeciency and obviously you can't use the built in date time functions.

    I think this is just another case of us bitches not having the specs.

  • AvonWyss (unregistered)

    The real WTF today for me is that you're using Chad Grant's suggesion, which does not respect character encodings and fails with special chars like äöüàéè or even the € symbol, and in addition uses commonly used delimiters (\r and \n) instead of a length prefix for the string data, which would prevent the use of a delimiter. Not to say that it is not very efficient in the means of speed... seems you haven't read all the comments on that one. Truly makes me wonder if your code is any better than the code you're critisizing here.

  • Alex Papadimoulis (unregistered)


    The original code posted by Chad will naturally fail on those characters because they are not ASCII-representable characters. If the to/from encoding is changed to Unicode (from Default), it works fine.

    I used unicode encoding and used device control characters (0011, 0012) instead of new lines. I'm guessing Chad used those for demonstrative purposes.

    Besides, this is only being used on extended user attributes, such as AIM, ICQ, and some other items. Worst case scenario is a decoding failure (which will then ignore extended attributes) or a box. I'm not too concerned.

  • Chris (unregistered)

    Whatever happened to System.Text.Encoding.UTF8.GetBytes?

  • Alex Papadimoulis (unregistered)

    UTF8 would work just as well.

    But, the reason System.Text.Encoding.Default won't work is because it only uses the system's current ANSI code page, which would likely not support those extra chars. Or so I'm guessing.

  • froz (unregistered)

    This could be so much more efficient if they had used a few else statements.

  • George Prado (unregistered)

    wow... this of course would break if the year some how change to 12 months instead of 9... but that could never happen...

  • George Prado (unregistered)

    Day = cal.get(Calendar.DATE);

    WTF? he sets Day equal to the entire date so that the output would look something like this if it was 11/8/04 at 3:50pm


    wow this is so wrong at so many levels... did this application actualy work?

  • Wanfactory (unregistered)

    So what happens at 12:15 am? is tempHour null?
    If I'm not mistaken, this looks like java (notice the Calendar.MONTH +1 patented java idiosyncracy) written with C#/VB naming conventions. Thats a minor WTF in of itself.

  • AvonWyss (unregistered)

    Alex, I understand that you more or less fixed the problems with Chads code. However, I don't understand why you didn't look into the solution I provided. And note that you'd have problems using UTF8 in your code because you don't know the number of bytes you need to read, since this may vary depending on the char to be read (can be 1 to 8 bytes AFAIR!). And I don't see why you'd fix broken code if you have code which works nicely without any problem...

  • arty (unregistered)

    Is this meant to adjust the timezone?

    cal.add(Calendar.HOUR, -2);

    I wonder if this person knows that you can make the computer count in local time too.

  • Alex Papadimoulis (unregistered)


    I worked with this http://thedailywtf.com/archive/2004/11/04/3303.aspx#3335 and changed it as described earlier. I didn't like the idea of going Char by Char.

  • MikeC (unregistered)

    @ George.


    public static final int DATE
    Field number for get and set indicating the day of the month. Calendar.DATE is not the entire date. Oddly.

  • Chad Grant (unregistered)

    AvonWyss - You like to critize. Would you like some cheese with that whine?

    I suppose that is what this site is all about.
    I wrote that code in a few mins, to lend a helping hand. It wasnt perfect, nor was it meant to be.

    This site is OBVIOUSLY english only. So ASCII charset would have been fine. But no, you wouldn't have that. It had to be UNICODE, so when WTF goes to Japan, he'll be ready.

    You also liked to point out that I used \r and \n as delimters. You're right, thats a horrible pick. But it was for EXAMPLE. I was too lazy to go pick out control chars for delimeters. I left that up to whomever would like to implement the code. It was a starting point.

    You also tried pointing out that unicode does not use 2 bytes per char. Unicode in .net absolutely uses 2 bytes per char. Read the docs:


    "This class encodes Unicode characters in Unicode Transformation Format, 16-bit encoding form (UTF-16); that is, the character is encoded in a 16-bit field consisting of two consecutive bytes."

    UTF 8 May use more than 1 byte per char. Again, read the docs.

    Do us all a favor and go get laid, please.


  • Scott C Reynolds (unregistered)

    wow! no defenders today! wheres guaya?


  • Marcelo (unregistered)

    Ah, couldn't resist... UTF16 represents characters in 2 bytes, except for the exceptions. Enter surrogate pairs. But I would agree that it's almost nit-picking at this point.


    The documentation calls these 'Surrogate characters', but it looks like it's just trying to weasel out from the fact that Char is a code point, not a character. From the Unicode standard: 'Surrogate Character. A misnomer. It would be an encoded character having a surrogate code point, which is impossible. Do not use this term.'

  • foxyshadis (unregistered)

    The main reason this site is english only is that .Text doesn't support non-ASCII charsets. ^~ There's been a few comments where people tried to use that and .Text butchered them.

    As difficult and often pointless as it is to roll your own database and interface solution, it's often the most fun route, so I can understand entirely. ^
    ~ On the other hand, reimplementing date formatting is very not fun and exceedingly error prone. I can spot a couple of major errors outright and god knows how many hidden ones are thrown in there that'd give incorrect results. I do like that he makes sure to catch all the errors to make sure it can never crash! rolls eyes

  • lejordet (unregistered)

    Next project: Code a web server and CMS entirely out of copy-pasted WTFs

  • xyz (unregistered)

    speaking of performance... Once I read this, I understood why the clock in the tray (on windows) show only minutes... To run a code like that every second will require a Cray!

  • Nick Daniels (unregistered)

    I love the use of error handling. It's almost as good as the error handling in C Pound!

  • Lothar (unregistered)

    That's the reason why Java is considered slow.

    What's wrong with

    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(dateOfReservation);
    return sdf.format("yyyy-MM-dd HH:mm");
    catch(Exception e){
    return "N/A";

    Remembers me to some code we received from an indian company.

  • Lothar (unregistered)


    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm");
    return sdf.format(dateOfReservation);
    catch(Exception e){
    return "N/A";

  • Matt Gorle (unregistered)

    Absolutely superb!

    Dude hasn't heard of methods, I suspect ;-)

  • Ben Hutchings (unregistered)

    xyz: The real problem with a clock updating every second is that <a href="http://weblogs.asp.net/oldnewthing/archive/2003/10/10/55256.aspx">it would have taken too much memory</a> out of Win95's intended requirement of 4 MB. Quite why the option to show seconds wasn't added later, though, I really don't know.

  • Ben Hutchings (unregistered)

    Bah. Stupid .Text.

  • Dave M. (unregistered)

    Ok, that looks like Java, and as Java it's shite. There are better ways of doing it in two lines, and the original author's whine is quite entertaining. 9/10

    Docked a point for this site's consistent WTF of not stating clearly which language it's in. And if you don't know, you ain't qualified to comment.

  • anonymouse (unregistered)

    What is this term that you use? "Shite"? Is that some sort of cavernous rock formation that grows upside down? And yes, before someone says it, rocks do grow.

  • Manni (unregistered)

    anonymouse I'm appalled that you haven't expanded your movie horizons to include such gems as "Trainspotting". And I'm sorry, I can't allow you to have that joke about the rock formation because the real name, stalactite or stalagmite (depending on which you were referring to), is kinda far off from the word "shite". You may as well say he's talking about "termites" or "flood lights" as long as you're playing the rhyme game.

    Ever heard of Shiite Muslims? The spelling couldn't be closer.

    Funny scale: 1 out of 10.

  • AvonWyss (unregistered)

    Chad, I know you won't believe me, but I know pretty well how unicode works and how it is eimplementied in Windows and in .NET. And, for the sake of your argument that this site is english only, there have been posts here which would not work with plain ASCII. It wouldn't even work with my name.

    If you don't have any better arguments, I think you should better shut up - because your comments are jokes for anyone who ever dealt with globalization issues...

  • Chad (unregistered)

    if (System.Text.Encoding.Unicode.GetBytes("ten chars!").Length == 20)
    Console.WriteLine("AvonWyss is a moron");

  • AvonWyss (unregistered)

    Chad, what a wonderful way to show your expertise. Now can you do that with another encoding please? That would be soooooo nice, I'm eager to see how this works, and I just cannot figure that out all by myself...

  • foxyshadis (unregistered)

    Ben: Because seconds are distracting and largely unnecessary. (You can change this, you know, in the regional options)

  • Gary (unregistered)

    In case you're still wondering, though I do hope you aren't, 'shite' is regional dialect for shit across the UK, particularly in the north.

Leave a comment on “Taking the Scenic Rote for Date/Time Conversion”

Log In or post as a guest

Replying to comment #:

« Return to Article