def date_cast(date):
 if (date is None):
  return datetime.datetime.now()
 elif isinstance(date, datetime.datetime):
  return date
 try:
  if isinstance(date, six.string_types):
   try:
    if HAS_TIMELIB:
     return timelib.strtodatetime(to_bytes(date))
   except ValueError:
    pass
   if date.isdigit():
    date = int(date)
   else:
    date = float(date)
  return datetime.datetime.fromtimestamp(date)
 except Exception:
  if HAS_TIMELIB:
   raise ValueError('Unable to parse {0}'.format(date))
  raise RuntimeError('Unable to parse {0}. Consider installing timelib'.format(date))

def date_cast ( date ) : if ( date is None ) : return datetime . datetime . now ( ) elif isinstance ( date , datetime . datetime ) : return date try : if isinstance ( date , six . string_types ) : try : if HAS_TIMELIB : return timelib . strtodatetime ( to_bytes ( date ) ) except ValueError : pass if date . isdigit ( ) : date = int ( date ) else : date = float ( date ) return datetime . datetime . fromtimestamp ( date ) except Exception : if HAS_TIMELIB : raise ValueError ( 'Unable to parse {0}' . format ( date ) ) raise RuntimeError ( 'Unable to parse {0}. Consider installing timelib' . format ( date ) )
casts any object into a datetime .