1from datetime import date
2from typing import ClassVar
3
4from icalendar.parser import Parameters
5
6
7class TimeBase:
8 """Make classes with a datetime/date comparable."""
9
10 default_value: ClassVar[str]
11 params: Parameters
12 ignore_for_equality = {"TZID", "VALUE"}
13
14 def __eq__(self, other):
15 """self == other"""
16 if isinstance(other, date):
17 return self.dt == other
18 if isinstance(other, TimeBase):
19 default = object()
20 for key in (
21 set(self.params) | set(other.params)
22 ) - self.ignore_for_equality:
23 if key[:2].lower() != "x-" and self.params.get(
24 key, default
25 ) != other.params.get(key, default):
26 return False
27 return self.dt == other.dt
28 from .list import vDDDLists
29
30 if isinstance(other, vDDDLists):
31 return other == self
32 return False
33
34 def __hash__(self):
35 return hash(self.dt)
36
37 from icalendar.param import RANGE, RELATED, TZID
38
39 def __repr__(self):
40 """String representation."""
41 return f"{self.__class__.__name__}({self.dt}, {self.params})"
42
43
44__all__ = ["TimeBase"]