utils: add function to get weekday index from date (#45159)
This commit is contained in:
parent
d1df43fd7e
commit
839a578bd0
|
@ -0,0 +1,2 @@
|
|||
def get_weekday_index(datetime):
|
||||
return (datetime.day - 1) // 7 + 1
|
|
@ -0,0 +1,23 @@
|
|||
import datetime
|
||||
|
||||
from chrono.utils.date import get_weekday_index
|
||||
|
||||
|
||||
def test_get_weekday_index():
|
||||
for date in (
|
||||
datetime.date(2021, 11, 1), # month starting a Monday
|
||||
datetime.date(2021, 12, 1), # month starting a Wednesday
|
||||
datetime.date(2021, 5, 1), # month starting a Sunday
|
||||
):
|
||||
assert get_weekday_index(date) == 1
|
||||
assert get_weekday_index(date.replace(day=3)) == 1
|
||||
assert get_weekday_index(date.replace(day=7)) == 1
|
||||
assert get_weekday_index(date.replace(day=8)) == 2
|
||||
assert get_weekday_index(date.replace(day=10)) == 2
|
||||
assert get_weekday_index(date.replace(day=14)) == 2
|
||||
assert get_weekday_index(date.replace(day=15)) == 3
|
||||
assert get_weekday_index(date.replace(day=21)) == 3
|
||||
assert get_weekday_index(date.replace(day=22)) == 4
|
||||
assert get_weekday_index(date.replace(day=28)) == 4
|
||||
assert get_weekday_index(date.replace(day=29)) == 5
|
||||
assert get_weekday_index(date.replace(day=30)) == 5
|
Loading…
Reference in New Issue