Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/sqlalchemy_utils/primitives/weekday.py: 70%

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

33 statements  

1from functools import total_ordering 

2 

3from .. import i18n 

4from ..utils import str_coercible 

5 

6 

7@str_coercible 

8@total_ordering 

9class WeekDay: 

10 NUM_WEEK_DAYS = 7 

11 

12 def __init__(self, index): 

13 if not (0 <= index < self.NUM_WEEK_DAYS): 

14 raise ValueError('index must be between 0 and %d' % self.NUM_WEEK_DAYS) 

15 self.index = index 

16 

17 def __eq__(self, other): 

18 if isinstance(other, WeekDay): 

19 return self.index == other.index 

20 else: 

21 return NotImplemented 

22 

23 def __hash__(self): 

24 return hash(self.index) 

25 

26 def __lt__(self, other): 

27 return self.position < other.position 

28 

29 def __repr__(self): 

30 return f'{self.__class__.__name__}({self.index!r})' 

31 

32 def __unicode__(self): 

33 return self.name 

34 

35 def get_name(self, width='wide', context='format'): 

36 names = i18n.babel.dates.get_day_names(width, context, i18n.get_locale()) 

37 return names[self.index] 

38 

39 @property 

40 def name(self): 

41 return self.get_name() 

42 

43 @property 

44 def position(self): 

45 return (self.index - i18n.get_locale().first_week_day) % self.NUM_WEEK_DAYS