33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from src.system_var import constants
|
|
|
|
|
|
class CalendarFile:
|
|
"""カレンダーファイル"""
|
|
|
|
__calendar_file_lines: list[str]
|
|
|
|
def __init__(self, calendar_file_path):
|
|
with open(calendar_file_path) as f:
|
|
self.__calendar_file_lines: list[str] = f.readlines()
|
|
|
|
def compare_date(self, date_str: str) -> bool:
|
|
"""与えられた日付がカレンダーファイル内に含まれているかどうか
|
|
カレンダーファイル内の日付はyyyy/mm/ddで書かれている前提
|
|
コメント(#)が含まれている行は無視される
|
|
|
|
Args:
|
|
date_str (str): yyyy/mm/dd文字列
|
|
|
|
Returns:
|
|
bool: 含まれていればTrue
|
|
"""
|
|
for calendar_date in self.__calendar_file_lines:
|
|
# コメント行が含まれている場合はスキップ
|
|
if constants.CALENDAR_COMMENT_SYMBOL in calendar_date:
|
|
continue
|
|
|
|
if date_str in calendar_date:
|
|
return True
|
|
|
|
return False
|