#NEWLINE# def _beginning_of_date( time , time_step ) : #NEWLINE# #INDENT# 'Calculate the beginning of given time, based on time step.\n\n    :param time: Given time\n    :type time: Datetime\n    :param time_step: Time step (monthly or daily)\n    :type time_step: String\n\n    :returns: Beginning of given time\n    :rtype: Datetime\n    ' #NEWLINE# if ( time_step . lower ( ) == 'monthly' ) : #NEWLINE# #INDENT# if ( time . day != 1 ) : #NEWLINE# #INDENT# start_time_string = time . strftime ( '%Y%m%d' ) #NEWLINE# start_time_string = ( start_time_string [ : 6 ] + '01' ) #NEWLINE# time = datetime . strptime ( start_time_string , '%Y%m%d' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( time_step . lower ( ) == 'daily' ) : #NEWLINE# #INDENT# if ( ( time . hour != 0 ) or ( time . minute != 0 ) or ( time . second != 0 ) ) : #NEWLINE# #INDENT# start_time_string = time . strftime ( '%Y%m%d%H%M%S' ) #NEWLINE# start_time_string = ( start_time_string [ : 8 ] + '000000' ) #NEWLINE# time = datetime . strptime ( start_time_string , '%Y%m%d%H%M%S' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return time