1"""The interface for timezone implementations."""
2
3from __future__ import annotations
4
5from abc import ABC, abstractmethod
6from typing import TYPE_CHECKING, Optional
7
8if TYPE_CHECKING:
9 from datetime import datetime, tzinfo
10
11 from dateutil.rrule import rrule
12
13 from icalendar import prop
14
15
16class TZProvider(ABC):
17 """Interface for timezone implementations."""
18
19 @property
20 @abstractmethod
21 def name(self) -> str:
22 """The name of the implementation."""
23
24 @abstractmethod
25 def localize_utc(self, dt: datetime) -> datetime:
26 """Return the datetime in UTC."""
27
28 @abstractmethod
29 def localize(self, dt: datetime, tz: tzinfo) -> datetime:
30 """Localize a datetime to a timezone."""
31
32 @abstractmethod
33 def knows_timezone_id(self, id: str) -> bool:
34 """Whether the timezone is already cached by the implementation."""
35
36 @abstractmethod
37 def fix_rrule_until(self, rrule: rrule, ical_rrule: prop.vRecur) -> None:
38 """Make sure the until value works for the rrule generated from the ical_rrule."""
39
40 @abstractmethod
41 def create_timezone(self, name: str, transition_times, transition_info) -> tzinfo:
42 """Create a pytz timezone file given information."""
43
44 @abstractmethod
45 def timezone(self, name: str) -> Optional[tzinfo]:
46 """Return a timezone with a name or None if we cannot find it."""
47
48 @abstractmethod
49 def uses_pytz(self) -> bool:
50 """Whether we use pytz."""
51
52 @abstractmethod
53 def uses_zoneinfo(self) -> bool:
54 """Whether we use zoneinfo."""
55
56
57__all__ = ["TZProvider"]