CSCI 150 - Project 1
This Day in History


Overview

Many systems have been devised over the years for keeping time. In this project, you will explore some of the oddities present in our current calendar system by using a formula to calculate the day of the week for any given day between 1700 and 2299.

In particular, this project will cover the following concepts we have discussed in class:

Description

Over the centuries, our calendar has been realigned many times to coincide with growth in our astronomical knowledge. Incorporating elements of both the solar and lunar cycle, the current international standard calendar is the Gregorian Calendar, first adopted in 1582. There are seven days a week due to religious influence, 12 months to a year in honor of the lunar cycle, and 365 days a year in relation to the earth's orbital period around the sun, with enough leap days included to properly align the system with the true orbital period of approximately 365.242190419 days. While better than the Egyptian and Roman calendars in use at the time of adoption, it is still an approximation with room for improvement, from the more-precise Iranian Calendar to a standardized and perpetual World Calendar.

One of the more interesting quirks of the Gregorian Calendar is that each year can start on a different day of the week, since 365 is not a multiple of 7. But there is a simple algorithm (based on the Doomsday Rule) that you can memorize to find the day of the week for any date between Jan 1st, 1700 and Dec 31st, 2299:

  1. Find the last 2 digits of the year. Divide this by four (using integer division) and sum these two together to get y.
  2. Get the corresponding offset (shown below) for the month for m.
  3. Take the day to get d
  4. Add y, m and d together to find dow.
  5. Add the year offset (also shown below) to dow.
  6. If the year is a leap year and the month is January or February, subtract 1 from dow.
  7. dow mod 7 corresponds to the day of the week. (0 = Sunday, 1 = Monday, 2 = Tuesday, etc.)
Table for Month Offset

JanFebMarAprMayJun JulAugSepOctNovDec
622503 514624

Table for Year Offset

170018001900200021002200
5310-2-4

For example, if you wish to know the day of the week for September 26th, 2014, these are the steps you would take:
  1. 14 + 3 = 17
  2. 4
  3. 26
  4. 17 + 4 + 26 = 47
  5. 47 + 0 = 47 (offset code = 0)
  6. 47 - 0 = 47 (a leap year, but not Jan or Feb)
  7. 47 % 7 = 5 for Friday

Leap Year Rule

Under the Gregorian Calendar, a year is a leap year (such that February has 29 days) if it is a multiple of four, except when it is also a multiple of 100 but not 400. So, 1900 and 2100 are not leap years, but 2000 is a leap year.

Coding

For this assignment, you will write a Python program called whatdayisit.py. This program will first tell the user about the program, and then take as input from the user the date they wish to use for finding the day of the week. This input must be in the form of one question to the user, formatted to have the day, then month, then year, with each separated by a dash. The month and the day must both be two digit entries, pad the beginning with 0 if necessary. So the user would type in "26-09-2014" for September 26th, 2014.

With correct input, your program will then parse this input into the day, month and year, follow the above algorithm to compute the day of the week, and output this to the user in the following format (using September 26th, 2014 as an example):

The 26th of September, 2014 takes place on a Friday.

For dates, use st, nd, rd and th suffixes appropriately.

Testing

Test your code on the following dates to ensure you are getting the right answers. I will be using other dates to test your project for grading, so you should also find three other dates than these for your own testing, one of which is in January or February of a leap year.

Restrictions

You may not use lists or strings to store the offset data. This should be accomplished with conditionals.

What to Hand In

Log in to Moodle. Copy your whatdayisit.py project into the directory called project1. Make sure you have followed the Python Style Guide, and have run your project through the Automated Style Checker.

You must hand in:


© Mark Goadrich, Hendrix College