def parse_datespec(datespec_str, assume_utc=False):
  '''
  Parse a date spec and return a filter function that returns true if the
  supplied time satisfies the date spec.

  Formats: 
  < [date expression]
  > [date expression]
  [date expression] to [date expression]
  '''
  datespec_str = datespec_str.strip()
  m = None
  if not m:
    m = _DATESPEC_RE1.match(datespec_str) or _DATESPEC_RE1A.match(datespec_str) 
    if m:
      direction = m.group(1)
      time = parse_datetime(m.group(2), assume_utc=assume_utc)

      if direction == "<":
        filter = lambda t: t <= time
      else:
        filter = lambda t: t >= time
  if not m:
    m = _DATESPEC_RE2.match(datespec_str) or _DATESPEC_RE2A.match(datespec_str)
    if m:
      time1, time2 = parse_datetime(m.group(1)), parse_datetime(m.group(2))
      filter = lambda t: time1 <= t and time2 <= t
  if not m:
    raise InvalidArgument("invalid date spec: '%s'" % datespec_str)

  return filter


##
## Common tools
##

# Simple serialization for short key/value pairs. We use our own for clarity, and so key order is deterministic.
dataset/ETHPy150Open bloomreach/zinc/zinc.py/parse_datespec/swapped operands of `<=`