-
Notifications
You must be signed in to change notification settings - Fork 0
/
bite186.py
40 lines (29 loc) · 1.29 KB
/
bite186.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from datetime import datetime
from dateutil.parser import parse
# work with a static date for tests, real use = datetime.now()
NOW = datetime(2019, 3, 17, 16, 28, 42, 966663)
WEEKS_PER_YEAR = 52
def get_number_books_read(books_per_year_goal: int,
at_date: str = None) -> int:
"""Based on books_per_year_goal and at_date, return the
number of books that should have been read.
If books_per_year_goal negative or 0, or at_date is in the
past, raise a ValueError."""
at_date = at_date or str(NOW)
date_parsed = parse(at_date)
print(date_parsed)
if books_per_year_goal <= 0 or date_parsed < NOW:
raise ValueError
week = date_parsed.isocalendar()[1]
date_percent = (week * 100) / 52
book_read = books_per_year_goal * date_percent / 100
return int(book_read)
# TODOs
# 1. use dateutil's parse to convert at_date into a
# datetime object
# 2. check books_per_year_goal and at_date and raise
# a ValueError if goal <= 0 or at_date in the past (< NOW)
# 3. check the offset of at_date in the year ("week of the
# year" - e.g. whatweekisit.com) and based on the books_per_year_goal,
# calculate the number of books that should have been read / completed
print(get_number_books_read(100, '11-20-2019'))