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

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, 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"]