def _to_seconds(timestr):
 timestr = timestr.upper()
 if ('H' in timestr):
  seconds = (int(timestr.replace('H', '')) * 3600)
 elif ('D' in timestr):
  seconds = (int(timestr.replace('D', '')) * 86400)
 elif ('W' in timestr):
  seconds = 604800
 else:
  try:
   seconds = int(timestr)
  except ValueError:
   seconds = 604800
 if (seconds > 604800):
  seconds = 604800
 return seconds

def _to_seconds ( timestr ) : timestr = timestr . upper ( ) if ( 'H' in timestr ) : seconds = ( int ( timestr . replace ( 'H' , '' ) ) * 3600 ) elif ( 'D' in timestr ) : seconds = ( int ( timestr . replace ( 'D' , '' ) ) * 86400 ) elif ( 'W' in timestr ) : seconds = 604800 else : try : seconds = int ( timestr ) except ValueError : seconds = 604800 if ( seconds > 604800 ) : seconds = 604800 return seconds
convert a timedelta to seconds .