Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# Times

C# Times

Scheduled Pinned Locked Moved C#
csharphelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Illegal Operation
    wrote on last edited by
    #1

    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

    L D 2 Replies Last reply
    0
    • I 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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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<=e2

      So 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

      1 Reply Last reply
      0
      • I 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

        D Offline
        D Offline
        David Skelly
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups