We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

# Working with shift schedules and dates

on
Medium Priority
474 Views
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.

K
cal.png
Comment
Watch Question

## View Solution Only

Commented:
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
``````

Not the solution you were looking for? Getting a personalized solution is easy.

Developer

Commented:
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?

Commented:
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.

Commented:
And, yes... any date in the past that is the first day team A/B comes on rotation should work as the startDate.
Developer

Commented:
Awesome.  I'll give it a go.  Thank you Chaosian.
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile