Created
June 20, 2014 14:21
-
-
Save kcelestine/6cc754ed1e0cc6082129 to your computer and use it in GitHub Desktop.
Zellers Congruence Command Line Calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from datetime import date | |
def zeller(day, month, year): | |
if month==1 or month==2: | |
month+=12 | |
year-=1 | |
h = ( ( day +( (month+1) * 26 // 10)+ year +( year // 4)+ 6 * (year // 100)+ (year // 400)) % 7 )+6 | |
return h%7 | |
def year(year): | |
for month in range(1,13): | |
print "%s %d" % (month_name(month), year) | |
day_start = zeller(1,month,year) | |
print_month(month,day_start) | |
def month(month, year=2014): | |
print "%s %d" % (month_name(month), year) | |
day_start = zeller(1,month,year) | |
print_month(month, day_start) | |
def print_month(month, day_start): | |
days = days_in_month(month) | |
print " S M T W T F S " | |
for j in range(day_start): | |
print " ", | |
i = 1 | |
while i <= days: | |
if i < 10: | |
print "", i, | |
else: | |
print i, | |
if (i+day_start) % 7 == 0: | |
print " " | |
i = i + 1 | |
def days_in_month(month): | |
days_in_months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
return days_in_months[month] | |
def month_name(month): | |
month_names = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | |
return month_names[month] | |
def month_number(month): | |
months={'January':1, 'February':2, 'March':3, 'April':4, 'May':5, 'June':6, 'July':7, 'August':8, 'September':9, 'October':10, 'November':11, 'December':12} | |
return months[month] | |
if len(sys.argv) == 2: | |
arg_year = sys.argv[1] | |
year(int(arg_year)) | |
elif len(sys.argv) == 3: | |
arg_year = int(sys.argv[1]) | |
arg_month = sys.argv[2] | |
arg_month = int(month_number(sys.argv[2])) | |
month(arg_month, arg_year) | |
else: | |
year(2014) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment