def coerce_date_dict(date_dict):
 keys = ['year', 'month', 'day', 'hour', 'minute', 'second']
 retVal = {'year': 1, 'month': 1, 'day': 1, 'hour': 0, 'minute': 0, 'second': 0}
 modified = False
 for key in keys:
  try:
   retVal[key] = int(date_dict[key])
   modified = True
  except KeyError:
   break
 return ((modified and retVal) or {})

def coerce_date_dict ( date_dict ) : keys = [ 'year' , 'month' , 'day' , 'hour' , 'minute' , 'second' ] retVal = { 'year' : 1 , 'month' : 1 , 'day' : 1 , 'hour' : 0 , 'minute' : 0 , 'second' : 0 } modified = False for key in keys : try : retVal [ key ] = int ( date_dict [ key ] ) modified = True except KeyError : break return ( ( modified and retVal ) or { } )
given a dictionary it returns a tuple that represents a date .