0001-utils-add-function-to-get-weekday-index-from-date-45.patch
chrono/utils/date.py | ||
---|---|---|
1 |
def get_weekday_index(datetime): |
|
2 |
return (datetime.day - 1) // 7 + 1 |
tests/test_utils.py | ||
---|---|---|
1 |
import datetime |
|
2 | ||
3 |
from chrono.utils.date import get_weekday_index |
|
4 | ||
5 | ||
6 |
def test_get_weekday_index(): |
|
7 |
for date in ( |
|
8 |
datetime.date(2021, 11, 1), # month starting a Monday |
|
9 |
datetime.date(2021, 12, 1), # month starting a Wednesday |
|
10 |
datetime.date(2021, 5, 1), # month starting a Sunday |
|
11 |
): |
|
12 |
assert get_weekday_index(date) == 1 |
|
13 |
assert get_weekday_index(date.replace(day=3)) == 1 |
|
14 |
assert get_weekday_index(date.replace(day=7)) == 1 |
|
15 |
assert get_weekday_index(date.replace(day=8)) == 2 |
|
16 |
assert get_weekday_index(date.replace(day=10)) == 2 |
|
17 |
assert get_weekday_index(date.replace(day=14)) == 2 |
|
18 |
assert get_weekday_index(date.replace(day=15)) == 3 |
|
19 |
assert get_weekday_index(date.replace(day=21)) == 3 |
|
20 |
assert get_weekday_index(date.replace(day=22)) == 4 |
|
21 |
assert get_weekday_index(date.replace(day=28)) == 4 |
|
22 |
assert get_weekday_index(date.replace(day=29)) == 5 |
|
23 |
assert get_weekday_index(date.replace(day=30)) == 5 |
|
0 |
- |