#NEWLINE# @ apply_wraps #NEWLINE# def apply( self , other ) : #NEWLINE# #INDENT# n = self . n #NEWLINE# ( wkday , _ ) = tslib . monthrange ( other . year , other . month ) #NEWLINE# first = _get_firstbday ( wkday ) #NEWLINE# monthsSince = ( ( other . month - result . startingMonth ) % 3 ) #NEWLINE# if ( ( n <= 0 ) and ( monthsSince != 0 ) ) : #NEWLINE# #INDENT# monthsSince = ( monthsSince - 3 ) #NEWLINE# #UNINDENT# if ( ( n <= 0 ) and ( ( monthsSince == 0 ) and ( other . day > first ) ) ) : #NEWLINE# #INDENT# n = ( n + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( n > 0 ) and ( ( monthsSince == 0 ) and ( other . day < first ) ) ) : #NEWLINE# #INDENT# n = ( n - 1 ) #NEWLINE# #UNINDENT# #UNINDENT# other = ( other + relativedelta ( months = ( ( 3 * n ) - monthsSince ) ) ) #NEWLINE# ( wkday , _ ) = tslib . monthrange ( other . year , other . month ) #NEWLINE# first = _get_firstbday ( wkday ) #NEWLINE# result = datetime ( other . year , other . month , first , other . hour , other . minute , other . second , other . microsecond ) #NEWLINE# return result