|
4 | 4 | # license information. |
5 | 5 | # ------------------------------------------------------------------------- |
6 | 6 | from enum import Enum |
7 | | -from typing import Dict, Any |
| 7 | +from typing import Dict, Any, Optional |
8 | 8 | from datetime import datetime |
9 | 9 | from dataclasses import dataclass |
10 | 10 | from email.utils import parsedate_to_datetime |
@@ -68,13 +68,18 @@ class RecurrencePattern: # pylint: disable=too-few-public-methods |
68 | 68 | The recurrence pattern settings. |
69 | 69 | """ |
70 | 70 |
|
| 71 | + days: list = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] |
| 72 | + |
71 | 73 | def __init__(self, pattern_data: Dict[str, Any]): |
72 | 74 | self.type = RecurrencePatternType.from_str(pattern_data.get("Type", "Daily")) |
73 | 75 | self.interval = pattern_data.get("Interval", 1) |
74 | 76 | if self.interval <= 0: |
75 | 77 | raise ValueError("The interval must be greater than 0.") |
76 | | - self.days_of_week = pattern_data.get("DaysOfWeek", []) |
77 | | - self.first_day_of_week = pattern_data.get("FirstDayOfWeek", 7) |
| 78 | + days_of_week = pattern_data.get("DaysOfWeek", []) |
| 79 | + for day in days_of_week: |
| 80 | + self.days_of_week.append(self.days.index(day)) |
| 81 | + first_day_of_week = pattern_data.get("FirstDayOfWeek", "Sunday") |
| 82 | + self.first_day_of_week = self.days.index(first_day_of_week) if first_day_of_week in self.days else 0 |
78 | 83 |
|
79 | 84 |
|
80 | 85 | class RecurrenceRange: # pylint: disable=too-few-public-methods |
@@ -110,7 +115,7 @@ class TimeWindowFilterSettings: |
110 | 115 |
|
111 | 116 | start: datetime |
112 | 117 | end: datetime |
113 | | - recurrence: Recurrence |
| 118 | + recurrence: Optional[Recurrence] |
114 | 119 |
|
115 | 120 |
|
116 | 121 | @dataclass |
|
0 commit comments