Last active
March 26, 2016 07:36
-
-
Save Ohcanep/8156383 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# https://docs.python.org/3/library/datetime.html | |
# https://docs.python.org/3/library/string.html#formatspec | |
from datetime import date, timedelta | |
def days_from_now(days: int) -> date: | |
return date.today() + timedelta(days=days) | |
def print_days_between(d1: date, d2: date = None): | |
if d2 is None: | |
d2 = date.today() | |
if d1 > d2: | |
d1, d2 = d2, d1 | |
print('{} days between {} and {}'.format((d2 - d1).days, d1, d2)) | |
def print_days_from_now(days: int): | |
delta = '{} days'.format(days) | |
target = days_from_now(days).isoformat() | |
print('{:<12}{}'.format(delta, target)) | |
if __name__ == '__main__': | |
print_days_between(date(2000, 1, 1), date.today()) | |
print_days_between(date(2038, 1, 19)) | |
print('----') | |
print_days_from_now(-180) | |
print_days_from_now(-90) | |
print_days_from_now(-30) | |
print_days_from_now(-14) | |
print_days_from_now(-7) | |
print('----') | |
print_days_from_now(7) | |
print_days_from_now(14) | |
print_days_from_now(30) | |
print_days_from_now(90) | |
print_days_from_now(180) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment