Working with shift schedules and dates

Posted on 2009-02-19
Medium Priority
Last Modified: 2013-11-16
I'm trying to determine the best way to tackle a calendar view of 4 shifts.  These shifts are designed as:

Day Shift A =   2on, 2off, 3on then 2off, 2on, 3off then repeat.
Night Shift B =  2on, 2off, 3on then 2off, 2on, 3off then repeat.
Day Shift C =    2off, 2on, 3off then 2on, 2off, 3on then repeat.
Night Shift D =  2off, 2on, 3off then 2on, 2off, 3on then repeat.

I've used a method long ago that determined opposite shifts by using the mod function, but this one has me scratching my head.  I have 2 goals here.  

One is having a calendar that can plot these shifts.  I'll probably use the .net calendar for this.  

The second is allowing the user to choose a date and then providing them the folks that will be working on that day.  Or more likely allowing them to navigate the calendar and it give them the viewable schedule as the attached image shows.

Thank you for your time,
Question by:westbergk
  • 3
  • 2
LVL 24

Accepted Solution

Jeff Certain earned 2000 total points
ID: 23682837
Two things you need. The first is the starting date of the cycle.

After that, you're dealing with a 14-day cycle. The fact that shifts run opposite each other simplifies life.

Find the difference (in days) between the date of interest and the start date. Then run mod 14 to get the position in the cycle.

Days 1, 2, 5, 6, 7, 10 and 11 are shift A/B on; other days are shift C/D.

    Public Function GetShift(ByVal startDate As DateTime, ByVal currentDate As DateTime) As String
        Dim days As Integer = DateDiff(DateInterval.Day, startDate, currentDate) + 1
        Dim cyclePosition As Integer = days Mod 14
        Select Case cyclePosition
            Case 1, 2, 5, 6, 7, 10, 11
                Return "A/B"
            Case Else
                Return "C/D"
        End Select
    End Function

Open in new window


Author Comment

ID: 23683053
Thank you Chaosian, that was fast... I must be a real doof.

So the starting date should be one that places these shifts in the correct position?  Shouldnt matter what date, as long as it is in the past?  Makes sense.

So if i were to use the .net calendar, do you think I should simply run the date against this function during the OnDayRender and then do some formating magic per each visible day of the calendar?

LVL 24

Expert Comment

by:Jeff Certain
ID: 23683942
Well, I've dealt with date problems a time or twelve :)

Your OnDayRender idea is going to be the easy way of doing things. Since it's a pretty fast algorithm, you shouldn't see a lot of perf issues, unless you're trying to view a ton of dates at the same time.

If you wanted to show a couple years' worth of data at once, you'd likely need to do some fancy work around performance, but it's not worth it otherwise.
LVL 24

Expert Comment

by:Jeff Certain
ID: 23683951
And, yes... any date in the past that is the first day team A/B comes on rotation should work as the startDate.

Author Closing Comment

ID: 31548801
Awesome.  I'll give it a go.  Thank you Chaosian.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question