@@ -1665,7 +1665,50 @@ class YearBegin(YearOffset):
1665
1665
# Special Offset Classes
1666
1666
1667
1667
1668
- class FY5253 (SingleConstructorOffset ):
1668
+ class FY5253Mixin (BaseOffset ):
1669
+ def __init__ (
1670
+ self , n = 1 , normalize = False , weekday = 0 , startingMonth = 1 , variation = "nearest"
1671
+ ):
1672
+ BaseOffset .__init__ (self , n , normalize )
1673
+ object .__setattr__ (self , "startingMonth" , startingMonth )
1674
+ object .__setattr__ (self , "weekday" , weekday )
1675
+
1676
+ object .__setattr__ (self , "variation" , variation )
1677
+
1678
+ if self .n == 0 :
1679
+ raise ValueError ("N cannot be 0" )
1680
+
1681
+ if self .variation not in ["nearest" , "last" ]:
1682
+ raise ValueError (f"{ self .variation } is not a valid variation" )
1683
+
1684
+ def is_anchored (self ) -> bool :
1685
+ return (
1686
+ self .n == 1 and self .startingMonth is not None and self .weekday is not None
1687
+ )
1688
+
1689
+ # --------------------------------------------------------------------
1690
+ # Name-related methods
1691
+
1692
+ @property
1693
+ def rule_code (self ) -> str :
1694
+ prefix = self ._prefix
1695
+ suffix = self .get_rule_code_suffix ()
1696
+ return f"{ prefix } -{ suffix } "
1697
+
1698
+ def _get_suffix_prefix (self ) -> str :
1699
+ if self .variation == "nearest" :
1700
+ return "N"
1701
+ else :
1702
+ return "L"
1703
+
1704
+ def get_rule_code_suffix (self ) -> str :
1705
+ prefix = self ._get_suffix_prefix ()
1706
+ month = ccalendar .MONTH_ALIASES [self .startingMonth ]
1707
+ weekday = ccalendar .int_to_weekday [self .weekday ]
1708
+ return f"{ prefix } -{ month } -{ weekday } "
1709
+
1710
+
1711
+ class FY5253 (SingleConstructorMixin , FY5253Mixin ):
1669
1712
"""
1670
1713
Describes 52-53 week fiscal year. This is also known as a 4-4-5 calendar.
1671
1714
@@ -1716,26 +1759,6 @@ class FY5253(SingleConstructorOffset):
1716
1759
_prefix = "RE"
1717
1760
_attributes = frozenset (["weekday" , "startingMonth" , "variation" ])
1718
1761
1719
- def __init__ (
1720
- self , n = 1 , normalize = False , weekday = 0 , startingMonth = 1 , variation = "nearest"
1721
- ):
1722
- BaseOffset .__init__ (self , n , normalize )
1723
- object .__setattr__ (self , "startingMonth" , startingMonth )
1724
- object .__setattr__ (self , "weekday" , weekday )
1725
-
1726
- object .__setattr__ (self , "variation" , variation )
1727
-
1728
- if self .n == 0 :
1729
- raise ValueError ("N cannot be 0" )
1730
-
1731
- if self .variation not in ["nearest" , "last" ]:
1732
- raise ValueError (f"{ self .variation } is not a valid variation" )
1733
-
1734
- def is_anchored (self ) -> bool :
1735
- return (
1736
- self .n == 1 and self .startingMonth is not None and self .weekday is not None
1737
- )
1738
-
1739
1762
def is_on_offset (self , dt : datetime ) -> bool :
1740
1763
if self .normalize and not is_normalized (dt ):
1741
1764
return False
@@ -1830,24 +1853,6 @@ def get_year_end(self, dt):
1830
1853
# The previous self.weekday is closer than the upcoming one
1831
1854
return target_date + timedelta (days_forward - 7 )
1832
1855
1833
- @property
1834
- def rule_code (self ) -> str :
1835
- prefix = self ._prefix
1836
- suffix = self .get_rule_code_suffix ()
1837
- return f"{ prefix } -{ suffix } "
1838
-
1839
- def _get_suffix_prefix (self ) -> str :
1840
- if self .variation == "nearest" :
1841
- return "N"
1842
- else :
1843
- return "L"
1844
-
1845
- def get_rule_code_suffix (self ) -> str :
1846
- prefix = self ._get_suffix_prefix ()
1847
- month = ccalendar .MONTH_ALIASES [self .startingMonth ]
1848
- weekday = ccalendar .int_to_weekday [self .weekday ]
1849
- return f"{ prefix } -{ month } -{ weekday } "
1850
-
1851
1856
@classmethod
1852
1857
def _parse_suffix (cls , varion_code , startingMonth_code , weekday_code ):
1853
1858
if varion_code == "N" :
@@ -1871,7 +1876,7 @@ def _from_name(cls, *args):
1871
1876
return cls (** cls ._parse_suffix (* args ))
1872
1877
1873
1878
1874
- class FY5253Quarter (SingleConstructorOffset ):
1879
+ class FY5253Quarter (SingleConstructorMixin , FY5253Mixin ):
1875
1880
"""
1876
1881
DateOffset increments between business quarter dates
1877
1882
for 52-53 week fiscal year (also known as a 4-4-5 calendar).
@@ -1941,15 +1946,8 @@ def __init__(
1941
1946
qtr_with_extra_week = 1 ,
1942
1947
variation = "nearest" ,
1943
1948
):
1944
- BaseOffset .__init__ (self , n , normalize )
1945
-
1946
- object .__setattr__ (self , "startingMonth" , startingMonth )
1947
- object .__setattr__ (self , "weekday" , weekday )
1949
+ FY5253Mixin .__init__ (self , n , normalize , weekday , startingMonth , variation )
1948
1950
object .__setattr__ (self , "qtr_with_extra_week" , qtr_with_extra_week )
1949
- object .__setattr__ (self , "variation" , variation )
1950
-
1951
- if self .n == 0 :
1952
- raise ValueError ("N cannot be 0" )
1953
1951
1954
1952
@cache_readonly
1955
1953
def _offset (self ):
@@ -1959,9 +1957,6 @@ def _offset(self):
1959
1957
variation = self .variation ,
1960
1958
)
1961
1959
1962
- def is_anchored (self ) -> bool :
1963
- return self .n == 1 and self ._offset .is_anchored ()
1964
-
1965
1960
def _rollback_to_year (self , other ):
1966
1961
"""
1967
1962
Roll `other` back to the most recent date that was on a fiscal year
@@ -2077,9 +2072,9 @@ def is_on_offset(self, dt: datetime) -> bool:
2077
2072
2078
2073
@property
2079
2074
def rule_code (self ) -> str :
2080
- suffix = self . _offset . get_rule_code_suffix ()
2075
+ suffix = FY5253Mixin . rule_code . fget ( self ) # type: ignore
2081
2076
qtr = self .qtr_with_extra_week
2082
- return f"{ self . _prefix } - { suffix } -{ qtr } "
2077
+ return f"{ suffix } -{ qtr } "
2083
2078
2084
2079
@classmethod
2085
2080
def _from_name (cls , * args ):
0 commit comments