3
ZioCain
5y

Dear fucking MicroSoft,

I really like the C# language, but the default System types have some little fucks up.

Like, if the DateTime.ToString() accepts "HH" to display hours with leading 0, WHY THE FUCK DOESN'T TimeSpan.ToString()?

Truly yours,
ZioCain

Comments
  • 0
    Because March 23. 00:00 + TimeSpan (4h) = March 23. 03:00 under DST.
  • 3
    And because Datetime is a particular point in time, so the 24 hour clock makes sense. Timespan represents a time period so the 24 hour clock doesn't have meaning.
  • 0
    @nibor ok, but when I have to output that information to a string, wouldn't be useful to have the same formats as DateTime? Just to avoid confusion
  • 3
    @ZioCain an amount of time is not a date.

    You can write your own to string func if you really need it.
  • 1
    Different data structures are different.
    Use something like:

    String myDurationSring =
    string.Format("{0:0000}:{1:00}:{2:00}.{3:00}",
    (int)(ts.TotalHours),
    ts.Minutes,
    ts.Seconds,
    ts.Milliseconds/10.0);
  • 0
    I'm sorry but the guy that indicate dates + timespan is bogus on certain dates didn't understand the issue. The ToString formatting issue isn't a problem for dates but rather the timespan. And anybody that doesn't understand a timespan of 11:20:30 is 11 hours 20 mins and 30 seconds doesn't understand that that's easier to read (and code) than 11 hours + 20 mins + 30 seconds. Now admittedly you can probably just do TimeSpan.ToString.SubString(0,8) to get an HH:MM:SS representation anyway, but regardless, it would be natural to assume that the ToString function should handle TIME formatting similarly to the way Date.ToString TIME formatting is handled. Is just totally fucking confusing to get an Exception when passing .ToString("HH:mm:ss") params. Just overall laziness on the part of the coder that wrote the ToSting function to not anticipate that time formatting and just say, you know what, fucking don't want to deal with it, so lets throw an exception instead.. Boo, Hiss!
Add Comment