C
Chris
Just wanting to vent my dissatisfaction with the TimeSpan type. It
isn't IConvertible and there is no TypeCode for it; so, when someone
passes my interface an Object and I need to deal with it according to
its type, I have to make a special case for it.
Jay Harlow responds on a thread subject
"How to Format a TimeSpan Without the Decimal Part of the Seconds"
"...when I need custom formatting of a TimeSpan is "convert"
it to a DateTime, then use custom DateTime formatting..."
This is a weak solution. (No disrepect to Jay.) TimeSpans are
durations of time; DateTimes are specific points in time. The
semantic difference is between telling your friend you will meet them
in one hour versus meeting them at 1:00 PM. What if you have the
value 370 days. I'm pretty sure that DateTime is not going to handle
that well. One year and five days you say? Really, for all years?
No. Aside from leap year problems there are issues with Julian versus
Gregorian calendars, the Jewish calendar, etc. The value 370 days is
perfectly meaningful when talking about intervals, but is meaningless
for DateTimes.
Just hoping that Microsoft picks up on this and makes some
improvements at some point. I don't know; maybe they decided there
was no other type that preserved the same meaning and so consiously
left it out of Convert and IConvertable. At least there should be a
TypeCode.
-Chris
isn't IConvertible and there is no TypeCode for it; so, when someone
passes my interface an Object and I need to deal with it according to
its type, I have to make a special case for it.
Jay Harlow responds on a thread subject
"How to Format a TimeSpan Without the Decimal Part of the Seconds"
"...when I need custom formatting of a TimeSpan is "convert"
it to a DateTime, then use custom DateTime formatting..."
This is a weak solution. (No disrepect to Jay.) TimeSpans are
durations of time; DateTimes are specific points in time. The
semantic difference is between telling your friend you will meet them
in one hour versus meeting them at 1:00 PM. What if you have the
value 370 days. I'm pretty sure that DateTime is not going to handle
that well. One year and five days you say? Really, for all years?
No. Aside from leap year problems there are issues with Julian versus
Gregorian calendars, the Jewish calendar, etc. The value 370 days is
perfectly meaningful when talking about intervals, but is meaningless
for DateTimes.
Just hoping that Microsoft picks up on this and makes some
improvements at some point. I don't know; maybe they decided there
was no other type that preserved the same meaning and so consiously
left it out of Convert and IConvertable. At least there should be a
TypeCode.
-Chris