def truncate_datetime(t, resolution):
resolutions = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>if resolution not in resolutions:<EOL><INDENT>raise KeyError("<STR_LIT>".format(resolution))<EOL><DEDENT>args = []<EOL>for r in resolutions:<EOL><INDENT>args += [getattr(t, r)]<EOL>if r == resolution:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return datetime.datetime(*args)<EOL>
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'