def parse_datetime(datetime_str, formats=DATETIME_FORMATS, tz_offset=None, assume_utc=False):
  '''Parse a date in one of various formats, returning seconds since epoch.'''
  if _DATETIME_SECONDS_RE.match(datetime_str):
    return int(datetime_str)

  # Unfornately, strptime doesn't handle timezones well, so we do it ourselves.
  # If the last token looks like a timezone, put the offset into tz_offset.
  if tz_offset is None:
    bits = split_whitespace(datetime_str)
    if len(bits) > 1:
      tz_offset = parse_timezone(bits[-1])
      if tz_offset is not None:
        datetime_str = " ".join(bits[:-1])

  datetime_str = datetime_str.strip()
  for format in formats:
    try:
      tuple = time.strptime(datetime_str, format)
      if tz_offset is not None:
        # Specified offset
        seconds = calendar.timegm(tuple)
        seconds += tz_offset * 60
      elif assume_utc:
        # Unspecified offset, using UTC
        seconds = calendar.timegm(tuple)
      else:
        # Unspecified offset, using local time
        seconds = time.mktime(tuple)
    except (ValueError, OverflowError):
      continue
    break
  else:
    raise InvalidArgument("could not parse date: '%s'" % datetime_str) 
  return seconds
dataset/ETHPy150Open bloomreach/zinc/zinc.py/parse_datetime/original