-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployee_birthdays.py
51 lines (37 loc) · 1.43 KB
/
employee_birthdays.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
41
42
43
44
45
46
47
48
49
50
51
from datetime import datetime
from collections import defaultdict
WEEKDAYS = {
0: "Monday",
1: "Tuesday",
2: "Wednesday",
3: "Thursday",
4: "Friday",
}
USERS_DATA = [
{"name": "Bill Gates", "birthday": datetime(1993, 5, 24)},
{"name": "Nick Hill", "birthday": datetime(1978, 12, 13)},
{"name": "John Doe", "birthday": datetime(1978, 12, 16)},
{"name": "Kate Peterson", "birthday": datetime(1978, 12, 7)},
{"name": "Julia Ferguson", "birthday": datetime(1978, 12, 9)},
{"name": "Mike Smith", "birthday": datetime(1978, 12, 6)},
{"name": "Conor Parker", "birthday": datetime(1978, 12, 6)},
]
def get_weekday(day_number):
if day_number > 4:
return WEEKDAYS[0]
return WEEKDAYS[day_number]
def get_birthdays_per_week(users):
result = defaultdict(list)
current_date = datetime.today().date()
for user in users:
birthday = user["birthday"].date()
birthday_this_year = birthday.replace(year=current_date.year)
if birthday_this_year < current_date:
birthday_this_year = birthday.replace(year=current_date.year + 1)
delta_days = (birthday_this_year - current_date).days
if delta_days < 7:
weekday = get_weekday(birthday_this_year.weekday())
result[weekday].append(user["name"])
for weekday, birthdays in result.items():
print(f"{weekday}: {", ".join(birthdays)}")
get_birthdays_per_week(USERS_DATA)