<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def before(self, idx):
 """Return datetime of newest existing data record whose datetime is < idx. Might not even be in the same year! If no such record exists, return None."""

        if not isinstance(idx, datetime):
            raise TypeError("'%s' is not %s" % (idx, datetime))
        day = min(idx.date(), self._hi_limit - DAY)
        while day >= self._lo_limit:
            if day < self._rd_cache.lo or day >= self._rd_cache.hi:
                self._load(self._rd_cache, day)
            self._rd_cache.set_ptr(idx)
            if self._rd_cache.ptr > 0:
                return self._rd_cache.data[self._rd_cache.ptr - 1]['idx']
            day = self._rd_cache.lo - DAY
        return None