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)
Given a datetime ``t`` and a ``resolution``, flatten the precision beyond the given resolution.
dataset/ETHPy150Open shazow/unstdlib.py/unstdlib/standard/datetime_.py/truncate_datetime