@@ -1039,55 +1039,62 @@ def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri',
1039
1039
_CustomMixin .__init__ (self , weekmask , holidays , calendar )
1040
1040
1041
1041
@cache_readonly
1042
- def cbday (self ):
1043
- kwds = self .kwds
1044
- return CustomBusinessDay (n = self .n , normalize = self .normalize , ** kwds )
1042
+ def cbday_roll (self ):
1043
+ """Define default roll function to be called in apply method"""
1044
+ cbday = CustomBusinessDay (n = self .n , normalize = False , ** self .kwds )
1045
+
1046
+ if self ._prefix .endswith ('S' ):
1047
+ # MonthBegin
1048
+ roll_func = cbday .rollforward
1049
+ else :
1050
+ # MonthEnd
1051
+ roll_func = cbday .rollback
1052
+ return roll_func
1045
1053
1046
1054
@cache_readonly
1047
1055
def m_offset (self ):
1048
1056
if self ._prefix .endswith ('S' ):
1049
- # MonthBegin:
1050
- return MonthBegin (n = 1 , normalize = self . normalize )
1057
+ # MonthBegin
1058
+ moff = MonthBegin (n = 1 , normalize = False )
1051
1059
else :
1052
1060
# MonthEnd
1053
- return MonthEnd (n = 1 , normalize = self .normalize )
1061
+ moff = MonthEnd (n = 1 , normalize = False )
1062
+ return moff
1054
1063
1055
-
1056
- class CustomBusinessMonthEnd (_CustomBusinessMonth ):
1057
- __doc__ = _CustomBusinessMonth .__doc__ .replace ('[BEGIN/END]' , 'end' )
1058
- _prefix = 'CBM'
1064
+ @cache_readonly
1065
+ def month_roll (self ):
1066
+ """Define default roll function to be called in apply method"""
1067
+ if self ._prefix .endswith ('S' ):
1068
+ # MonthBegin
1069
+ roll_func = self .m_offset .rollback
1070
+ else :
1071
+ # MonthEnd
1072
+ roll_func = self .m_offset .rollforward
1073
+ return roll_func
1059
1074
1060
1075
@apply_wraps
1061
1076
def apply (self , other ):
1062
1077
# First move to month offset
1063
- cur_mend = self .m_offset . rollforward (other )
1078
+ cur_month_offset_date = self .month_roll (other )
1064
1079
1065
1080
# Find this custom month offset
1066
- compare_date = self .cbday . rollback ( cur_mend )
1067
- n = liboffsets .roll_monthday (other , self .n , compare_date )
1081
+ compare_date = self .cbday_roll ( cur_month_offset_date )
1082
+ n = liboffsets .roll_convention (other . day , self .n , compare_date . day )
1068
1083
1069
- new = cur_mend + n * self .m_offset
1070
- result = self .cbday . rollback (new )
1084
+ new = cur_month_offset_date + n * self .m_offset
1085
+ result = self .cbday_roll (new )
1071
1086
return result
1072
1087
1073
1088
1089
+ class CustomBusinessMonthEnd (_CustomBusinessMonth ):
1090
+ __doc__ = _CustomBusinessMonth .__doc__ .replace ('[BEGIN/END]' , 'end' )
1091
+ _prefix = 'CBM'
1092
+
1093
+
1074
1094
class CustomBusinessMonthBegin (_CustomBusinessMonth ):
1075
1095
__doc__ = _CustomBusinessMonth .__doc__ .replace ('[BEGIN/END]' , 'beginning' )
1076
1096
_prefix = 'CBMS'
1077
1097
1078
- @apply_wraps
1079
- def apply (self , other ):
1080
- # First move to month offset
1081
- cur_mbegin = self .m_offset .rollback (other )
1082
-
1083
- # Find this custom month offset
1084
- compare_date = self .cbday .rollforward (cur_mbegin )
1085
- n = liboffsets .roll_monthday (other , self .n , compare_date )
1086
-
1087
- new = cur_mbegin + n * self .m_offset
1088
- result = self .cbday .rollforward (new )
1089
- return result
1090
-
1091
1098
1092
1099
# ---------------------------------------------------------------------
1093
1100
# Semi-Month Based Offset Classes
0 commit comments