Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/icalendar/timezone/provider.py: 83%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

29 statements  

1"""The interface for timezone implementations.""" 

2 

3from __future__ import annotations 

4 

5from abc import ABC, abstractmethod 

6from typing import TYPE_CHECKING, ClassVar 

7 

8if TYPE_CHECKING: 

9 from datetime import datetime, tzinfo 

10 

11 from dateutil.rrule import rrule 

12 

13 from icalendar import prop 

14 from icalendar.cal.timezone import Timezone 

15 

16 

17class TZProvider(ABC): 

18 """Interface for timezone implementations.""" 

19 

20 name: ClassVar[str] 

21 """The name of the implementation.""" 

22 

23 @abstractmethod 

24 def localize_utc(self, dt: datetime) -> datetime: 

25 """Return the datetime in UTC.""" 

26 

27 @abstractmethod 

28 def localize(self, dt: datetime, tz: tzinfo) -> datetime: 

29 """Localize a datetime to a timezone.""" 

30 

31 @abstractmethod 

32 def knows_timezone_id(self, tzid: str) -> bool: 

33 """Whether the timezone is already cached by the implementation.""" 

34 

35 @abstractmethod 

36 def fix_rrule_until(self, rrule: rrule, ical_rrule: prop.vRecur) -> None: 

37 """Make sure the until value works for rrules generated from the ical_rrule.""" 

38 

39 @abstractmethod 

40 def create_timezone(self, tz: Timezone) -> tzinfo: 

41 """Create a pytz timezone file given information.""" 

42 

43 @abstractmethod 

44 def timezone(self, name: str) -> tzinfo | None: 

45 """Return a timezone with a name or None if we cannot find it.""" 

46 

47 @abstractmethod 

48 def uses_pytz(self) -> bool: 

49 """Whether we use pytz.""" 

50 

51 @abstractmethod 

52 def uses_zoneinfo(self) -> bool: 

53 """Whether we use zoneinfo.""" 

54 

55 

56__all__ = ["TZProvider"]