C# Times
-
Hi! I have a problem. I have created a time sheet system that enables a person to enter a start time and an end time. It then calculates the total hours worked. The problem I have is this: When a person has been on lunch from say 11:00 to 11:30 and then wants to enter a time worked say 11:15 then an exception should be thrown stating that times cannot overlap. How will I go about checking for this? Thanks in advance!!
Illegal Operation
-
Hi! I have a problem. I have created a time sheet system that enables a person to enter a start time and an end time. It then calculates the total hours worked. The problem I have is this: When a person has been on lunch from say 11:00 to 11:30 and then wants to enter a time worked say 11:15 then an exception should be thrown stating that times cannot overlap. How will I go about checking for this? Thanks in advance!!
Illegal Operation
two intervals [b1,e1] and [b2,e2] overlap when any of the following is true:
b1<=b2<=e1
b1<=e2<=e1
b2<=b1<=e2
b2<=e1<=e2So start comparing begin and end DateTimes. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Sunday, February 28, 2010 8:15 PM
-
Hi! I have a problem. I have created a time sheet system that enables a person to enter a start time and an end time. It then calculates the total hours worked. The problem I have is this: When a person has been on lunch from say 11:00 to 11:30 and then wants to enter a time worked say 11:15 then an exception should be thrown stating that times cannot overlap. How will I go about checking for this? Thanks in advance!!
Illegal Operation
If you google for c# DateRange you will find a number of classes that people have written to address this sort of problem, i.e. dealing with fixed periods of time and testing for intersection with other periods, and so on. One example is here: http://noticeablydifferent.com/CodeSamples/DateRange.aspx[^] This example is OK, except I would make it immutable since in its present form it's not thread-safe.