Skip to content

Commit ab40ce3

Browse files
committed
submit seasons
1 parent 7648c91 commit ab40ce3

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Binary file not shown.
Binary file not shown.

week8/seasons/seasons.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from datetime import date, datetime, time
2+
import sys
3+
import inflect
4+
p = inflect.engine()
5+
6+
7+
def main():
8+
# prompts the user for their date of birth in YYYY-MM-DD format
9+
date_of_birth = input("Date of Birth: ")
10+
if len(date_of_birth.split("-")) != 3:
11+
sys.exit("Invalid date")
12+
print(print_minutes(date_of_birth))
13+
14+
15+
# given the date of birth(dob), prints how old user is in minutes
16+
def print_minutes(dob, today_date=date(2000, 1, 1)):
17+
dob = dob.split("-")
18+
y = dob[0][2:4]
19+
m, d = dob[1:]
20+
21+
formatted_date = datetime.strptime(f"{y}/{m}/{d}", "%y/%m/%d")
22+
date_tuple = formatted_date.timetuple()
23+
year, month, day = date_tuple[0:3]
24+
if year >= 2000:
25+
today_date = date.today()
26+
27+
28+
days = abs(date(year, month, day) - today_date).days
29+
minutes = days * 1440
30+
return p.number_to_words(minutes, andword="").capitalize() + " minutes"
31+
32+
33+
if __name__ == "__main__":
34+
main()

week8/seasons/test_seasons.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from seasons import print_minutes
2+
from datetime import date
3+
4+
5+
def test_default_date_print_minutes():
6+
assert print_minutes("1970-01-01",
7+
) == "Fifteen million, seven hundred seventy-eight thousand eighty minutes"
8+
assert print_minutes("1999-01-01",
9+
) == "Five hundred twenty-five thousand, six hundred minutes"
10+
11+
assert print_minutes("1998-06-20",
12+
) == "Eight hundred six thousand, four hundred minutes"
13+
14+
15+
def test_today_date_print_minutes():
16+
assert print_minutes(
17+
"2022-04-21") == "Five hundred twenty-five thousand, six hundred minutes"
18+
assert print_minutes(
19+
"2023-4-01") == "Twenty-eight thousand, eight hundred minutes"

0 commit comments

Comments
 (0)