code: def truncate_datetime(t, resolution):
      
  
      resolutions = ['year', 'month', 'day', 'hour', 'minute', 'second', 'microsecond']
      if resolution not in resolutions:
          raise KeyError("Resolution is not valid: {0}".format(resolution))
  
      args = []
      for r in resolutions:
          args += [getattr(t, r)]
          if r == resolution:
              break
  
      return datetime.datetime(*args)
docs: Given a datetime ``t`` and a ``resolution``, flatten the precision beyond the given resolution.
  
      ``resolution`` can be one of: year, month, day, hour, minute, second, microsecond
  
      Example::
  
          >>> t = datetime.datetime(2000, 1, 2, 3, 4, 5, 6000) # Or, 2000-01-02 03:04:05.006000
  
          >>> truncate_datetime(t, 'day')
          datetime.datetime(2000, 1, 2, 0, 0)
          >>> _.isoformat()
          '2000-01-02T00:00:00'
  
          >>> truncate_datetime(t, 'minute')
          datetime.datetime(2000, 1, 2, 3, 4)
          >>> _.isoformat()
          '2000-01-02T03:04:00'