Skip to content

Instantly share code, notes, and snippets.

@stemid
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stemid/3f07e5521066b47afea3 to your computer and use it in GitHub Desktop.
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
#!/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