Created
March 22, 2013 12:20
-
-
Save tunaktu86/5220846 to your computer and use it in GitHub Desktop.
This gives the week day you were born based on your birthdate. (mm-dd-yy)
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
Sign up for a GitHub Account Sign in | |
PUBLIC | |
anonymous / gist:5220817 | |
Created just now | |
Find the week day you were born on based on your birthdate (mm-dd-yyy) | |
Gist Detail | |
Revisions 1 | |
Download Gist | |
Clone this gist | |
Embed this gist | |
Link to this gist | |
gistfile1.pyPython | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
import sys | |
# Find day of week of birthdate | |
# call birthdate mm-dd-yy format | |
# Used to check the digits on the input birthay to determine if the layout works | |
# def Birth_day(date) : | |
# mm = int(date[0:2]) | |
# dd = int(date[3:5]) | |
# yy = int(date[6:]) | |
# return mm, dd, yy | |
#Calculates the first portion of the doomsday calculation | |
#that feeds into Year_step_2 | |
def Year_step_1(date): | |
yy = int(date[8:]) | |
if yy%2 == 0: | |
div_date = yy/2 | |
else: | |
div_date = (yy+11)/2 | |
return div_date | |
#This portion of code determines how many days off from the Standard | |
#doomsday the year in question is. All years in the 1900s have a base doomsday | |
#of Wednesday, all 2000's have a base doomsday of Thursday. | |
def Year_step_2(date): | |
div_date = Year_step_1(date) | |
if div_date%2 == 0: | |
mod_date = div_date%7 | |
else: | |
mod_date = (div_date+11)%7 | |
return 7 - mod_date | |
#This portion of code checks wether the birthday is in the 1900's or the | |
#2000's so the base doomsday can be adjusted. the week is based on the | |
#Sunday through Saturday week with Sunday as zero "0" and Saturday as six "6" | |
def Anchor_finder(date): | |
yyxx = int(date[6:8]) | |
if yyxx == 19: | |
anchor = 3 | |
if yyxx == 20: | |
anchor = 4 | |
return anchor | |
#this code is used to output the numerical day of the week to be used to | |
#adjust from the Anchor date to the birthdate input. This code can be uncommented to | |
#output the human readable day of the week. | |
def Doomsday(date): | |
weekday = (Anchor_finder(date) + Year_step_2(date))%7 | |
day_of_week = ['Sunday', 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'] | |
return weekday | |
# if weekday == 0: | |
# return day_of_week[0] | |
# if weekday == 1: | |
# return day_of_week[1] | |
# if weekday == 2: | |
# return day_of_week[2] | |
# if weekday == 3: | |
# return day_of_week[3] | |
# if weekday == 4: | |
# return day_of_week[4] | |
# if weekday == 5: | |
# return day_of_week[5] | |
# if weekday == 6: | |
# return day_of_week[6] | |
#This code determines if the year in question is a leap year or not. | |
#Leap years require that the anchor date in a given month need to be changed. | |
def Leap_year(date): | |
year = int(date[6:]) | |
leap_year = 0 | |
if year%400 == 0: | |
leap_year = 1 | |
elif year%100 == 0: | |
leap_year = 0 | |
elif year%4 == 0: | |
leap_year = 1 | |
else: | |
leap_year = 0 | |
return leap_year | |
#This code uses the input from the above calculations to determine | |
#what day of the week the birthday is on. | |
def User_Day(date): | |
leap_year = Leap_year(date) | |
doomsday = Doomsday(date) | |
anchor = (Anchor_finder(date) + Year_step_2(date))%7 | |
mm = int(date[0:2]) | |
dd = int(date[3:5]) | |
if leap_year == 1: | |
month = [0,4,22,14,4,9,6,4,8,5,10,7,12] | |
elif leap_year == 0: | |
month = [0,3,14,14,4,9,6,4,8,5,10,7,12] | |
if month[mm] < dd: | |
ndd = dd - month[mm] | |
ndd = abs(ndd) | |
diff = ndd%7 | |
week_day = doomsday + diff | |
week_day = abs(week_day)%7 | |
else: | |
ndd = month[mm] - dd | |
ndd = abs(ndd) | |
diff = ndd%7 | |
week_day = doomsday + 7 - diff | |
week_day = abs(week_day)%7 | |
return int(week_day)#, anchor, diff, ndd, dd | |
def Day_of_week(date): | |
weekday = User_Day(date) | |
day_of_week = ['Sunday', 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'] | |
if weekday == 0: | |
return day_of_week[0] | |
if weekday == 1: | |
return day_of_week[1] | |
if weekday == 2: | |
return day_of_week[2] | |
if weekday == 3: | |
return day_of_week[3] | |
if weekday == 4: | |
return day_of_week[4] | |
if weekday == 5: | |
return day_of_week[5] | |
if weekday == 6: | |
return day_of_week[6] | |
else: | |
return 'ERROR' | |
def main(): | |
if len(sys.argv[1]) != 10: | |
print 'Your year must be in a 4 digit form mm-dd-yyy' | |
sys.exit(1) | |
else: | |
date = sys.argv[1] | |
# print Birth_day(date) | |
# print Year_step_2(date) | |
# print Anchor_finder(date) | |
# print 'Doomsday is',Doomsday(date) | |
print 'You were born on a', Day_of_week(date) | |
# print User_Day(date),'User_Day' | |
if __name__ == '__main__': | |
main() | |
Please sign in to comment on this gist. | |
© 2013 GitHub Inc. All rights reserved. | |
The GitHub Blog Support Contact |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment