Docstring finished, weeksdays bitmask added

This commit is contained in:
2022-09-23 13:54:36 +02:00
parent a093d1b5d7
commit e1e3f40643
2 changed files with 69 additions and 37 deletions

21
pyrmv/utility/bitmask.py Normal file
View File

@@ -0,0 +1,21 @@
from typing import OrderedDict
def weekdays_to_bitmask(data: OrderedDict[str, bool]) -> str:
"""Convert ordered dict with weekdays to a bitmask.
### Args:
* data (OrderedDict[str, bool]): OrderedDict formatted as follows: OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)
### Returns:
* str: _description_
"""
output = ""
if len(data) != 7:
raise ValueError("OrderedDict must be formatted as follows: OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)")
for day in data:
if data[day]:
output += "1"
else:
output += "0"
return output