def parse_datetime(string, rebase=True):
  from datetime import datetime
  from time import strptime

  from kay.utils import to_utc

  # shortcut: string as None or "now" or the current locale's
  # equivalent returns the current timestamp.
  if string is None or string.lower() in ('now', _('now')):
    return datetime.utcnow().replace(microsecond=0)

  def convert(format):
    """Helper that parses the string and convers the timezone."""
    rv = datetime(*strptime(string, format)[:7])
    if rebase:
      rv = to_utc(rv)
    return rv.replace(microsecond=0)

  # first of all try the following format because this is the format
  # Texpress will output by default for any date time string in the
  # administration panel.
  try:
    return convert(u'%Y-%m-%d %H:%M')
  except ValueError:
    pass

  # no go with time only, and current day
  for fmt in TIME_FORMATS:
    try:
      val = convert(fmt)
    except ValueError:
      continue
    return to_utc(datetime.utcnow().replace(hour=val.hour,
                  minute=val.minute, second=val.second, microsecond=0))

  # no try various types of date + time strings
  def combined():
    for t_fmt in TIME_FORMATS:
      for d_fmt in DATE_FORMATS:
        yield t_fmt + ' ' + d_fmt
        yield d_fmt + ' ' + t_fmt

  for fmt in combined():
    try:
      return convert(fmt)
    except ValueError:
      pass

  raise ValueError('invalid date format')
Number of queries for the context processor with no cache.
dataset/ETHPy150Open IanLewis/kay/kay/i18n/__init__.py/parse_datetime--crossover with--dataset/ETHPy150Open mlavin/django-ad-code/adcode/tests/test_performance.py/QueryCountsTestCase.test_context_processor_no_cache