code: def nearest(self, idx):
          
          hi = self.after(idx)
          lo = self.before(idx)
          if hi is None:
              return lo
          if lo is None:
              return hi
          if abs(hi - idx) < abs(lo - idx):
              return hi
          return lo
docs: Return datetime of record whose datetime is nearest idx.