views:

50

answers:

3

My school wants me (the school's webmaster) to put in some sort of display that would show the proper day in our 4-day school cycle on the home page. It doesn't have to be anything fancy; just a simple script that shows "Today is Day 1", etc.

Our school operates on a 4-day school cycle. What this means is that on the first day of school, we begin on "Day 1". The kids refer to their class schedule and see where to go for their classes on Day 1. The next day is "Day 2". Again,the kids' classes are the same, but in a different order. Then,"Day 3", same thing, and then "Day 4", same thing again. After Day 4, the cycle starts again on Day 1, and continues in an endless loop until the school year is done.

Of course, there are no school "days" on weekends and statutory holidays (Canadian). For example: Friday, October 9 was "Day 4", but Monday is Thanksgiving in Canada, so there is no school and therefore no school "day". On Tuesday, the school "day" will be Day 1.

So, I need a piece of code I can put on our website's home page to indicate the "day" of the school cycle, but I need that code not to count weekends at the very least. If it can't cope with holidays, that's fine, I can deal with that and make changes as needed.

I've done tons of Google searches and I can't find anything even closely related to what I'm looking for.

+1  A: 

well just have a counter then an if then statement, so if the thing equals 5 (meaning it'll be a day one) it'll reset the counter to one

Matt S.
That doesn't take into account anything about weekends and holidays.
TheTXI
oh yea, uh, have it check the day of the week then? And if it's a holiday (defined by a database) count it as a weekend
Matt S.
A: 

Since I don't know what language you're using, I'll just outline it loosely.

To start the script, you start at the first day of school, and at Day 1. You can represent this with an enumeration, a DateTime-like object, or some other kind of identifier.

Then you start a loop, and in each iteration, you increase the day by one (e.g. Monday to Tuesday, etc). You also increment the day number, unless the Day is 4, in which case it wraps over to Day 1. If the day is a weekend or a holiday, you don't increment anything. You keep doing this until you reach the current day, and then you have your cycle number.

An example in C#:

public int GetDayNumber()
{
     DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
     DateTime day = new DateTime(today.Year, 9, 8); // Year, Month, Day
     int cycle = 1;

     do
     {
          if (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday))
          {
               day = day.AddDays(1);
               continue;
          }

          cycle = cycle == 4 ? 1 : cycle + 1;
          day = day.AddDays(1);
     }
     while (day != today)

     return cycle;
}

This is only a rough implementation and has not been debugged, but you see how it could be implemented.

nasufara
A: 

It is probably easiest to take a leaf out of the (database) warehousing folks book and create a table in a database that contains each date plus an indicator (showing holidays - perhaps call them 'day 0' and the day in the cycle). Populating that table can be done once, carefully, but it is ultimately the easiest way to deal with the idiosyncrasies of calendrical scheduling.

You can also use the table to store other interesting information for the days. For example, there may be days that have 'names' (like Thanksgiving, or Canada Day). And maybe you keep a day count into the school year, or the current term, or both.

Jonathan Leffler