I'm struggling with "Time" values at present and wonder how other people have dealt with this.
My database (SQL Server 2005) stores Time values in a (nullable) date column with no date component.
In my BOs I am using a SmartDate. To allow meaningful comparisons, I have ensured that all of my Time values do not contain a date component. However, this means that 12am is the same as DateTime.MinValue, which I use to represent a Null for all my date values.
I thought about using the MaxValue to represent Nulls, but I'm nervous about not having a consistent approach toward Null representation and how this could easily lead to bugs. Especially since I'm using CodeSmith to create the BOs and they all default to using the MinValue.
Any ideas on how others have dealt with this would be greaty appreciated.
More than once I have thought that there should be 3 types:
Date -- no hours,minutes,seconds etc....
Time - with hh:mm:ss.tttt that hold a max of 24h 0s
DateTime - like we have now.
and be able to add a Date and a time to make a datetime and other related conversions.
calender apps and other date and time related stuff could really benifit IMHO
Thanks for your comments.
I ended up creating a SmartTime structure stealing a fair bit from the SmartDate source code. I also created a SmartDuration (based on the TimeSpan type) as I required some different behaviour (e.g. values greater than 24hrs). It is now working really well and I was able to greatly simplify the code in my UI controls.
With regard to storing times in the database as integers, doesn't this complicate your queries?
I wonder.... with SQL CLR and 2005 defined types...
could we have sql return a new type ?
if not then have a SQL CLR type for time that stores an unsigned int but displays a day + time string
then have a matching .net type that does the rest of what we might want.
5,184,000.0 would be 24 hours as 60th's of a second -- that should be good time res for all but a few uses.
32 bits unsigned would give: 828 days and about 12 hours of storage so it would handle showing
days hh:mm:ss:tt
by having sql defined type handle storage and output formating -- like it does with datetime
then your .net side class would do a .Parse() on reading and a .ToSTring() on writing to sql.
seems like we could make it very easy to use.
Copyright (c) Marimer LLC