Created
May 31, 2014 00:25
-
-
Save yuchan/1b5b57b719161d0c9929 to your computer and use it in GitHub Desktop.
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 | |
import sys | |
from datetime import datetime | |
arguments = sys.argv | |
arg_date = arguments[1] | |
bd = datetime.strptime(arg_date, "%Y%m%d") | |
now = datetime.now() | |
diff = now - bd | |
delta = diff.days / 365.2425 | |
age = int(delta) | |
month = int((delta - age) * 12) | |
nextbirthday = bd.replace(year=(now.year + 1)) | |
nextdelta = nextbirthday - now | |
nextdiff = nextdelta.days + 1 | |
if nextdiff > 365.2425: | |
nextbirthday = bd.replace(year=(now.year), month=bd.month) | |
nextdelta = nextbirthday - now | |
nextdiff = nextdelta.days + 1 | |
print "You are " + str(age) + " years old and " + str(month) + " months." | |
print "Next Birthday is after " + str(nextdiff) + " days." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment