Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most Efficient Way To Represent Time periods

I have a need to take a time period, e.g. a week and break it down into days and then further down into either hours, 30 minutes, 15 minutes etc.

Then I want to be able to assign (possibly multiple) people to those time spans.

e.g.

30 May 2012

0700 : 0730 - Alice, Bob

0730 : 0800 - Alice

.... : ....

1930 : 2000 - Alice

31 May 2012

0700 : 0730 - Carol

0730 : 0800 - Carol

.... : ....

1930 : 2000 - Carol

Where the start times and end times each day are customisable.

I need to be able to sort the working periods and do query them to see if any don't have a person assigned to them. Check over a Day / Week that no one person is assigned to > x hours.

I know .Net has TimeSpan and DateTime but these seem cumbersome to use for what is a seems like a simple representation of some data and TimeSpan has no StartTime, it's purely just a span of time (e.g. 30 minutes, 5 minutes, 1 hour etc).

What I had initially in mind was to create a class called WorkingDay, a WorkingDay can have a number of WorkingPeriods. a WorkingPeriod has a StartTime and EndTime and a List of people assigned to that WorkingPeriod with simple methods to AddPerson and RemovePerson.

WorkingDay will have a function to get a list of people assigned for that day by running through the WorkingPeriods and pulling out all unique people that are assigned for any period. It will also have a function that pulls out all WorkingPeriods with no-one assigned.

This seems far too cumbersome though! Especially as I'm going to need something else that takes in a number of WorkingDays and checks that the total time someone is assigned over multiple days is less than x hours etc.

Any suggestions for a good structure for this ? Is their an existing .Net Structure that will provide this which I'm missing ?

like image 919
user476683 Avatar asked May 30 '12 12:05

user476683


1 Answers

The most direct (and compact) representation for a timeslot is DateTime start, TimeSpan duration.

That lends itself well for querying, less well for setting up and validating (against overlap etc).

The next option is to divide each day (or week) into a fixed number of periods, define those periods once and code each timeslot as DateTime base, int PeriodId. Better for finding empties and duplicates.

like image 108
Henk Holterman Avatar answered Oct 26 '22 17:10

Henk Holterman