Using strings for time



  • Someone just uploaded this wtf on codeproject.com, read it before the author realizes that its total crap takes it down. It's a C# class which for some reason implements part of the TimeSpan class. However, his version of timespan, called Time, returns strings for most actions, like adding two time objects returns a string. There's more wtf, for example his copy constructor for the Time class don't take a Time object as parameter, instead it takes an object. So do most other of his methods as well so at least he is consistent.

    He stores time as integer, of course using public:

    public int Hours, Minunteses, Seconds;
     Here's how Add is implemented:
    /// Add new time and sum it with other times.
    public string Add(object time)
    {
    string[] vals = time.ToString().Split(new char[] { ':' });

    Hours += Convert.ToInt32(vals[0]);
    Minuntes += Convert.ToInt32(vals[1]);
    Seconds += Convert.ToInt32(vals[2]);

    return this.ToString();
    }
    http://www.codeproject.com/useritems/Simple_time_class.asp 



  • "Minuntes"?!

    "Minunteses"?!?! 



  • I suppose that chucks differences with localisation out of the window too.
    Truly the stuff of nightmares. I think I'll stick to the built-in DateTime class.



  • Why would anyone ever use this?



  • Nasty hobbitses and their minuntses.



  • [quote user="teedyay"]

    "Minunteses"?!?! 

    [/quote]

    The Minunteses was some weird copy/paste mistake that the forum software added when I switched between design/html mode. I fixed some but missed that one. So that wtf is not part of the Time class but this forum.
     



  • Ack! That's one of the most horrible implementations I've ever seen.

    If someone ever used that in a production system that had to support DST, it would cause a mini-Y2K.

    I can imagine Amtrak running on that. [ read: train wreck ]



  • Talking about a Junior Developer and what they can do is one thing - this is just bad design and more importantly bad implementation.



  • So it is possible to have 50 hours, 69 minutes and 248 seconds?



  • The Code Project is a great source of WTFs.  I stumbled across this: http://www.codeproject.com/system/xservice.asp

     A complete mess.  A class that allocates memory but doesn't have a destructor.  Crashes left, right, and centre.  Feel free to check out the code, and then rate this article down.  It is truly a nasty piece of work, and the more people that know it is bad the better.


     



  • [quote user="kuroshin"]

    Ack! That's one of the most horrible implementations I've ever seen.

    If someone ever used that in a production system that had to support DST, it would cause a mini-Y2K.

    I can imagine Amtrak running on that. [ read: train wreck ]

    [/quote]

    I have to call bullshit on some of these comments; the contructor and output are bad, and it must be annoying to calculate that 900 hours means a little over a month when talking large time intervals, but all sane time functions work by normalizing time to GMT and ignoring time zone (which is sideband information) until it's time to print it back out. The main exception is XML datetime, where timezones are passed around as strings and recalculated everytime; they basically work exactly like this, but less stupid.

    It sure is useless to wrap DateTime if you're not going to add anything to it, though. And betrays his utter lack of knowledge of DateTime formatting methods, if he would consider using GetTimeFromSeconds to format a date.



  • The code is horrible, but that might be acceptable if it at least worked. 

    I wrote a message regarding a pair of the bugs in the class, like that the parameterless constructor can create objects with incorrect time, and that the Add method returns am incorrect value approximately 85% of the time.

     



  • Hilarious!

     I just checked and this crap is still on the Code Project.
     



  • [quote user="johan"]

    Hilarious!

     I just checked and this crap is still on the Code Project.
     

    [/quote]

     

    Not anymore... :( 

     



  • [quote user="Devi"][quote user="johan"]

    Hilarious!

     I just checked and this crap is still on the Code Project.
     

    [/quote]

     

    Not anymore... :( 

     

    [/quote]

     

    Still in Google cache



  • [quote user="Grimoire"]The Code Project is a great source of WTFs.[/quote]

    Yeah. There's some really good stuff on there, but there is a lot of crap as well. My only hope is that people aren't putting my contributions into the 'crap' category ;).


Log in to reply