Last active
August 29, 2015 14:10
-
-
Save stemid/3f07e5521066b47afea3 to your computer and use it in GitHub Desktop.
calculates days of each month with a simple formula thought up by Curtis McEnroe
This file contains hidden or 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
#!/usr/bin/env python | |
# http://cmcenroe.me/2014/12/05/days-in-month-formula.html | |
from __future__ import print_function | |
from argparse import ArgumentParser | |
import math | |
parser = ArgumentParser() | |
parser.add_argument( | |
'month', | |
metavar='MONTH', | |
type=int, | |
choices=range(1,13), | |
help='Number of month that you want the number of days from' | |
) | |
args = parser.parse_args() | |
def days(month): | |
days = 28 | |
days = days + (month + math.floor(month/8)) % 2 + 2 % month + 2 * math.floor(1/month) | |
return int(days) | |
print(days(args.month)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment