Results 1 to 10 of 10

Thread: [2005] Timespan 2 shifts.

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    55

    [2005] Timespan 2 shifts.

    Hi,
    Im having some difficulty implementing 2 shifts.

    For example. A person works from 8:00 - 16.00 on 10th of may
    The next time a person enters a timespan from say 15.00 - 18.00 on the 10th of may , it should give an error. Because 15.00 - 16.00 he already worked.

    It should also work with Crossdates if someone worked like 11th of may and also did a latenight shift on the 10th of may.

    Does anyone know a thread that had the same problem cause ive searched the forum and not found any.

    Is the Timespan.compare the answer to my problems?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Timespan 2 shifts.

    The TimeSpan is useless to you because it has no concept of when it started or when it finished. A TimeSpan could represent 3 minute and 47 seconds, but that could be from before Christ, last week, today or some time in the distant future. The TimeSpan doesn't know. Think of a TimeSpan like a piece of string. You can put it wherever you like and it's still the same length. It doesn't care where it starts or where it ends.

    You need to keep two distinct DateTime objects for the start of a shift and the end. Only then can you compare two shifts to see if they overlap.

    Given that this is OOP you should do it the OO way. Create a Shift class. Take a start time and an end time in the constructor. Provide a Duration property that returns the TimeSpan that is the difference between the two DateTimes. Provide a method to compare two shifts to see if they overlap. For that you check the start times to see which one was started first. You'd then check whether the first one also finished before or when the second one started.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    55

    Re: [2005] Timespan 2 shifts.

    Well ive got no clue to do this the OO way.Im just a little familiar with it and writing something like this is i think a bit out of my league.

    Are there no examples for this kind of problem , if you dont mind me asking.

    Is there a way to check this with a simple loop instead of doing it the OO way ?

    ps: Im a bit mind boggled after reading that
    Last edited by IamMacro; May 10th, 2007 at 04:12 AM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Timespan 2 shifts.

    I've already told you how to determine whether two shifts overlap:
    you check the start times to see which one was started first. You'd then check whether the first one also finished before or when the second one started.
    That holds true whether you're using creating a class to represent a shift or not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    55

    Re: [2005] Timespan 2 shifts.

    nm this one


    appreciate your help
    Last edited by IamMacro; May 10th, 2007 at 08:29 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Timespan 2 shifts.

    As I have already said, twice, if you want to test whether two shifts overlap you first compare their start times to see which started first. You then compare the end time of the first with the start time of the second. If the first ends when or before the second starts then they do not overlap. So, start creating your DateTime objects and comparing them.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    55

    Re: [2005] Timespan 2 shifts.

    Yeah Sorry , about that but i forgot to tell , my field

    WorkdayStart is a datetime with "05/05/2007" 9:00 - "05/05/2007" 15:00
    second row (is a different workday) "05/05/2007" 9:00 - "05/05/2007" 17:00

    but i understand that the Datetime variable checks the entire Datetime.
    So i think ill get it now.

    thx jmcilhinney.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    55

    Re: [2005] Timespan 2 shifts.

    dtewerk = datepicker.value.date "10-05-2007"
    straankomst = "3:15"

    insertCommand.Parameters("workdaystart").Value =
    DateTime.Parse(dtewerk & straankomst, "DD/MM/YYYY HH:MM")

    Im getting an InvalidCast Exception , what am i doing wrong ?

  9. #9
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Timespan 2 shifts.

    So you are adding the data to a DB? Would it not be better having just 1 column (of DateTime type) and then adding the value from the DateTime Picker to that. It would store the date and time anyway?

    vb Code:
    1. Dim startTime As DateTime = Me.DateTimePicker1.Value
    2.  
    3.         MessageBox.Show(startTime.ToShortDateString)
    4.         MessageBox.Show(startTime.ToShortTimeString)
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    55

    Re: [2005] Timespan 2 shifts.

    Users can enter a Workday on a later time.
    So they work from 8:00 - 16:00 but they filled it in the next day.

    So im using Comboboxes filled with 1 2 3 4 - 23 , and 0 15 30 45 for minutes to let them pick a time

    Code:
    dim _dtewerk as string
    
    _dtework = Format(Datetimepicker1.Value, "dd/MM/yyyy")
    
    _strarrival = cmbHours.text & " " & cmbminutes.text
    
    Dim test As String = _dtewerk & " " & _strarrival
    
    insertCommand.Parameters("start").Value = test
    this works but is far from perfect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width