#NEWLINE# @ staticmethod #NEWLINE# @ apply_settings #NEWLINE# def get_valid_day( res , new_date , settings = None ) : #NEWLINE# #INDENT# ( _ , tail ) = calendar . monthrange ( res . get ( 'year' , new_date . year ) , res . get ( 'month' , new_date . month ) ) #NEWLINE# if ( 'day' in res ) : #NEWLINE# #INDENT# if ( res [ 'day' ] > tail ) : #NEWLINE# #INDENT# raise ValueError ( 'Day not in range for month' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return res [ 'day' ] #NEWLINE# #UNINDENT# #UNINDENT# options = { #NEWLINE# #INDENT# 'first' : 1 , #NEWLINE# 'last' : tail , #NEWLINE# 'current' : ( new_date . day if ( new_date . day <= tail ) else tail ) , #NEWLINE# #UNINDENT# } #NEWLINE# return options [ settings . PREFER_DAY_OF_MONTH ]